Hướng dẫn cài đặt Rsyslog 5.7.x trên nền tảng CentOS 5.x QuanTriMang - Trong bài hướng dẫn sau, chúng tôi sẽ trình bày một số bước cơ bản để cài đặt và cấu hình syslog server bằng cách
Trang 1Hướng dẫn cài đặt Rsyslog 5.7.x trên nền tảng
CentOS 5.x
QuanTriMang - Trong bài hướng dẫn sau, chúng tôi sẽ trình bày một số bước cơ bản để cài đặt và cấu hình syslog server bằng cách sử dụng Rsyslog Theo thông tin từ phía hãng,
Rsyslog có khả năng cải thiện khả năng hỗ trợ syslogd, có thể
được sử dụng như 1 phương án thay thế hoặc dự phòng Bên cạnh
đó, những tính năng nâng cao khá phù hợp với các tầng lớp doanh nghiệp, khả năng bảo mật mã hóa cũng khá đơn giản và dễ thiết lập, dù cho đối tượng người sử dụng có ít kinh nghiệm Cụ thể, chúng ta sẽ cùng nhau kết hợp và cài đặt tất cả các tính năng của Rsyslog 5.7.2 trên nền tảng CentOS 5.5 server
Để bắt đầu, chúng ta cần cài đặt những gói hỗ trợ sau:
yum install -y pcre pcre-devel mysql-server mysql-devel gnutls gnutls-devel gnutls-utils net-snmp net-snmp-devel net-snmp-libs net-snmp-perl net-snmp-utils libnet libnet-devel
Tiếp theo là gói librelp (Reliable Event Logging Protocol
Trang 2Library) để sử dụng các thư viện dành cho giao thức RELP – có
nhiệm vụ cung cấp khả năng ghi lại các sự kiện xảy ra trong hệ thống mạng và đảm bảo rằng không bỏ sót bất kỳ tin nhắn cũng như email nào, cho dù có vấn đề xảy ra với quá trình kết nối hoặc các đầu peer không ổn định
cd /tmp
wget
1.0.0.tar.gz
Trang 4tar -xvf rsyslog-5.7.2.tar.gz
cd rsyslog-5.7.2
Để tìm hiểu thông tin về những tùy chọn có sẵn trong Rsyslog,
các bạn có thể sử dụng lệnh /configure –help Câu lệnh sau sẽ
kích hoạt hầu hết các tính năng rsyslog như Compression,
Multithreading, MySql, SNMP, Mail, RELP :
./configure enable-regexp enable-zlib enable-pthreads enable-klog enable-inet enable-unlimited-select enable-debug enable-rtinst enable-memcheck enable-diagtools enable-mysql enable-snmp enable-gnutls enable-rsyslogrt enable-rsyslogd enable-extended-tests enable-mail enable-imptcp enable-omruleset enable-valgrind enable-imdiag enable-relp enable-testbench enable-imfile enable-omstdout enable-omdbalerting
enable-omuxsock enable-imtemplate
enable-omtemplate enable-pmlastmsg
Trang 5omudpspoof omprog impstats
mysql -u root -p mysql
GRANT ALL ON Syslog.* TO rsyslog@localhost IDENTIFIED BY 'your-mysql-password';
Trang 6#
# chkconfig: - 12 88
# description: Syslog is the facility by
which many daemons use to log \
# messages to various system log files It
is a good idea to always \
Trang 7multi-# among others, MySQL,
syslog/tcp, RFC 3195, permitted
# sender lists, filtering on any message part, and fine
# grain output format control
### END INIT INFO
# Source function library
/etc/init.d/functions
RETVAL=0
start() {
[ -x /usr/local/sbin/rsyslogd ] || exit 5
#[ -x /usr/local/sbin/rklogd ] || exit 5
# Do not start rsyslog when sysklogd
is running
if [ -e /var/run/syslogd.pid ] ;
then
Trang 8echo $"Shut down sysklogd before you run rsyslog";
exit 1;
fi
# Source config
if [ -f /etc/sysconfig/rsyslog ] ; then
/etc/sysconfig/rsyslog else
fi
umask $SYSLOG_UMASK
echo -n $"Starting system logger: "
Trang 10echo -n "Reloading system logger "
Trang 13;;
*)
echo $"Usage: $0
Trang 14
{start|stop|restart|reload|force-reload|condrestart}"
exit 2
esac
exit $?
Hãy lưu ý đến giá trị SYSLOGD_OPTIONS="-c5" đã
được thiết lập Sau đây, chúng ta sẽ thiết lập Syslog và Rsyslog:
service syslog stop
chkconfig syslog off
chmod 755 /etc/init.d/rsyslog
chkconfig add rsyslog
chkconfig rsyslog on
Các đoạn mã init có thể download tại đây
(http://honeynet.ir/software/rsyslog/) Một số mẫu tham khảo khác các bạn có thể tìm và tham khảo thêm tại trang chủ (http://www.rsyslog.com/):
vi /etc/rsyslog.conf
Trang 15# Input Modules -This line is comment
-This line is comment
# -$ModLoad impstats.so
$PStatsInterval 300
syslog.info /var/log/rsyslog-stats
-This line is comment
#$ModLoad immark.so # provides MARK message capability
$ModLoad imuxsock.so # provides
support for local system logging (via logger command)
$ModLoad imklog.so # provides
kernel logging support (previously done
by rklogd)
-This line is comment
Trang 16# -$ModLoad imudp.so # provides UDP syslog reception
$UDPServerAddress * # all local interfaces
$UDPServerRun 514 # start UDP server (log server receiver)
-This line is comment
# -$ModLoad imtcp.so # provides TCP syslog reception and GSS-API (if
compiled)
$InputTCPServerRun 514 # start TCP server (log server receiver)
-This line is comment
# -$ModLoad imrelp.so # RELP input
$InputRELPServerRun 20514 # start RELP Protocol
Trang 17-This line is comment
# -$ModLoad imfile.so # Text file
# -#$ModLoad imgssapi.so # Plain TCP and GSSAPI
#$ModLoad im1395.so # Messages via RFC1395
Trang 18# Output Modules -This line is comment
-This line is comment
# -$ModLoad omsnmp.so # Send SNMP traps
# -$ModLoad ommysql.so # Log to MySQL
#$ModLoad ompgsql.so # Log to
PostgreSQL
-This line is comment
Trang 19# -$ModLoad ommail.so # Send mail
#if $msg contains 'hard disk fatal
failure' then :ommail:;mailBody
-This line is comment
# -$ModLoad omrelp.so # Send to
another host via RELP
#$ModLoad omlibdbi.so # Log via
generic DB output
Trang 20#$ModLoad omgss.so # GSS enabled output
# Globals -This line is comment
default location for work (spool) files
$ActionQueueType LinkedList # use asynchronous processing
$ActionQueueFileName queue # set file name, also enables disk mode
$ActionResumeRetryCount -1 #
infinite retries on insert failure
$ActionQueueSaveOnShutdown on # save in-memory data if rsyslog shuts down
$MainMsgQueueMaxFileSize 100M
Trang 21$ActionQueueMaxFileSize 5M
-This line is comment
# -# Below find some samples of what a
template can do Have a good
# time finding out what they do [or
just tun them] ;)
# A template that resambles traditional syslogd file output:
$template
TraditionalFormat,"%timegenerated%
%HOSTNAME% lf%\n"
%syslogtag%%msg:::drop-last-# a template useful for debugging
format issues
$template DEBUG,"Debug line with all properties:\nFROMHOST: '%FROMHOST%', HOSTNAME: '%HOSTNAME%', PRI:
%PRI%,\nsyslogtag '%syslogtag%',
programname: '%programname%', APP-NAME:
Trang 22'%APP-NAME%', PROCID: '%PROCID%',
# (yes, there is NO space betwen
syslogtag and msg! that's important!)
# The template below emulates winsyslog format, but we need to check the time
Trang 23# stamps used for now, it is good
enough ;) This format works best with
# other members of the MonitorWare
product family It is also a good
rfc3339%,%timegenerated:12:19:date-
rfc3339%,%timegenerated:1:10:date-
rfc3339%,%timegenerated:12:19:date-rfc3339%,%syslogfacility%,%syslogpriority%,%syslogtag%%msg%\n"
# A template used for database writing (notice it *is* an actual
# sql-statement):
$template dbFormat,"insert into
SystemEvents (Message,
Trang 24$template
FileFormat,"%TIMESTAMP:::date-rfc3339%
%HOSTNAME% 1st-sp%%msg:::drop-last-lf%\n"
%syslogtag%%msg:::sp-if-no-$template
ForwardFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME%
%syslogtag:1:32%%msg:::sp-if-no-1st-sp%%msg%"
# Selector lines are somewhat different from stock syslogd With
Trang 25# rsyslog, you can add a semicolon ";" after the target and then
# the template name That will assign this template to the respective
# action If no template name is given,
a hardcoded template is used
# If a template name is given, but the template was not defined, the
# selector line is DEACTIVATED
-
-This line is comment
# -# Forward via TCP with maximum
compression:
#$AllowedSender TCP, 127.0.0.1,
192.0.2.0/24, [::1]/128, *.example.net, somehost.example.com
#*.* @@(z9)192.168.x.x:514
Trang 26# Forward via UDP with maximum
compression:
#$AllowedSender UDP, 127.0.0.1,
192.0.2.0/24, [::1]/128, *.example.net, somehost.example.com
#*.* @(z9)192.168.x.x:514
# Forward via RELP Protocol :
#*.*
:omrelp:192.168.2.4:20514;TraditionalFormat
# Store all log files in MySQL DB :
#*.*
mysql-password
:ommysql:127.0.0.1,Syslog,rsyslog,your This line is comment
-This line is comment
Trang 27# -# Log all kernel messages to the
console
# Logging much else clutters up the
screen
#kern.* /dev/console;TraditionalFileFormat
# Log anything (except mail) of level
# Log all the mail messages in one
place
Trang 28mail.* -/var/log/maillog
# Log cron stuff
cron.* /var/log/cron
# Everybody gets emergency messages
*.emerg
*
# Save news errors of level crit and
higher in a special file
uucp,news.crit /var/log/spooler
# Save boot messages also to boot.log
local7.* /var/log/boot.log
# -This line is comment
$IncludeConfig /etc/rsyslog.d/*.conf
Trang 29-This line is comment
# -#if message contains 'network error' then run the restart-network.sh shell script!!!
#:msg, contains, "network error"