1上次说过了mysql的主从配置
tar zxf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
yum install gcc gcc-c++
yum install kernel-devel -y
2报错
configure: error: Popt libraries is required
yum install popt-devel
3继续执行
./configure --with-kernel-dir=/usr/src/kernels/2.6.32-696.20.1.el6.x86_64/
Make
Make install
4 DIR=/usr/local/
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/ && mkdir -p /etc/keepalived
cp /usr/local/sbin/keepalived /usr/sbin/
5创建配置文件vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs { notification_email { 132769137@qq.com } notification_email_from 1327629137@qq.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } #VIP1 vrrp_instance VI_1 { state MASTER interface eth0 lvs_sync_daemon_inteface eth0 virtual_router_id 151 priority 100 advert_int 5 #nopreempt authentication { auth_type PASS auth_pass 2222 } virtual_ipaddress { 192.168.118.128 } } virtual_server 192.168.118.128 3306 { delay_loop 6 lb_algo wrr lb_kind DR persistence_timeout 60 protocol TCP real_server 192.168.118.128 3306 { weight 100 notify_down /data/sh/msyql.sh TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 3306 } } }
6启动
/etc/init.d/keepalived restart
tail -fn100 /var/log/messages日志一直在滚动,没有加载ipvs模块
modprobe ip_vs
lsmod |grep ip_vs
/etc/init.d/keepalived restart
tail -fn100 /var/log/messages
ul 31 21:09:16 localhost rsyslogd-2177: imjournal: begin to drop messages due to rate-limiting
成功
7从服务器
Mysql 从服务器配置keepalived.conf跟master 一样,只需要把Realserver IP修改成
real_server 192.168.118.129;优先级从100改为90即可
在master、slave数据库上创建/data/sh/mysql.sh脚本,内容为:
pkill keepalived
然后分别重启两台数据库上keepalive服务即可,最后测试停止master mysql 服务,是否会自动切换
到backup上