centos 搭建日志服务器
系統(tǒng)是centos 6.5 x64
服務(wù)器端
yum install -y rsyslog
mkdir /data/log
vi /etc/sysconfig/rsyslog
#SYSLOGD_OPTIONS="-c 5"
#r表示允許接收,x表示不需要DNS解析,m表示立即同步 0表示關(guān)閉
SYSLOGD_OPTIONS="-r -x -m 0"
cp /etc/rsyslog.conf /etc/rsyslog.conf.bak
vim /etc/rsyslog.conf
?10 $ModLoad immark #immark是模塊名,支持日志標(biāo)記
?13 $ModLoad imudp #imupd是模塊名,支持udp協(xié)議
?14 $UDPServerRun 514 #允許514端口接收使用UDP和TCP協(xié)議轉(zhuǎn)發(fā)過來的日志
?24 #$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat #默認(rèn)日志模板,默認(rèn)發(fā)送主機(jī)名,如果需要發(fā)送IP,添加下面2行。
?25 $template myFormat,"%timestamp% %fromhost-ip%%msg%\n"
?26 $ActionFileDefaultTemplate myFormat
?44 #*.info;mail.none;authpriv.none;cron.none ? ? ? ? ? ? ? ?/var/log/messages
?45 *.info;mail.none;authpriv.none;cron.none ? ? ? ? ? ? ? ?/data/log/messages #自定義存儲路徑
重啟rsyslog
/etc/init.d/rsyslog restart
查看端口是否啟動
netstat -napulu | grep 514
udp ? ? ? ?0 ? ? ?0 0.0.0.0:514 ? ? ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 8757/rsyslogd?
客戶端
yum install -y rsyslog
vim /etc/rsyslog.conf
?24 #$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
?25 $template myFormat,"%timestamp% %fromhost-ip%%msg%\n"
?26 $ActionFileDefaultTemplate myFormat
?45 *.info;mail.none;authpriv.none;cron.none ? ? ? ? ? ? ? ?@10.169.13.219 #發(fā)送到日志服務(wù)器
重啟rsyslog
/etc/init.d/rsyslog restart
服務(wù)端跟蹤日志
tail -f /data/log/messages?
客戶端測試重啟nrpe
killall -9 nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
/usr/local/nagios/libexec/check_nrpe -H localhost
服務(wù)器查看有日志過來了
May 14 15:37:25 10.168.23.232 Starting up daemon
May 14 15:37:25 10.168.23.232 Listening for connections on port 5666
May 14 15:37:25 10.168.23.232 Allowing connections from: 10.252.119.80,127.0.0.1
服務(wù)器和客戶端加入開機(jī)啟動項(xiàng)
echo "/etc/init.d/rsyslog start" >> /etc/rc.local
如果服務(wù)器查看的日志格式不符合,可以自己定義格式
在服務(wù)器端修改vim /etc/rsyslog.conf
比如
$template myFormat, "%fromhost-ip%^^^^^%msg%\n"
然后引用
local4.* ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-/data/log/messages;myFormat
重啟rsyslog就可以了
轉(zhuǎn)載于:https://blog.51cto.com/xiao987334176/1652325
總結(jié)
以上是生活随笔為你收集整理的centos 搭建日志服务器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ueditor1.4.3配置过程(包含单
- 下一篇: 第二阶段冲刺1