mysql +keeplive

下载tar包

./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/ \      注意加内核  

&&make && make install

 

cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

cp  /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

cp /usr/local/keepalived/sbin/keepalived  /usr/sbin/

cp -r /usr/local/keepalived/etc/keepalived/ /etc   将配置文件 CP可到/etc

架构 192.168.10.129 httpd服务器 连的VIP    192.168.10.128 真实IP 为master   192.168.10.130 真实IP 为bakcup

配置文件  VIP需跟本地IP同一网段且IP未曾使用

master 配置

! Configuration File for keepalived
global_defs {
notification_email {
liu6630@qq.com
}
notification_email_from liu6630@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
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.111.111
}
}
virtual_server 192.168.111.111 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.10.128 3306 {
weight 100
notify_down /root/shell/mysql_keepalived.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}

BACK_UP 配置

! Configuration File for keepalived
global_defs {
notification_email {
liu6630@qq.com
}
notification_email_from liu6630@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
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.111.111
}
}
virtual_server 192.168.111.111 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.10.130 3306 {
weight 100
notify_down /root/shell/mysql_keepalived.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}

}

TCP_CHECK  模板只能 检测本机端口    notify_down检测到端口挂了执行 杀死keepalived 脚本

global_defs {
notification_email {
wgkgood@139.com
}
notification_email_from wgkgood@139.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}

vrrp_script chk_nginx {
script "/data/sh/nginx.sh"
interval 2
weight 2
}

vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 151
priority 90
advert_int 5
authentication {
auth_type PASS
auth_pass 2222
}

track_script {
chk_nginx
}

virtual_ipaddress {
192.168.111.188
}
}  

用脚本检测   脚本内容可为 

BACKMSG= `ps -C nginx --noheader |wc -l `

if [ $BACKMSG -eq 0 ];then

  service keepalived stop

else

  exit  

fi

 

notify_master 脚本 放到VRRP实例
URL_CHECK
HTTP_GET

配置文件重启keeeplived  

需手动加载 modprobe ip_vs  

 

排错 

1.编译是否加了内核 没加内核不会启动检测 加了

2配置文件是否在 /etc/keepalivde 下  cp -r /usr/local/keepalived/etc/keepalived/ /etc                 最终配置文件/etc/keepalived/keepalived.cof

3是否加载modprobe ip_vs   未加载虚拟IP模块 有VIP也不能 其他服务也不能访问VIP

4是否VIP与真实IP同一网段且无IP冲突 

5VIP是否起来 可以用 ip addr list 查看 

6 virtual_router_id  同一集群的keepalived的主、备机的virtual_router_id 必须相同,取值0-255 但是同一内网中不应有相同virtual_router_id的集群 

7 查看/var/messages日志  

 

posted @ 2017-05-12 00:22  林夕之风  阅读(497)  评论(0编辑  收藏  举报