keepalived只做心跳检测部署文档-2011-12-10
##################################################################
定义如下环境:
vip: 192.168.33.222
mas: 192.168.33.220
sla: 192.168.33.221
软件版本:
keepalived-1.1.18.tar.gz
##################################################################
yum install openssl-devel
tar zxvf keepalived-1.1.18.tar.gz
cd keepalived-1.1.18
./configure
make
make install
cd ..
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/
service keepalived start
做成系统启动服务方便管理.
[root@slave init.d]# chkconfig keepalived on
[root@slave init.d]# chkconfig --list | grep keepalivd
[root@slave init.d]# chkconfig --list | grep keep
keepalived 0:off 1:off 2:on 3:on 4:on 5:on 6:off
######################################################################
配置日志:
yum install sysklogd syslog-n rsyslog
vi /etc/rsyslog.conf
添加下面配置:
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
$UDPServerAddress 127.0.0.1
*.info;mail.none;authpriv.none;cron.none;local3.none /var/log/messages
local3.* /var/log/haproxy/haproxy.log
#keepalived -S 0
local0.* /var/log/keepalived/keepalived.log
/sbin/rsyslogd -i /var/run/syslogd.pid -c 5
[root@master ~]# netstat -na | grep 514
udp 0 0 0.0.0.0:514 0.0.0.0:*
udp 0 0 :::514 :::*
unix 3 [ ] STREAM CONNECTED 16514 @/
[root@master keepalived]# /usr/local/sbin/keepalived -D -d -S 0
[root@master keepalived]# ps -ef | grep keep
root 5201 1 0 23:49 ? 00:00:00 /usr/local/sbin/keepalived -D -d -S 0
root 5202 5201 0 23:49 ? 00:00:00 /usr/local/sbin/keepalived -D -d -S 0
root 5203 5201 0 23:49 ? 00:00:00 /usr/local/sbin/keepalived -D -d -S 0
以上操作主端 从端一致
------------------------------------------------------------------
主端配置文件如下:
global_defs {
router_id MySQL-ha
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 60
priority 100
advert_int 1
# 不主动抢占资源
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.33.222/24
}
}
从配置信息:
global_defs {
router_id MySQL-ha
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 60
priority 90
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.33.222/24
}
}
从设置为只读:
mysql> show variables like '%read_only%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| innodb_read_only | OFF |
| read_only | ON |
| tx_read_only | OFF |
+------------------+-------+
3 rows in set (0.02 sec)
报错信息:
Jun 18 14:11:04 test Keepalived_vrrp[1663]: ip address associated with VRID not present in received packet : 192.168.32.66
Jun 18 14:11:04 test Keepalived_vrrp[1663]: one or more VIP associated with VRID mismatch actual MASTER advert
Jun 18 14:11:04 test Keepalived_vrrp[1663]: bogus VRRP packet received on eth1 !!!
更换 virtual_router_id 51 为60解决,原因之前已有机器是51的ID