源码安装最新版keepalived,剥离日志出来并配置日志轮询

安装

yum install -y gcc openssl-devel popt-devel ipvsadm libnl3-devel net-snmp-devel libnl libnl-devel libnfnetlink-devel
tar -zxvf keepalived-2.2.4.tar.gz
cd keepalived-2.2.4
./configure --prefix=/usr/local/keepalived-2.2.4

mkdir /etc/keepalived/
cp /usr/local/keepalived-2.2.4/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived-2.2.4/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/src/keepalived-2.2.4/keepalived/keepalived.service /etc/systemd/system/
cp /usr/local/keepalived-2.2.4/sbin/keepalived /usr/sbin/
cp /usr/local/src/keepalived-2.2.4/keepalived/etc/init.d/keepalived /etc/init.d/
chmod 755 /etc/init.d/keepalived 
systemctl enable keepalived.service

剥离日志出来

mkdir /var/log/keepalived/

vim /etc/sysconfig/keepalived
KEEPALIVED_OPTIONS="-D -d -S 0"

vim /etc/rsyslog.conf 
local0.* /var/log/keepalived/keepalived.log

systemctl restart rsyslog

vim /etc/systemd/system/keepalived.service
EnvironmentFile=/etc/sysconfig/keepalived

systemctl daemon-reload

systemctl start keepalived.service

配置日志轮转

vim /etc/logrotate.d/keepalived
/var/log/keepalived/*.log {  
    su root root
    daily     
    rotate 7    
    create 0600 root root
    compress    
    delaycompress 
    missingok  
    dateext    
    sharedscripts
    postrotate   
      /bin/kill -HUP $(/bin/cat /var/run/syslogd.pid 2>/dev/null) &>/dev/null
    endscript
}
测试强制轮询
/usr/sbin/logrotate -vf  /etc/logrotate.d/keepalived
crontab  -e  #添加以下代码
0 0 * * * /usr/sbin/logrotate -vf /etc/logrotate.d/keepalived   #每天凌晨定时执行脚本
posted @ 2021-09-07 17:48  哈喽哈喽111111  阅读(244)  评论(0编辑  收藏  举报