日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

centos 搭建日志服务器

發布時間:2025/3/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 搭建日志服务器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。