当前位置:Gxlcms > mysql > mysql集群之keepalived简单搭建_MySQL

mysql集群之keepalived简单搭建_MySQL

时间:2021-07-01 10:21:17 帮助过:9人阅读

1安装必须的相关包

yum -y install kernel-devel openssl* popt popt-devel

2下载安装

wget http://www.keepalived.org/software/keepalived-1.2.9.tar.gz
tar  -xf keepalived-1.2.9.tar.gz 
mkdir /usr/local/keepalived 
cd ~/ keepalived-1.2.9
./configure  --prefix=/usr/local/keepalived/
make && make install
cp /usr/local/keepalived/sbin/keepalived  /usr/sbin/ 
cp /usr/local/keepalived/etc/sysconfig/keepalived  /etc/sysconfig
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived  /etc/init.d/
chmod +x /etc/init.d/keepalived
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived

3修改配置文件如下

[root@M128 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
    notification_email {
 [email protected]
    }
    notification_email_from [email protected]
      smtp_server smtp.126.com   # 邮件服务器地址  
    smtp_connect_timeout 30     # 连接超时时间  
    router_id LVS_Master
}
vrrp_script chk_http_port {
    script  "/etc/keepalived/check_haproxy.sh"    # haproxy运行检测脚本[haproxy宕掉重启haproxy服务]  
    interval        5                     # 脚本执行间隔  
    weight         -5                    # 执行脚本后优先级变更:5表示优先级+5;-5则表示优先级-5
}
vrrp_instance VI_A {
    state MASTER                    # 主上此值为MASTER,从上为BACKUP 
    interface eth0
    virtual_router_id 50           # 此值主从必须一致
    priority 100
    advert_int 1
    authentication {                   # authentication两个参数值,主从也必须一致  
        auth_type PASS
    auth_pass yiban
    }
track_script {
    chk_http_port
    }
    virtual_ipaddress {
          192.168.78.220
    }
}

5启动keepalived

确保网络正常

service network restart (线上不要这么做)

/etc/init.d/keepalived start

查看结果

ip a

人气教程排行