------------------ Both LB1 & LB2 server ---------------------
# yum –y install keepalived
# mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf-backup
# vi /etc/keepalived/keepalived.conf
------------------ NODE LB1 ------------------------
vrrp_scrpt chk_haproxy {
script "pidof haproxy" # check the haproxy process
interval 2 # every 2 seconds
weight 2 # add 2 points if OK
}
vrrp_instance VI_1 {
interface ens33 # interface to monitor
state MASTER # MASTER on haproxy, BACKUP on haproxy2
virtual_router_id 51
priority 101 # 101 on haproxy, 100 on haproxy2
virtual_ipa {
10.10.10.99 # virtual ip address
}
track_scrpt {
chk_haproxy
}
}
------------------ NODE LB2 ------------------------
vrrp_script chk_haproxy {
script "pidof haproxy" # check the haproxy process
interval 2 # every 2 seconds
weight 2 # add 2 points if OK
}
vrrp_instance VI_1 {
interface ens33 # interface to monitor
state BACKUP # MASTER on haproxy, BACKUP on haproxy2
virtual_router_id 51
priority 100 # 101 on haproxy, 100 on haproxy2
virtual_ip {
10.10.10.99 # virtual ip address
}
track_script {
chk_haproxy
}
}
** Restart service Keepalived
# systemctl enable keepalived
# systemctl restart keepalived
# ip a
LB01 Down
LB02 Status
------------------ Both LB1 & LB2 server ---------------------
# systemctl disable firewalld; systemctl stop firewalld; systemctl status firewalld
------------------ Both LB1 & LB2 server ---------------------
# yum -y update
# yum - y install net-tools mariadb-server
# systemctl enable mariadb
# systemctl start mariadb
# mysql_secure_installation
# mv /etc/my.cnf /etc/my.cnf-bk
# vi /etc/my.cnf
----------------------------- Master 1-----------------------------------
[mysqld]
server-id=1
log-bin=mysql
auto-increment-increment = 2
auto-increment-offset = 1
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysl.sock
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
# systemctl restart mariadb
----------------------------- Master 2-----------------------------------
# mv /etc/my.cnf /etc/my.cnf-bk
# vi /etc/my.cnf
[mysqld]
server-id=2
log-bin=mysql-bin
auto-increment-increment = 2
auto-increment-offset = 2
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
# systemctl restart mariadb
** Create the replicator user on each server
----------------------------- Master 1-----------------------------------
# mysql –u root –p1234556
> GRANT REPLICATION SLAVE ON *.* TO 'DTULAB'@'5.5.5.5' IDENTIFIED BY '123456';
> FLUSH PRIVILEGES;
----------------------------- Master 2-----------------------------------
# mysql –u root –p1234556
> GRANT REPLICATION SLAVE ON *.* TO 'DTULAB'@'5.5.5.3' IDENTIFIED BY '123456';
> FLUSH PRIVILEGES;
** Check master status
----------------------------- Master 1-----------------------------------
> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 399 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
----------------------------- Master 2-----------------------------------
> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 399 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
** Set master to master relationship
----------------------------- Master 1-----------------------------------
> STOP SLAVE;
> CHANGE MASTER TO
-> MASTER_HOST = '5.5.5.5',
-> MASTER_USER = 'DTULAB',
-> MASTER_PASSWORD = '123456',
-> MASTER_PORT = 3306,
-> MASTER_LOG_FILE = 'mysql-bin.000001',
-> MASTER_LOG_POS = 399,
-> MASTER_CONNECT_RETRY = 10;
> START SLAVE;
----------------------------- Master 2-----------------------------------
> STOP SLAVE;
> CHANGE MASTER TO
-> MASTER_HOST = '5.5.5.3',
-> MASTER_USER = 'DTULAB',
-> MASTER_PASSWORD = '123456',
-> MASTER_PORT = 3306,
-> MASTER_LOG_FILE = 'mysql-bin.000001',
-> MASTER_LOG_POS = 399,
-> MASTER_CONNECT_RETRY = 10;
> START SLAVE;
** Check slave config
------------------ Both MASTER1 & MASTER2 server ---------------------
> SHOW STATUS SLAVE \G;
…
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
…
> EXIT;
ðSlave_IO_Running and Slave_SQL_Running are all YES that successful configuration
----------------------------- Master 1-----------------------------------
# mysql –u root –p123456
MariaDB [(none)]> create database DTULAB;
----------------------------- Master 2-----------------------------------
# mysql –u root –p123456
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| DTULAB |
| Linux |
| Linux2 |
| mysql |
| performance_schema |
| reptest |
+--------------------+
» Tin mới nhất:
» Các tin khác: