安装依赖包
yum install gcc openssl-devel libnl3-devel pcre-devel
选择安装net-snmp-devel libnfnetlink-devel
下载源码包
wget https://www.keepalived.org/software/keepalived-2.0.15.tar.gz
tar xf keepalived-2.0.15.tar.gz
cd keepalived-2.0.15
./configure --prefix=/usr/local/keepalived-2.0.15
make && make install
ln -s /usr/local/keepalived-2.0.15 /usr/local/keepalived
mkdir /etc/keepalived/
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived-2.0.15/etc/sysconfig/keepalived /etc/sysconfig/
cp /root/keepalived-2.0.15/keepalived/keepalived.service /etc/systemd/system/
ln -s /usr/local/keepalived-2.0.15/sbin/keepalived /usr/sbin/
# 这个从keepalived源码目录复制,安装目录中没有
cp /root/keepalived-2.0.15/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.d/keepalived.conf
local0.* /var/log/keepalived/keepalived.log
systemctl restart rsyslog
systemctl start keepalived.service
配置日志轮转
/var/log/keepalived/*.log { #切分的两个文件名
daily #按天切分
rotate 7 #保留7份
create 0644 haproxy haproxy #创建新文件的权限、用户、用户组
compress #压缩旧日志
delaycompress #延迟一天压缩
missingok #忽略文件不存在的错误
dateext #旧日志加上日志后缀
sharedscripts #切分后的重启脚本只运行一次
postrotate #切分后运行脚本重载rsyslog,让rsyslog向新的日志文件中输出日志
/bin/kill -HUP $(/bin/cat /var/run/syslogd.pid 2>/dev/null) &>/dev/null
endscript
}