码迷,mamicode.com
首页 > 其他好文 > 详细

Keepalived安装配置

时间:2019-03-22 18:35:09      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:messages   live   glob   lb01   sql   ref   virt   star   log   

 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 末尾添加

[root@lb01 /]# 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安装配置

标签:messages   live   glob   lb01   sql   ref   virt   star   log   

原文地址:https://www.cnblogs.com/EikiXu/p/10579957.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!