192.168.81.109 vip
192.168.81.100 centos7 客户端
192.168.81.101 centos7 MysqL主+keepalived主
192.168.81.102 centos7 MysqL主+keepalived备
192.168.81.100
部署数据库
yum -y install mariadb mariadb-server
修改配置文件
vim /etc/my.cnf
server-id=1
log-bin=MysqLbin
relay-log=relays-log
启动mariadb
systemctl start mariadb
部署主服务器
MysqL -e "grant all on *.* to MysqL@'%' identified by 'MysqL';"
MysqL -e "show master status;"
MysqL -e "change master to master_host='192.168.81.102',master_user='MysqL',master_passowrd='MysqL',master_log_file='MysqLbin.000001',master_log_pos=123456"
MysqL -e "slave start;"
MysqL -e "show slave status \G;"
部署keepalived
yum -y install keepalived ipvsadm
修改keepalived配置文件
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.81.109
}
}
virtual_server 192.168.81.109 3306 {
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP
real_server 192.168.81.100 3306 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
启动keepalived
systemctl start keepalived
开机启动
chkconfig keepalived on
查看ipvsadm
ipvsadm
192.168.81.100
部署数据库
yum -y install mariadb mariadb-server
修改配置文件
vim /etc/my.cnf
server-id=1
log-bin=MysqLbin
relay-log=relays-log
启动mariadb
systemctl start mariadb
部署主服务器
MysqL -e "grant all on *.* to MysqL@'%' identified by 'MysqL';"
MysqL -e "show master status;"
MysqL -e "change master to master_host='192.168.81.101',master_user='MysqL',master_passowrd='MysqL',master_log_file='MysqLbin.000001',master_log_pos=123456"
MysqL -e "slave start;"
MysqL -e "show slave status \G;"
部署keepalived
yum -y install keepalived ipvsadm
修改keepalived配置文件
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state SLAVE
interface eth0
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.81.109
}
}
virtual_server 192.168.81.109 3306 {
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP
real_server 192.168.81.101 3306 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
启动keepalived
systemctl start keepalived
开机启动
chkconfig keepalived on
查看ipvsadm
ipvsadm
192.168.81.100
部署mariadb
yum -y install mariadb mariadb-server
systemctl start mariadb
远程登陆MysqL主主架构
MysqL -uMysqL -pMysqL -h192.168.81.109 -P3306
MysqL -e "show variables like 'server_id';"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
1 row in set (0.00 sec)
关闭keepalived主的keepalived和MysqL
systemctl stop keepalived
systemctl stop mariadb
再远程登陆MysqL
MysqL -uMysqL -pMysqL -h192.168.81.109 -P3306
MysqL -e "show variables like 'server_id';"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 2 |
+---------------+-------+
1 row in set (0.00 sec)
自动切换为keepalived备用MysqL数据库
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。