1. 配置双主:
双机名
win89.inno.com
win88.inno.com
准备账号
SET SQL_LOG_BIN=0;
set passwordfor ‘root‘@‘localhost‘=‘123456‘;
grant all privileges on*.* to root@‘localhost‘with grant option;
create user‘repl‘@‘win88.inno.com‘ identified WITH mysql_native_password by ‘123456‘PASSWORD EXPIRE NEVER ;
grant replication slave on*.* to ‘repl‘@‘win88.inno.com‘with grant option;
create user‘repl‘@‘win89.inno.com‘ identified WITH mysql_native_password by ‘123456‘PASSWORD EXPIRE NEVER ;
grant replication slave on*.* to ‘repl‘@‘win89.inno.com‘with grant option;
create user‘repl‘@‘192.168.68.88‘ identified WITH mysql_native_password by ‘123456‘PASSWORD EXPIRE NEVER ;
grant replication slave on*.* to ‘repl‘@‘192.168.68.88‘with grant option;
create user‘repl‘@‘192.168.68.89‘ identified WITH mysql_native_password by ‘123456‘PASSWORD EXPIRE NEVER ;
grant replication slave on*.* to ‘repl‘@‘192.168.68.89‘with grant option;
flush privileges;
SET SQL_LOG_BIN=1;
配置主从
设win88.inno.com 的主机
change master to master_host=‘win89.inno.com‘,master_port=3308,master_user=‘repl‘,master_password=‘123456‘,master_auto_position=1;
start slave;
show slave status\G
设win89.inno.com 的主机
change master to master_host=‘win88.inno.com‘,master_port=3308,master_user=‘repl‘,master_password=‘123456‘,master_auto_position=1;
start slave;
show slave status\G
设置mysql 开机自启
cp -p /data/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig--add mysqldcp -p /data/3308/my.cnf /etc/my.cnf.d/my.cnf
chkconfig --list
安装keepalive
yum -y install keepalived
win89.inno.com 的keepalived 设定
[root@win89 ~]# cat /etc/keepalived/keepalived.conf! Configuration File forkeepalived
global_defs {
router_id mysql_slave_
vrrp_skip_check_adv_addr
vrrp_script check_run {
script"/data/mysql_check.sh"interval10}
vrrp_garp_interval0vrrp_gna_interval0}
vrrp_instance VI_1 {
state BACKUP
interface ens160
virtual_router_id51priority90advert_int1authentication {
auth_type PASS
auth_pass1111}
virtual_ipaddress {192.168.68.188}
track_script {
check_run
}
}
virtual_server192.168.68.188 3308{
delay_loop6lb_algo wrr
lb_kind DR
nat_mask255.255.255.0persistence_timeout50protocol TCP
real_server192.168.68.89 3308{
weight1TCP_CHECK {
connect_timeout3nb_get_retry3connect_port3308}
}
}
win88.inno.com 的keepalived 设定
[root@win88 ~]# cat /etc/keepalived/keepalived.conf! Configuration File forkeepalived
global_defs {
router_id mysql_master_
vrrp_skip_check_adv_addr
vrrp_script check_run {
script"/data/mysql_check.sh"interval10}
vrrp_garp_interval0vrrp_gna_interval0}
vrrp_instance VI_1 {
state BACKUP
interface ens160
virtual_router_id51priority100advert_int1authentication {
auth_type PASS
auth_pass1111}
virtual_ipaddress {192.168.68.188}
track_script {
check_run
}
}
virtual_server192.168.68.188 3308{
delay_loop6lb_algo wrr
lb_kind DR
nat_mask255.255.255.0persistence_timeout50protocol TCP
real_server192.168.68.88 3308{
weight1TCP_CHECK {
connect_timeout3nb_get_retry3connect_port3308}
}
}
设置keepalived 开机自启
systemctl enable keepalived systemctl start keepalived