mysql with keepalived
----主機資訊
os:cent os 6.5
host: ct6505/192.108.56.115 ct6506/192.108.56.116
mysql:5.6.24
keepalived:1.2.17
----安裝mysql
--ct6505,ct6506
[root@ct6505/6 ~]# ls My*
MySQL-client-advanced-5.6.24-1.el6.x86_64.rpm
MySQL-server-advanced-5.6.24-1.el6.x86_64.rpm
[root@ct6505/6 ~]# yum remove mysql-libs-5.1.71-1.el6.x86_64
[root@ct6505/6 ~]# yum install libaio
[root@ct6505/6 ~]# yum install perl
[root@ct6505/6 ~]# rpm -ivh MySQL-*
----配置mysql主主複製
--ct6505,ct6506
[root@ct6505/6 ~]# mkdir -p /u02/mysqldata
[root@ct6505/6 mysql]# cd /var/lib/mysql
[root@ct6505/6 mysql]# cp -r * /u02/mysqldata/
[root@ct6505/6 mysql]# chown -R mysql.mysql /u02/mysqldata
--ct6505
[root@ct6505 u02]# vi /usr/my.cnf
[mysqld]
pid-file=/u02/mysqldata/mysql01.pid
datadir =/u02/mysqldata
log_bin=/u02/mysqldata/mysql01.log
log_error=/u02/mysqldata/mysql01.err
server-id=1
innodb_flush_log_at_trx_commit=1
sync_binlog=1
binlog_format=row
innodb_support_xa=1
innodb_buffer_pool_size=512M
innodb_additional_mem_pool_size=20M
innodb_log_file_size=256M
innodb_log_files_in_group=3
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
--ct6506
[root@ct6506 u02]# vi /usr/my.cnf
[mysqld]
pid-file=/u02/mysqldata/mysql02.pid
datadir =/u02/mysqldata
log_bin=/u02/mysqldata/mysql02.log
log_error=/u02/mysqldata/mysql02.err
server-id=2
innodb_flush_log_at_trx_commit=1
sync_binlog=1
binlog_format=row
innodb_support_xa=1
innodb_buffer_pool_size=512M
innodb_additional_mem_pool_size=20M
innodb_log_file_size=256M
innodb_log_files_in_group=3
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
--ct6505,ct6506
[root@ct6505/6 ~]# cat /root/.mysql_secret
# The random password set for the root user at Fri Jun 19 13:25:21 2015 (local time): Igi1I1PJxfzOdRLq
[root@ct6505/6 mysql]# mysql -uroot -p
mysql> SET PASSWORD = PASSWORD('system');
mysql> use mysql;
mysql> update user set host='%' where host='localhost';
mysql> flush privileges;
--ct6506
mysql> SHOW MASTER STATUS
--ct6505
mysql> STOP SLAVE;
mysql> CHANGE MASTER TO MASTER_HOST='192.108.56.116',
MASTER_USER='repl_user',
MASTER_PASSWORD='repl',
MASTER_LOG_FILE='mysql02.000001', --此處的值為ct6506上SHOW MASTER STATUS得到的結果
MASTER_LOG_POS=123; --此處的值為ct6506上SHOW MASTER STATUS得到的結果
mysql> START SLAVE;
--ct6505
mysql> SHOW MASTER STATUS
--ct6506
mysql> STOP SLAVE;
mysql> CHANGE MASTER TO MASTER_HOST='192.108.56.115',
MASTER_USER='repl_user',
MASTER_PASSWORD='repl',
MASTER_LOG_FILE='mysql02.000001', --此處的值為ct6505上SHOW MASTER STATUS得到的結果
MASTER_LOG_POS=321; --此處的值為ct6505上SHOW MASTER STATUS得到的結果
mysql> START SLAVE;
----安裝keepalived
--ct6505,ct6506
[root@ct6505/6 ~]# tar -xzvf keepalived-1.2.17.tar.gz
[root@ct6505/6 keepalived-1.2.17]# yum install gcc
[root@ct6505/6 keepalived-1.2.17]# yum install openssl openssl-devel
[root@ct6505/6 keepalived-1.2.17]# ./configure
[root@ct6505/6 keepalived-1.2.17]# make && make install
[root@ct6505/6 keepalived-1.2.17]# mkdir /etc/keepalived
----配置keepalived
--ct6505
[root@ct6505 keepalived-1.2.17]# vi /etc/keepalived/keepalived.conf
global_defs {
router_id mysql-ha
}
vrrp_instance VI_1 {
state backup
interface eth0
virtual_router_id 51
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.108.56.117/24
#192.108.56.117 label eht0:1
}
}
virtual_server 192.108.56.117 3306 {
delay_loop 2
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.108.56.115 3306 {
weight 3
notify_down /etc/keepalived/mysql-ha.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
[root@ct6505 ~]# vi /etc/keepalived/mysql-ha.sh
#!/bin/sh
pkill keepalived
[root@ct6505 ~]# chmod +x /etc/keepalived/mysql-ha.sh
--ct6506
[root@ct6506 mysql]# mkdir /etc/keepalived
[root@ct6506 mysql]# vi /etc/keepalived/keepalived.conf
global_defs {
router_id mysql-ha
}
vrrp_instance VI_1 {
state backup
interface eth0
virtual_router_id 51
priority 90
advert_int 1
#nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.108.56.117/24
#192.108.56.117 label eht0:1
}
}
virtual_server 192.108.56.117 3306 {
delay_loop 2
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.108.56.116 3306 {
weight 3
notify_down /etc/keepalived/mysql-ha.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
[root@ct6506 ~]# vi /etc/keepalived/mysql-ha.sh
#!/bin/sh
pkill keepalived
[root@ct6506 ~]# chmod +x /etc/keepalived/mysql-ha.sh
--ct6505,ct6506
[root@ct6505/6 ~]keepalived -D
PS:測試省略.keepalived也可以配置成服務,更方便.
os:cent os 6.5
host: ct6505/192.108.56.115 ct6506/192.108.56.116
mysql:5.6.24
keepalived:1.2.17
----安裝mysql
--ct6505,ct6506
[root@ct6505/6 ~]# ls My*
MySQL-client-advanced-5.6.24-1.el6.x86_64.rpm
MySQL-server-advanced-5.6.24-1.el6.x86_64.rpm
[root@ct6505/6 ~]# yum remove mysql-libs-5.1.71-1.el6.x86_64
[root@ct6505/6 ~]# yum install libaio
[root@ct6505/6 ~]# yum install perl
[root@ct6505/6 ~]# rpm -ivh MySQL-*
----配置mysql主主複製
--ct6505,ct6506
[root@ct6505/6 ~]# mkdir -p /u02/mysqldata
[root@ct6505/6 mysql]# cd /var/lib/mysql
[root@ct6505/6 mysql]# cp -r * /u02/mysqldata/
[root@ct6505/6 mysql]# chown -R mysql.mysql /u02/mysqldata
--ct6505
[root@ct6505 u02]# vi /usr/my.cnf
[mysqld]
pid-file=/u02/mysqldata/mysql01.pid
datadir =/u02/mysqldata
log_bin=/u02/mysqldata/mysql01.log
log_error=/u02/mysqldata/mysql01.err
server-id=1
innodb_flush_log_at_trx_commit=1
sync_binlog=1
binlog_format=row
innodb_support_xa=1
innodb_buffer_pool_size=512M
innodb_additional_mem_pool_size=20M
innodb_log_file_size=256M
innodb_log_files_in_group=3
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
--ct6506
[root@ct6506 u02]# vi /usr/my.cnf
[mysqld]
pid-file=/u02/mysqldata/mysql02.pid
datadir =/u02/mysqldata
log_bin=/u02/mysqldata/mysql02.log
log_error=/u02/mysqldata/mysql02.err
server-id=2
innodb_flush_log_at_trx_commit=1
sync_binlog=1
binlog_format=row
innodb_support_xa=1
innodb_buffer_pool_size=512M
innodb_additional_mem_pool_size=20M
innodb_log_file_size=256M
innodb_log_files_in_group=3
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
--ct6505,ct6506
[root@ct6505/6 ~]# cat /root/.mysql_secret
# The random password set for the root user at Fri Jun 19 13:25:21 2015 (local time): Igi1I1PJxfzOdRLq
[root@ct6505/6 mysql]# mysql -uroot -p
mysql> SET PASSWORD = PASSWORD('system');
mysql> use mysql;
mysql> update user set host='%' where host='localhost';
mysql> flush privileges;
--ct6506
mysql> SHOW MASTER STATUS
--ct6505
mysql> STOP SLAVE;
mysql> CHANGE MASTER TO MASTER_HOST='192.108.56.116',
MASTER_USER='repl_user',
MASTER_PASSWORD='repl',
MASTER_LOG_FILE='mysql02.000001', --此處的值為ct6506上SHOW MASTER STATUS得到的結果
MASTER_LOG_POS=123; --此處的值為ct6506上SHOW MASTER STATUS得到的結果
mysql> START SLAVE;
--ct6505
mysql> SHOW MASTER STATUS
--ct6506
mysql> STOP SLAVE;
mysql> CHANGE MASTER TO MASTER_HOST='192.108.56.115',
MASTER_USER='repl_user',
MASTER_PASSWORD='repl',
MASTER_LOG_FILE='mysql02.000001', --此處的值為ct6505上SHOW MASTER STATUS得到的結果
MASTER_LOG_POS=321; --此處的值為ct6505上SHOW MASTER STATUS得到的結果
mysql> START SLAVE;
----安裝keepalived
--ct6505,ct6506
[root@ct6505/6 ~]# tar -xzvf keepalived-1.2.17.tar.gz
[root@ct6505/6 keepalived-1.2.17]# yum install gcc
[root@ct6505/6 keepalived-1.2.17]# yum install openssl openssl-devel
[root@ct6505/6 keepalived-1.2.17]# ./configure
[root@ct6505/6 keepalived-1.2.17]# make && make install
[root@ct6505/6 keepalived-1.2.17]# mkdir /etc/keepalived
----配置keepalived
--ct6505
[root@ct6505 keepalived-1.2.17]# vi /etc/keepalived/keepalived.conf
global_defs {
router_id mysql-ha
}
vrrp_instance VI_1 {
state backup
interface eth0
virtual_router_id 51
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.108.56.117/24
#192.108.56.117 label eht0:1
}
}
virtual_server 192.108.56.117 3306 {
delay_loop 2
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.108.56.115 3306 {
weight 3
notify_down /etc/keepalived/mysql-ha.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
[root@ct6505 ~]# vi /etc/keepalived/mysql-ha.sh
#!/bin/sh
pkill keepalived
[root@ct6505 ~]# chmod +x /etc/keepalived/mysql-ha.sh
--ct6506
[root@ct6506 mysql]# mkdir /etc/keepalived
[root@ct6506 mysql]# vi /etc/keepalived/keepalived.conf
global_defs {
router_id mysql-ha
}
vrrp_instance VI_1 {
state backup
interface eth0
virtual_router_id 51
priority 90
advert_int 1
#nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.108.56.117/24
#192.108.56.117 label eht0:1
}
}
virtual_server 192.108.56.117 3306 {
delay_loop 2
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.108.56.116 3306 {
weight 3
notify_down /etc/keepalived/mysql-ha.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
[root@ct6506 ~]# vi /etc/keepalived/mysql-ha.sh
#!/bin/sh
pkill keepalived
[root@ct6506 ~]# chmod +x /etc/keepalived/mysql-ha.sh
--ct6505,ct6506
[root@ct6505/6 ~]keepalived -D
PS:測試省略.keepalived也可以配置成服務,更方便.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28539951/viewspace-1719377/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql + keepalived 安裝配置MySql
- mysql高可用之keepalivedMySql
- mysql高可用衡搭建(Keepalived)MySql
- Keepalived 架構高可用 Mysql架構MySql
- MySQL 高可用性—keepalived+mysql雙主MySql
- MySQL高可用架構:mysql+keepalived實現MySql架構
- keepalived+MySQL實現高可用MySql
- MySQL主主模式+Keepalived高可用MySql模式
- 利用Keepalived實現MySQL高可用MySql
- mysql-proxy+keepalived對mysql做讀寫分離MySql
- [Mysql高可用]——雙主互備+keepalivedMySql
- Keepalived+Mysql配置主主複製MySql
- Mysql+keepalived主主切換薦MySql
- keepalived+mysql+centos6.4 簡單配置MySqlCentOS
- MySQL主主複製+Keepalived打造高可用MySQL叢集MySql
- MySQL主從配置及haproxy和keepalived搭建MySql
- 基於keepalived Mysql雙主熱備配置MySql
- haproxy+keepalived+mycat+mysql (讀寫分離)MySql
- 利用keepalived構建高可用MySQL-HAMySql
- mysql+keepalived 雙主熱備高可用MySql
- 利用KEEPALIVED構建mysql主主複製MySql
- mysql主主複製+keepalived 打造高可用mysql叢集薦MySql
- linux上mysql MM(雙主)及keepalived搭建LinuxMySql
- MySQL進階:主主複製+Keepalived高可用MySql
- MySQL叢集搭建(6)-雙主+keepalived高可用MySql
- Haproxy+Keepalived+MySQL實現讀均衡負載MySql負載
- keepalived(四)Keepalived+NginxNginx
- 【MySQL】keepalived+haproxy實現mysql的高可用與負載均衡MySql負載
- 【Mysql】MySQL 主主複製 + LVS + Keepalived 實現 MySQL 高可用性MySql
- MYSQL8+CENTOS7.6 主從+keepalived搭建總結MySqlCentOS
- mysql5.6主主複製及keepalived 高可用MySql
- keepalived+haproxy實現mysql負載均衡高可用MySql負載
- LVS#MySQL+Keepalived四層負載均衡MySql負載
- 通過keepalived實現 MySQL VIP 自動切換MySql
- keepalived與mysql主主叢集自動切換MySql
- MySQL 高可用性之 Keepalived 雙主熱備MySql
- keepalived
- mysql 5.7+keepalived主從切換步驟簡述MySql