สำนักวิทยบริการและเทคโนโลยีสารสนเทศ (สวส.)

Office of Academic Resources and Information Technology

การติดตั้ง Central Log ด้วย rsyslog , mysql, php

Install RSyslog+MySQL เพื่อจำ

ขั้นตอนการติดตั้งและตั้งค่า  RSyslog+MySQL+ PHP
 
1.ติดตั้งโปรแกรม RSyslog+MySQL 
ขั้นตอนที่1
ทำการติดตั้งโปรแกรม
aptitude install apache php mysql php-mysql mysql-server wget rsyslog rsyslog-mysql php-gd
 
ขั้นตอนที่ 2
ทำการตั้งค่า Mysql
-By default the MySQL root database user is blank so for security we should set it now:
# mysqladmin -u root password YourNewPassword //ตั้ง password ให้กับ user root ใหม่
-Now let’s import the database schema for the rsyslog database into MySQL. You may need to adjust the path to your “createDB.sql” file below if the rsyslog version has been updated 
#mysql -u root -p < mysql -u root -p < /usr/share/doc/rsyslog-mysql-5.8.10/createDB.sql
- It is best practice to limit database access for applications, so now we’ll set up a user specifically for LogAnalyzer and rsyslog that we’ll use to access the newly created rsyslog database. For even greater security you may want to set up separate accounts for both rsyslog and LogAnalyzer, since LogAnalyzer is only viewing the rsyslog database fewer privileges like select should be needed. For my environment using the same user is adequate. Notice with MySQL you can make access very granular and specify to only allow the rsyslog user database access from the localhost. Also we’ll execute the “flush privileges” MySQL command to activate our permissions changes immediately
#mysql -u root -p 
Mysql> GRANT ALL ON Syslog.* TO root@localhost IDENTIFIED BY 'Password';
Mysql> flush privileges;
Mysql> exit
 
ขั้นตอนที่ 3
ให้ทำการตั้งค่า rsyslog.conf ที่“/etc/rsyslog.conf”
Command line
#Vi /etc/rsyslog.conf
#### Module ####
$ModLoad imuxsock 
$ModLoad imklog 
#$ModLoad immark 
$ModLoad ommysql 
$ModLoad imudp
$UDPServerRun 514
$ModLoad imtcp
$InputTCPServerRun 514
$ModLoad ommail
$ModLoad ommysql
*.* :ommysql:127.0.0.1,Syslog,root,Password
( *.* :ommysql:database-server,database-name,database-userid,database-password //ทำให้ rsyslog เขียนลงฐานข้อมูล แก้ไข database-server,database-name,database-userid,database-password ให้ถูกต้องตามที่ตั้งไว้)
 ให้ทำการ save และออกจากโปรแกรม vi
ขั้นตอนที่ 5
ให้ทำการเปิด-ปิด service ของโปรแกรม rsyslog ถ้
#/etc/init.d/rsyslog restart
 

ขั้นตอนที่ 4
แก้ไขไฟล์ /etc/logrotate.d/rsyslog เพื่อ บีบอัดไพล์ log ให้มีขนาดเล็ก และแยกไพล์ log แยกเป็นวัน 
/var/log/messages // log file ที่ต้องการ rotate
#vi /var/log/messages
{
compress // บีบอัด log ที่ rotate
rotate 90 // rotate log ไว้ 90 วัน
daily // rotate log แยกเป็นรายวัน
missingok
notifempty
delaycompress
sharedscripts
postrotate
invoke-rc.d rsyslog reload > /dev/null
endscript
}
ให้ทำการ save และออกจากโปรแกรม vi

ให้ทำการ restart service rsyslog
#service rsyslog resatrt

ที่มา url : http://www.itsoul4u.com/index.php/marticle/8-articles/8-rsyslog