Keepalived安装配置
Posted eikixu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Keepalived安装配置相关的知识,希望对你有一定的参考价值。
1.安装
方法一:
yum install psmisc wget http://www.keepalived.org/software/keepalived-1.2.12.tar.gz tar xf keepalived-1.2.12.tar.gz cd keepalived-1.2.12 ./configure --prefix=/usr/local/keepalived 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/ mkdir /etc/keepalived cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
方法二:
yum -y install keepalived
2.配置keepalived的配置文件
vi /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { router_id haproxy_mysql #keepalived组的名称 } vrrp_script chk_haproxy { script "/usr/bin/sh /etc/keepalived/check_haproxy.sh" interval 2 weight 2 } vrrp_instance VI_HAPROXY { state MASTER #备份机是BACKUP #nopreempt #非抢占模式 interface ens33 virtual_router_id 51 #同一集群中该数值要相同,只能从1-255 priority 100 //备库可以90 advert_int 1 authentication { auth_type PASS #Auth 用密码,但密码不要超过8位 auth_pass 1111 } virtual_ipaddress { 10.10.48.240 } track_script { chk_haproxy } }
3.配置监控脚本:
vi /etc/keepalived/check_haproxy.sh #!/bin/bash if [ `ps -C mysqld --no-header |wc -l` -eq 0 ];then systemctl stop keepalived elif [ `ps -C haproxy --no-header |wc -l` -eq 0 ]; then /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg sleep 3 if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then /etc/init.d/keepalived stop fi fi
4.配置keepalived日志单独存放
默认日志存放在系统日志:/var/log/messages下 修改/etc/sysconfig/keepalived 把KEEPALIVED_OPTIONS="-D" 修改为:KEEPALIVED_OPTIONS="-D -d -S 0" touch /var/log/keepalived.log 在/etc/rsyslog.conf 末尾添加 [[email protected] /]# vim /etc/rsyslog.conf local0.* /var/log/keepalived.log 重启日志记录服务 /etc/init.d/rsyslog restart Shutting down system logger: [ OK ] Starting system logger: [ OK ] 或者 systemctl restart rsyslog
5.启动keepalived服务,查看日志
/etc/init.d/keepalived start vi /var/log/keepalived
以上是关于Keepalived安装配置的主要内容,如果未能解决你的问题,请参考以下文章