CentOS7.4搭建利用Rsyslog+LogAnalyzer+MySQL部署日志服务器
简介
LogAnalyzer 是一款syslog日志和其他网络事件数据的Web前端。它提供了对日志的简单浏览、搜索、基本分析和一些图表报告的功能。数据可以从数据库或一般的syslog文本文件中获取,所以LogAnalyzer不需要改变现有的记录架构。基于当前的日志数据,它可以处理syslog日志消息,Windows事件日志记录,支持故障排除,使用户能够快速查找日志数据中看出问题的解决方案。
LogAnalyzer 获取客户端日志会有两种保存模式,一种是直接读取客户端/var/log/目录下的日志并保存到服务端该目录下,一种是读取后保存到日志服务器数据库中,推荐使用后者。
LogAnalyzer 采用php开发,所以日志服务器需要php的运行环境,本文采用LAMP。
二、系统环境
Rsyslog Server OS:CentOS Linux release 7.4.1708 (Core) Rsyslog Server IP:192.168.123.100 Rsyslog 版本:rsyslog-8.24.0-12.el7.x86_64 LogAnalyzer 版本:LogAnalyzer 3.6.5 (v3-stable) Apache版本:httpd-2.4.6-67.el7.centos.x86_64
Mariadb版本(CentOS7版本以上):mariadb-5.5.56-2.el7.x86_64 PHP版本:php-5.4.16-42.el7.x86_64、php-gd-5.4.16-42.el7.x86_64
关闭防火墙:systemctl stop firewalld ; systemctl disable firewalld 关闭SElinux:setenforce 0 ; vi /etc/selinux/config SELINUX=disabled
关闭NetworkManager:systemctl stop NetworkManager ;systemctl disable NetworkManager
Rsyslog Client IP:192.168.123.101
修
改
三、安装并设置LAMP环境
3.1、安装LAMP环境
# yum -y install httpd mariadb-server mariadb php php-mysql
3.2 启动服务并加入开机启动
# systemctl start httpd # systemctl enable httpd # systemctl start mariadb # systemctl enable mariadb
3.3 设置MySQL root 密码
# mysqladmin -uroot password '123456'
3.4 测试php运行环境
# cat > /var/www/html/index.php << eof
> phpinfo(); > ?> > eof
四、安装服务器软件
安装rsyslog软件和rsyslog 连接MySQL数据库的模块 # yum -y install rsyslog rsyslog-mysql
五、配置服务器端
5.1 导入rsyslog-mysql 数据库文件
# cd /usr/share/doc/rsyslog-8.24.0/
# mysql -uroot -p123456 < mysql-createDB.sql
5.2 创建rsyslog用户在mysql下的相关权限
# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \\g. Your MariaDB connection id is 117
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement. MariaDB [(none)]> grant all on Syslog.* to rsyslog@localhost identified by '123456';
MariaDB [(none)]> flush privileges; MariaDB [(none)]>exit
5.3 配置rsyslog配置文件
# vi /etc/rsyslog.conf
在 #### MODULES #### 下添加下面两行: $ModLoad ommysql
*.* :ommysql:localhost,Syslog,rsyslog,123456
然后把下面三行前面的井号去掉:
$ModLoad immark #immark是模块名,支持日志标记 $ModLoad imudp
#imupd是模块名,支持udp协议
$UDPServerRun 514 #允许514端口接收使用UDP和TCP协议转发过来的日志
5.4、重启rsyslog服务
# systemctl restart rsyslog
六、配置客户端
6.1 检查rsyslog 是否安装
# rpm -qa|grep rsyslog
6.2 配置rsyslog 客户端发送本地日志到服务端
# vi /etc/rsyslog.conf
在最后一行增加下面这行内容,即客户端将本地日志发送到服务器。 *.* @192.168.123.100