欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

keepalived+mysql主主双备  

程序员文章站 2024-03-23 11:44:40
...
my.cnf配置如下:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

server-id=60
log-bin=mysql-bin
binlog-format=mixed
relay-log=mysql-relay

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

2、重起mysql服务(service mysqld restart)
3、授权grant replication slave, replication client on *.* to 'root'@'192.168.3.60' identified by '123456';
4、主服务的mysql执行show master status
5、将4的内容获取出来放在从服务的mysql 中执行change master to master_host='192.168.3.70',master_user='root',master_password='12354',master_log_file='mysql-bin.000021',master_log_pos=106;替换master_log_file和master_log_pos的内容

6、从服务执行show slave status查看Slave_IO_Running 和 Slave_SQL_Running是否为yes

keepalived的配置只需修改
安装过程看https://www.cnblogs.com/dcrq/p/5642680.html
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.3.88
        192.168.3.99
    }
}
可以添加如下的配置对mysql进行监控(可以使用nmap等工具进行监控,多次拉不起来则关闭本地的keepalived服务(service keepalived stop),在重试范围内则不需要)
vrrp_script chk_mysql_port {

    script "sh脚本的地址"

    interval 2

    weight 2

}