Posted by: kezhong | May 22, 2009

Writing rsyslog messages to MySQL on Fedora10

Recently, I’ve been studying how to write the rsyslog messages to MySQL on Fedora 10 system. Today, I finally made it work. The following is my steps:

The first terminal

Open the first terminal, and install MySQL.

# yum -y install mysql mysql-server

Start the service.

# service mysqld start

Set up the mysql database root password.

# mysqladmin -u root password ‘password’

Start a MySQL session and create the table syslog with only one field messages in database test.
#mysql -u root -p
mysql>show databases;
mysql>use test
mysql>create table syslog (messages varchar(100));
mysql>select * from syslog;

The result of checking is nothing.

The second terminal

Open the second terminal, and install rsyslog-mysql package.

# yum -y install rsyslog-mysql

Edit the file /etc/rsyslog.conf and append the below lines:
$ModLoad ommysql
$template dbtest, “insert into syslog(messages) values (‘%msg%’)”,SQL
*.*    :ommysql:127.0.0.1,test,root,password;dbtest

Restart the service of rsyslog.

# service rsyslog restart

Send the message to rsyslog.

# logger “This is a rsyslog test”

Return the first terminal, check again and will find the message have stored into database.

mysql>select * from syslog;

References

http://www.rsyslog.com/doc-rsyslog_mysql.html


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: