系统需求
mysql mysql-devel mysql-server php php-mysql php-pdo php-common php-gd httpd
yum install rsyslog
yum install rsyslog-mysql
service syslog stop
chkconfig syslog off
倒rsyslog数据库
cd /usr/share/doc/rsyslog-mysql-[version]/createDB.sql
mysql -u root -p < createDB.sql
编辑/etc/rsyslog.conf,修改并增加以下行
$ModLoad immark.so
$ModLoad imudp.so
$UDPServerRun 514
$ModLoad ommysql.so
*.* :ommysql:localhost,Syslog,root,123456
# 注 localhost 字节是database-server
# Syslog 是数据中database-name
# root 是database-userid
# frank 是root用户登录mysql的密码
#该行的格式
#*.* :ommysql:database-server,database-name,database-userid,database-password
#同样要注意的是database-name 必须和/usr/share/doc/rsyslog-mysql-[version]/createDB.sql 中的相同
service rsyslog start|stop|status
chkconfig --level 345 rsyslog on
安装loganalyzer 并修改权限
#tar xvf loganalyzer-3.0.4.tar.gz
#cd loganalyzer-3.0.4
#cp -r src/ /var/www/html/log
#cp -r contrib/* /var/www/html/log
#chown -R apache:apache /var/www/html/log
# cd /var/www/html/log
chmod a+x *sh
./configure.sh #创建config.php文件,并设置chmod 666 config.php的属性
http://IP/log
1)here
2)next
3)
Enable user database Yes
Database Host localhost
Database Port 3306
Database Name Syslog
Table prefix 空
Database User root
Database password ....
Require user to be logged in Yes
4)next
5)next
6)
username:admin
password:
repeat password:
7)
Name of the Source : My Syslog Source
Source Type : MYSQL Native
Select View : Syslog Field
Table type : MonitorWare
Database Host : localhost
Database Name : Syslog
Database Tablename : SystemEvents #注意大小写,否则登入以后提示talbes找不到
Database User : root
Databses password :
Enable Row counting Yes
8)next
./secure.sh 修改config.php文件属性chmod 644 config.php
9)登录
ps:如果出现无法连接数据库,或者显示mysql数据库没有记录,请慎重重新配置config.php文件,会导致数据库数据清空!
Linux客户端配置:
编辑/etc/rsyslog.conf
添加如下行
*.* @remoteIP:514
windows客户端配置:
为了收集windows日志,需要安装一个eventlog转换为syslog的工具,叫evtsys,可以到http://code.google.com/p/eventlog-to-syslog/下载,这个工具的好处是可以支持中文操作系统,如果你的系统没有中文系统,也可以下载一个叫nxlog的工具,把eventlog转换为syslog,这个工具不支持中文操作系统,经测试evtsys可以更好的转换系统日志,所以我们这里采用evtsys来搜集日志
解压缩放到 C:\Windows\System32
evtsys -i -s 10 -h log-server-ip -p 514
net start evtsys
在安装的时候,会报一个错误,是配置文件的问题,可以忽略它,只要看到最后的安装成功即可。以下附上evtsys命令的详细参数:
Version: 4.4 (32-bit)
Usage: evtsys.exe -i|-u|-d [-h host] [-b host] [-f facility] [-p port]
[-s minutes] [-l level] [-n]
-i Install service
-u Uninstall service
-d Debug: run as console program
-h host Name of log host
-b host Name of secondary log host (optional)
-f facility Facility level of syslog message
-l level Minimum level to send to syslog.\n", stderr);
0=All/Verbose, 1=Critical, 2=Error, 3=Warning, 4=Info
-n Include only those events specified in the config file.
-p port Port number of syslogd
-q bool Query the Dhcp server to obtain the syslog/port to log to
(0/1 = disable/enable)
-s minutes Optional interval between status messages. 0 = Disabled
Default port: 514
Default facility: daemon
Default status interval: 0
Host (-h) required if installing.
配置完成后即可在loganalyzer 页面上显示日志信息。
PS:evtsys解决windows中文客户端乱码问题
修改 functions_common.php以支持中文
vi /var/www/html/loganalyzer/include/functions_common.php
将 return htmlentities($myStr, ENT_NOQUOTES, $content['HeaderDefaultEncoding']); //"UTF-8");
修改为 return htmlspecialchars($myStr, ENT_NOQUOTES, $content['HeaderDefaultEncoding']); //"UTF-8");
或者return htmlentities($myStr,ENT_QUOTES,"UTF-8");
然后重启rsyslog服务,这时即可支持中文
PS:当你的数据量每天增长很快时,单表数据很大导致查询很慢,这时可以采取分区或者分表操作
分区:
use Syslog;
CREATE TABLE SystemEvents
(
ID int unsigned not null auto_increment,
CustomerID bigint,
ReceivedAt datetime NULL,
DeviceReportedTime datetime NULL,
Facility smallint NULL,
Priority smallint NULL,
FromHost varchar(60) NULL,
Message text,
NTSeverity int NULL,
Importance int NULL,
EventSource varchar(60),
EventUser varchar(60) NULL,
EventCategory int NULL,
EventID int NULL,
EventBinaryData text NULL,
MaxAvailable int NULL,
CurrUsage int NULL,
MinUsage int NULL,
MaxUsage int NULL,
InfoUnitID int NULL ,
SysLogTag varchar(60),
EventLogType varchar(60),
GenericFileName VarChar(60),
SystemID int NULL,
primary key (ID,DeviceReportedTime)
)ENGINE=InnoDB
PARTITION BY RANGE (TO_DAYS (DeviceReportedTime)) (
PARTITION s201407 VALUES LESS THAN (TO_DAYS('2014-08-01')),
PARTITION s201408 VALUES LESS THAN (TO_DAYS('2014-09-01')),
PARTITION s201409 VALUES LESS THAN (TO_DAYS('2014-10-01')),
PARTITION s201410 VALUES LESS THAN (TO_DAYS('2014-11-01')),
PARTITION s201411 VALUES LESS THAN (TO_DAYS('2014-12-01')),
PARTITION s201412 VALUES LESS THAN (TO_DAYS('2015-01-01')),
PARTITION p1 VALUES LESS THAN (MAXVALUE)
);
执行以下命令查询创建的分区
SELECT PARTITION_NAME,TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS;