centos 搭建日志服务器
系統是centos 6.5 x64
服務器端
yum install -y rsyslog
mkdir /data/log
vi /etc/sysconfig/rsyslog
#SYSLOGD_OPTIONS="-c 5"
#r表示允許接收,x表示不需要DNS解析,m表示立即同步 0表示關閉
SYSLOGD_OPTIONS="-r -x -m 0"
cp /etc/rsyslog.conf /etc/rsyslog.conf.bak
vim /etc/rsyslog.conf
?10 $ModLoad immark #immark是模塊名,支持日志標記
?13 $ModLoad imudp #imupd是模塊名,支持udp協議
?14 $UDPServerRun 514 #允許514端口接收使用UDP和TCP協議轉發過來的日志
?24 #$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat #默認日志模板,默認發送主機名,如果需要發送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 #發送到日志服務器
重啟rsyslog
/etc/init.d/rsyslog restart
服務端跟蹤日志
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
服務器查看有日志過來了
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
服務器和客戶端加入開機啟動項
echo "/etc/init.d/rsyslog start" >> /etc/rc.local
如果服務器查看的日志格式不符合,可以自己定義格式
在服務器端修改vim /etc/rsyslog.conf
比如
$template myFormat, "%fromhost-ip%^^^^^%msg%\n"
然后引用
local4.* ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-/data/log/messages;myFormat
重啟rsyslog就可以了
轉載于:https://blog.51cto.com/xiao987334176/1652325
總結
以上是生活随笔為你收集整理的centos 搭建日志服务器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ueditor1.4.3配置过程(包含单
- 下一篇: 第二阶段冲刺1