In centos7 configure the keepalived log as a different path
- 2020-12-10 01:05:08
- OfStack
keepalived installation:
cd <keepalived_sourcecode_path>
./configure --prefix=/usr/local/keepalived
make && make install
mkdir /etc/keepalived
mkdir /etc/keepalived/scripts
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /root/keepalived-2.0.6/keepalived/etc/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/sbin/keepalived /sbin/keepalived
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
chmod +x /etc/init.d/keepalived
Since by default keepalived's logs are written to /var/log/message, we need to strip this out.
Under centos 6:
(1) First modify /etc/sysconfig/keepalived file, comment out the following and add the following:
#KEEPALIVED_OPTIONS="-D"
KEEPALIVED_OPTIONS="-D -d -S 0"
(2) Next, modify the /etc/ rsyslog.conf file and add the following:
local0.* /var/log/keepalived.log
Under centos 7, you also need to modify/lib systemd/system/keepalived service file:
centos 7 is used. Because use systemctl centos 7, through service systemctl calls, so you need to modify/lib systemd/system/keepalived service file.
Put inside:
EnvironmentFile=-/usr/local/keepalived/etc/sysconfig/keepalived
ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS
Modified to:
EnvironmentFile=/etc/sysconfig/keepalived
ExecStart=/sbin/keepalived $KEEPALIVED_OPTIONS
Then reload service:
systemctl daemon-reload
The whole idea is,
1. Launch via systemctl start keepalived;
2. Start keepalived, reads service configuration file: / lib/systemd/system/keepalived service;
3. When in service's configuration file:
3.1 Start file path ExecStart=/sbin/keepalived $KEEPALIVED_OPTIONS, that is, start with parameters in the environment variable file;
3.2 Read the environment variable parameter EnvironmentFile=/etc/sysconfig/keepalived.
4. The $KEEPALIVED_OPTIONS parameter is configured in /etc/sysconfig/keepalived; We configured KEEPALIVED_OPTIONS=" -ES101en-ES102en-ES103en 0"; And - is S syslog facility, 0 means on local0, in/etc/rsyslog conf configured in local0. * / var/log/keepalived log
5. So, writing log/var log/keepalived log.