關閉SeLinuxphp
一、 環境html
centos7 Rsyslog、loganalyzer+數據庫服務器 ,IP地址爲:10.41.1.87mysql
客戶端:10.41.1.85web
二、 Rsyslog的安裝與配置sql
安裝數據庫:數據庫
yum install mariadb-serverapache
啓動數據庫centos
systemctl start mariadb.service服務器
[root@localhost ~]# netstat -lntup|grep 3306tcp
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1688/mysqld
配置數據庫
mysql_secure_installation#默認root沒有密碼
安裝數據庫驅動包
yum install rsyslog-mysql #rsyslog連接數據庫須要使用此驅動包
rpm -ql rsyslog-mysql #看看安裝了哪些文件
[root@localhost ~]# rpm -ql rsyslog-mysql
/usr/lib64/rsyslog/ommysql.so
/usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
建立日誌用戶
mysql -uroot -p
grant all on Syslog.* to loguser@'10.41.%.%' identified by '111111';
flush privileges;
驗證:
mysql -uloguser -p111111 -h10.41.1.87
導入數據庫:
mysql -uloguser -h10.41.1.87 -p </usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
查看:
mysql -uloguser -p111111 -h10.41.1.87
show databases; //查看是否有Syslog數據庫
use Syslog;
show tables;
配置rsyslog服務器能夠使用mysql:
#### MODULES ####
$ModLoad ommysql
##信息模板
$template MySQLInsert,"insert into SystemEvents (Message, Facility, FromHost,Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%', %syslogfacility%, '%fromhost-ip%', %syslogpriority%, '%timereported:::date-mysql%', '%timegenerated:::date-mysql%', %iut%, '%syslogtag%')",SQL
#### RULES ####
*.info;mail.none;authpriv.none;cron.none :ommysql:10.41.1.87,Syslog,loguser,111111;MySQLInsert
# *.info;mail.none;authpriv.none;cron.none :ommysql:10.41.1.87,Syslog,loguser,111111
說明:
ommysql :模塊
10.41.1.87 : 服務器IP
Syslog : 數據庫名
loguser : 登入用戶
111111 : 密碼
重啓服務:
systemctl restart rsyslog
本機測試:
logger "this is a test log"
use Syslog;
select count(*) from SystemEvents;
select * from SystemEvents;
select * from SystemEvents\G
三、 apache安裝
yum install httpd php php-mysql php-gd
systemctl start httpd
netstat -lntup|grep 80
四、 loganalyzer-4.1.7安裝
tar zxf loganalyzer-4.1.7.tar.gz
mkdir /var/www/html/log
mv loganalyzer-4.1.7/src/* /var/www/html/log
cd /var/www/html/log
chmod +x ~/loganalyzer-4.1.7/contrib/configure.sh
chmod +x ~/loganalyzer-4.1.7/contrib/secure.sh
~/loganalyzer-4.1.7/contrib/configure.sh
~/loganalyzer-4.1.7/contrib/secure.sh
chown -R apache.apache ..//log
web配置:
配置loganalyzer數據庫:
添加loganalyzer的admin用戶和密碼
SystemEvents頁面中爲小寫,改成大寫開頭,否則提示錯誤。
五、 客戶端配置
Tcp:
rsyslog.conf:
#### MODULES ####
$ModLoad imtcp
$InputTCPServerRun 514
$template myFormat,"10.41.1.85_34 %syslogpriority% %timestamp% %hostname% %syslogtag% %msg%"
#### RULES ####
*.* @@10.41.1.87:514;myFormat#兩個「@」
UDP:
$template myFormat,"192.168.82.129_34 %syslogpriority% %timestamp% %hostname% %syslogtag% %msg%"
*.* @192.168.92.1:9898;myFormat#一個」@」
六、 漢化包
[root@localhost lang]# pwd
/var/www/html/log/lang
mkdir zh
cd zh
上傳中文漢化包