指定Keepalived输出日志文件

来源:互联网 发布:linux主机 编辑:程序博客网 时间:2024/06/05 21:18

默认日志存放在系统日志:/var/log/messages下

复制代码
[root@lb01 /]# tail -f  /var/log/messagesOct  6 13:30:07 lb01 Keepalived_vrrp[3671]: Kernel is reporting: interface eth0 UPOct  6 13:30:07 lb01 Keepalived_vrrp[3671]: VRRP_Instance(VI_1) Transition to MASTER STATEOct  6 13:30:08 lb01 Keepalived_vrrp[3671]: VRRP_Instance(VI_1) Entering MASTER STATEOct  6 13:30:08 lb01 Keepalived_vrrp[3671]: VRRP_Instance(VI_1) setting protocol VIPs.Oct  6 13:30:08 lb01 Keepalived_vrrp[3671]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.119.150Oct  6 13:30:08 lb01 Keepalived_healthcheckers[3670]: Netlink reflector reports IP 192.168.119.150 addedOct  6 13:30:13 lb01 Keepalived_vrrp[3671]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.119.150Oct  6 13:30:48 lb01 dhclient[856]: DHCPREQUEST on eth0 to 192.168.119.254 port 67 (xid=0x32903a31)Oct  6 13:30:48 lb01 dhclient[856]: DHCPACK from 192.168.119.254 (xid=0x32903a31)Oct  6 13:30:50 lb01 dhclient[856]: bound to 192.168.119.128 -- renewal in 783 seconds.
复制代码

把日志单独存放

修改/etc/sysconfig/keepalived

把KEEPALIVED_OPTIONS="-D" 修改为:KEEPALIVED_OPTIONS="-D -d -S 0"

复制代码
[root@lb01 /]# vim /etc/sysconfig/keepalived # Options for keepalived. See `keepalived --help' output and keepalived(8) and# keepalived.conf(5) man pages for a list of all options. Here are the most# common ones :## --vrrp               -P    Only run with VRRP subsystem.# --check              -C    Only run with Health-checker subsystem.# --dont-release-vrrp  -V    Dont remove VRRP VIPs & VROUTEs on daemon stop.# --dont-release-ipvs  -I    Dont remove IPVS topology on daemon stop.# --dump-conf          -d    Dump the configuration data.# --log-detail         -D    Detailed log messages.# --log-facility       -S    0-7 Set local syslog facility (default=LOG_DAEMON)#KEEPALIVED_OPTIONS="-D -d -S 0"
复制代码

在/etc/rsyslog.conf 末尾添加

[root@lb01 /]# vim /etc/rsyslog.conf local0.*                                                /var/log/keepalived.log

重启日志记录服务

[root@lb01 /]# /etc/init.d/rsyslog restartShutting down system logger:                               [  OK  ]Starting system logger:                                    [  OK  ]

重启keepalived

[root@lb01 /]# /etc/init.d/keepalived restartStopping keepalived:                                       [  OK  ]Starting keepalived:                                       [  OK  ]

查看日志

复制代码
[root@lb01 /]# tail -f /var/log/keepalived.log Oct  6 13:48:22 lb01 Keepalived_healthcheckers[3998]:  Using autogen SSL contextOct  6 13:48:22 lb01 Keepalived_healthcheckers[3998]: Using LinkWatch kernel netlink reflector...Oct  6 13:48:22 lb01 Keepalived_vrrp[3999]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]Oct  6 13:48:22 lb01 Keepalived_vrrp[3999]: VRRP_Instance(VI_1) Transition to MASTER STATEOct  6 13:48:22 lb01 Keepalived_vrrp[3999]: VRRP_Instance(VI_1) Received lower prio advert, forcing new electionOct  6 13:48:23 lb01 Keepalived_vrrp[3999]: VRRP_Instance(VI_1) Entering MASTER STATEOct  6 13:48:23 lb01 Keepalived_vrrp[3999]: VRRP_Instance(VI_1) setting protocol VIPs.Oct  6 13:48:23 lb01 Keepalived_healthcheckers[3998]: Netlink reflector reports IP 192.168.119.150 addedOct  6 13:48:23 lb01 Keepalived_vrrp[3999]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.119.150Oct  6 13:48:28 lb01 Keepalived_vrrp[3999]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.119.150
复制代码
注意:
默认情况下,rsyslog是受selinux限制的 
所以日志只能输出到 /var/log/messages里,自定义的目录无效 
例如keepalived,haproxy的日志输出,都依赖于rsyslog 
因此我们要关闭selinux 

【关闭selinux】 
查看 
sestatus -v 

永久关闭 
修改/etc/selinux/config 文件 
将SELINUX=enforcing改为SELINUX=disabled 

重启服务器 

【设置rsyslog】 
/etc/rsyslog.conf 
增加 
local3.* /data0/search/keepalived/log/my.log 
重启                                                                                            
service rsyslog stop 
service rsyslog start 
测试日志输出 
logger -p local3.info ‘test log print by piaohailin‘ 

参考文章 
selinux关闭教程 
http://bguncle.blog.51cto.com/3184079/957315 

查看SELinux状态:

4、/usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态

SELinux status:                 enabled

5、getenforce                 ##也可以用这个命令检查

关闭SELinux:

6、临时关闭(不用重启机器):

setenforce 0                  ##设置SELinux 成为permissive模式

                              ##setenforce 1 设置SELinux 成为enforcing模式

7、修改配置文件需要重启机器:

修改/etc/selinux/config 文件

将SELINUX=enforcing改为SELINUX=disabled

重启机器即可


原创粉丝点击