How to Install RSyslog+MySQL with LogAnalyzer on CentOS

Gathering information message is important on Data Center, in some situations you’ll want to store all entries of logfiles on another server. If a server crashes or gets hacked it will be able to trace through  logfiles from your machine. this is can be accomplished by using centralized log server that receive messages from another hosts.  A syslog facility can receive messages from Unix/Linux hosts but also network devices and windows hosts.

In this post, I want to explain step installation of Rsyslog, and Centralized log using MySQL Database. And using LogAnalyzer web interface, for graphical view and administrative.

Step Installation:

1. First we need to install the following packages:

# yum install rsyslog rsyslog-mysql mysql-server php-mysql php-gd httpd mod_ssl

2. Configure rsyslog, mysqld, and httpd to run on startup:

#  chkconfig --add rsyslog
#  chkconfig --add mysqld
#  chkconfig --add httpd
#  chkconfig rsyslog on
#  chkconfig httpd on
#  chkconfig mysqld on
#  service rsyslog start
#  service mysqld start
#  service httpd start

3.  Configure RSyslog with MySQL Database Connection

Assuming for example:
user: root
password: sql password
host: localhost
db to create: Rsyslogdb
RSyslog-mysql database installation path: /usr/share/doc/rsyslog-mysql-2.0.0/createDB.sql

Create database:
# mysql –u root –psqlpassword
mysql> CREATE DATABASE Rsyslogdb;

Export rsyslog database table:
# mysql –u root –psqlpassword Rsyslogdb < /usr/share/doc/rsyslog-mysql-2.0.0/createDB.sql

Setup MySQL permission (must be same with /etc/rsyslog.conf and /path/to/loganalyzer/config.php)
# mysql –u root –psqlpassword
mysql> GRANT ALL ON Rsyslogdb.* TO ‘root’@’localhost’ IDENTIFIED BY 'sqlpassword';

4. Configure RSyslog

edit rsyslog configuration file
vi /etc/rsyslog.conf

add this line below:
$ModLoad ommysql
$ModLoad imuxsock
$ModLoad imklog
$Modload imudp
$UDPServerRun 514
$Modload imtcp
$InputTCPServerRun 514
## Optional
$UDPServerAddress 0.0.0.0
## Optional
$RepeatedMsgReduction ()
$template dbFormat,"insert into SystemEvents (Message, Facility,FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%', %syslogfacility%, '%HOSTNAME%',%syslogpriority%, '%timereported:::date-mysql%', '%timegenerated:::date-mysql%', %iut%, '%syslogtag%')",sql
*.*       : ommysql:localhost,Ryslog,root,sqlpassword
*.info;mail.none;authpriv.none;cron.none            /var/log/messages
authpriv.*                                          /var/log/secure
mail.*                                              /var/log/maillog
cron.*                                              /var/log/cron
*.emerg                                             *
uucp,news.crit                                      /var/log/spooler
local7.*                                             /var/log/boot.log

5. Restarting rsyslog service:
# service rsyslog restart

6. Centralized Syslog Server
Edit file:  /etc/sysconfig/rsyslog  (add this line)
# vi /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS="-m 0 -r"

7. Log Analyzer Installation
Download the latest installation :
http://loganalyzer.adiscon.com/downloads

# cd /tmp
# wget http://download.adiscon.com/loganalyzer/loganalyzer-3.0.6.tar.gz
# tar -zxvf loganalyzer-3.0.6.tar.gz
# cd /tmp/loganalyzer-3.0.6/src/
# mkdir /var/www/html/Rsyslog
# cp –R * /var/www/html/Rsyslog
# cp loganalyzer-3.0.6/contrib/configure.sh /var/www/html/
# chmod +x configure.sh
# ./configure.sh

After you execute configuration.sh files, it will create an empty config.php that used for Log Analyzer Configuration.

Open your favorite web browser and navigate into your homepage (i.e: http://localhost), then fill in and follow the Log Analyzer configuration steps to complete. From here RSyslog can be displayed on Show Events tab, choose MySQL Native to load your syslog messages on this machine into your RSyslog database on MySQL.

Done!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值