Keepalived安裝配置

 1.安裝mysql

方法一:sql

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/

  

方法二:vim

yum -y install keepalived


2.配置keepalived的配置文件bash

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.配置監控腳本:rest

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服務,查看日誌router

/etc/init.d/keepalived start
vi /var/log/keepalived
相關文章
相關標籤/搜索