Rsyslog 日志服务器
实现了基本的syslog协议
直接兼容syslogd的syslog.conf配置文件
在同一台机器上支持多个rsyslogd进程,支持多线程
丰富的过滤功能,可以实现过滤日志信息中的任何部分,可将消息过滤后在转发
灵活的配置选项,配置文件中可以写简单的逻辑判断,自定义输出格式等
增加了重要的功能,如使用tcp进行消息传输,支持UDP,TCP,SSL,TLS,RELP
有现成的前端web展示程序
可以使用MySQL,PGSQL,Oralce实现日志存储
默认安装的rsyslog软件包提供的守护进程是rsyslog,它是一项系统的基础服务,应该设置开机运行
loganalyzer是一款syslog日志和其他网络时间数据的web前端,它提供了对日志的简单浏览、搜索、基本分析和一些图表报告的功能。数据可以从数据库或一般syslog文本文件中获取,所有loganalyzer不需要改变现有的记录架构。基于当前的日志数据,它可以处理syslog日志消息windows事件日志记录,支持故障排除,使用户能快速查找日志数据中看出问题的解决方案
loganalyzer 获取客户端日志会有两种保存模式,一种是直接读取客户端/var/log目录下的日志并保存到服务端该目录下,一种是读取后保存日志服务器数据库中,这里测试的是mariadb数据库
loganalyzer采用php开发,所以服务需要php的运行环境,这里用的lnmp**
角色 | 主机名 | IP地址 |
---|---|---|
web | web1 | 192.168.145.132 |
mysql | mysql | 192.168.145.133 |
rsyslog-mysql | web3 | 192.168.145.134 |
[root@web1 ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
[root@web1 ~]# yum -y install nginx
[root@web1 ~]# rpm -qa | grep nginx
nginx-mod-stream-1.16.1-1.el7.x86_64
nginx-1.16.1-1.el7.x86_64
nginx-filesystem-1.16.1-1.el7.noarch
nginx-mod-http-perl-1.16.1-1.el7.x86_64
nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64
nginx-mod-http-image-filter-1.16.1-1.el7.x86_64
nginx-mod-mail-1.16.1-1.el7.x86_64
nginx-all-modules-1.16.1-1.el7.noarch
[root@web1 ~]# yum -y install php-fpm
[root@web1 ~]# rpm -qa | grep php-fpm
php-fpm-5.4.16-48.el7.x86_64
[root@web1 ~]# yum -y install rsyslog rsyslog-mysql
[root@web1 ~]# rpm -qa | grep rsyslog
rsyslog-mysql-8.24.0-52.el7_8.2.x86_64
rsyslog-8.24.0-52.el7_8.2.x86_64
[root@web1 ~]# yum -y install mariadb mariadb-server
[root@web1 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.65-1.el7.x86_64
mariadb-5.5.65-1.el7.x86_64
mariadb-server-5.5.65-1.el7.x86_64
[root@web1 ~]# cp /etc/rsyslog.conf{,.bak}
[root@web1 ~]# vim /etc/rsyslog.conf
$ModLoad imtcp 放开端口
$InputTCPServerRun 514
#*.info;mail.none;authpriv.none;cron.none /var/log/messages
*.info;mail.none;authpriv.none;cron.none @192.168.145.134 指向后端rsyslog服务器web3
# web3服务器配置为 rsyslog-server
[root@web3 ~]# vim /etc/rsyslog.conf
$ModLoad imudp
$UDPServerRun 514 # 指定端口
[root@web3 ~]# systemctl restart rsyslog
[root@web3 ~]# systemctl enable rsyslog
web1 rsyslog-client 测试
[root@web1 ~]# systemctl restart rsyslog.service
web3 rsyslog-server 验证
[root@rsyslog-mysql-web3 ~]# tail -f /var/log/messages
Jul 25 16:26:34 rsyslog-mysql-web3 systemd: Started System Logging Service.
Jul 25 16:26:40 rsyslog-mysql-web3 systemd: Reloading.
Jul 25 16:35:36 web1 systemd: Stopping System Logging Service...
Jul 25 16:35:36 web1 rsyslogd: [origin software="rsyslogd" swVersion="8.24.0-52.el7_8.2" x-pid="12508" x-info="http://www.rsyslog.com"] exiting on signal 15.
Jul 25 16:35:36 web1 systemd: Stopped System Logging Service.
Jul 25 16:35:36 web1 systemd: Starting System Logging Service...
Jul 25 16:35:36 web1 rsyslogd: [origin software="rsyslogd" swVersion="8.24.0-52.el7_8.2" x-pid="14563" x-info="http://www.rsyslog.com"] start
Jul 25 16:35:36 web1 systemd: Started System Logging Service.
1、web3 上安装mysql数据库
[root@rsyslog-mysql-web3 ~]# yum install mariadb-server mariadb
2、查看是否安装 rsyslog
[root@web1 ~]# rpm -qa | grep rsyslog
rsyslog-mysql-8.24.0-52.el7_8.2.x86_64
rsyslog-8.24.0-52.el7_8.2.x86_64
3、配置 mysql 数据库
[root@rsyslog-mysql-web3 ~]# systemctl restart mariadb
[root@rsyslog-mysql-web3 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>use mysql; # 修改root密码1
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> update user set password=password('123.com') where user='root'; # 改root密码2
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
MariaDB [mysql]> GRANT ALL ON Syslog.* TO 'Syslog'@'192.168.%.%'IDENTIFIED BY '123.com'; # 授权syslog
Query OK, 0 rows affected (0.00 sec)
27
MariaDB [mysql]> FLUSH PRIVILEGES; #刷新
Query OK, 0 rows affected (0.01 sec)
MariaDB [mysql]>
[root@web1 ~]# less /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
CREATE DATABASE Syslog;
USE Syslog;
CREATE TABLE SystemEvents
[root@web1 ~]# mysql -uSyslog -h192.168.145.134 -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
5、数据库优化
[root@rsyslog-mysql-web3 ~]# vim /etc/my.cnf
在[mysqld]中添加
skip_name_resolve=on # 这个参数是禁止域名解析
innodb_file_per_table=on # 共享表空间转化为独立表空间
[root@rsyslog-mysql-web3 ~]# systemctl restart mariadb
6、重定向导入数据库
[root@web1 ~]# mysql -uSyslog -h192.168.145.134 -p < /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
Enter password:
7、数据库有了,修改配置文件
[root@web1 ~]# vim /etc/rsyslog.conf
#### MODULES ####
$ModLoad ommysql
#### RULES ####
#*.info;mail.none;authpriv.none;cron.none /var/log/messages
#*.info;mail.none;authpriv.none;cron.none @192.168.145.134
*.info;mail.none;authpriv.none;cron.none :ommysql:192.168.145.134,Syslog,Syslog,123.com
[root@web1 ~]# systemctl restart rsyslog
8、测试
在web3 上数据库看一下有没有写入
[root@rsyslog-mysql-web3 ~]# mysql -uroot -p
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| Syslog |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> use Syslog;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [Syslog]> show tables;
+------------------------+
| Tables_in_Syslog |
+------------------------+
| SystemEvents |
| SystemEventsProperties |
+------------------------+
2 rows in set (0.00 sec)
MariaDB [Syslog]> select count(*) from SystemEvents;
+----------+
| count(*) |
+----------+
| 11 |
+----------+
1 row in set (0.00 sec)
MariaDB [Syslog]> select *from SystemEvents\G # 竖排显示
.....
1、lnmp 环境
web1 上配置lnmp修改nginx配置文件添加端口方式的虚拟主机
[root@web1 ~]# yum install mysql-server mysql-devel httpd php-mysql php php-gd php-xml -y
2、配置loganalyzer
[root@web1 ~]# wget http://download.adiscon.com/loganalyzer/loganalyzer-4.1.10.tar.gz
[root@web1 ~]# cp -r loganalyzer-4.1.10/src/* /loganalyzer/
[root@web1 ~]# cp loganalyzer-4.1.10/contrib/* /loganalyzer/
[root@web1 ~]# cd /loganalyzer/
[root@web1 loganalyzer]# ls
admin cron index.php search.php
asktheoracle.php css install.php secure.sh
BitstreamVeraFonts details.php js statistics.php
chartgenerator.php export.php lang templates
classes favicon.ico login.php themes
configure.sh images reportgenerator.php userchange.php
convert.php include reports.php
[root@web1 loganalyzer]# chmod +x *.sh
[root@web1 loganalyzer]# ./configure.sh
[root@web1 loganalyzer]# ./secure.sh
[root@web1 loganalyzer]# chmod 666 config.php
3、修改nginx配置文件,添加虚拟主机
[root@web1 ~]# cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name 192.168.145.132;
index index.html index.htm index.php;
charset utf-8;
root /loganalyzer;
location / {
#max_fails=6;
#fail_timeout=60;
root /loganalyzer;
}
location ~.*\.php$ {
fastcgi_connect_timeout 300;
root /loganalyzer;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
#max_fails=6;
#fail_timeout=60;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
#fastcgi_pass unix:/dev/shm/php-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
try_files $uri = 404;
}
location ~.*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$ {
expires 30d;
}
location ~.*\.(js|css)$ {
expires 12h;
}
}
server {
listen 81;
server_name 192.168.145.132;
index index.html index.htm index.php;
charset utf-8;
root /usr/share/zabbix;
location / {
#max_fails=6;
#fail_timeout=60;
root /usr/share/zabbix;
}
location ~.*\.php$ {
fastcgi_connect_timeout 300;
root /usr/share/zabbix;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
#max_fails=6;
#fail_timeout=60;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
#fastcgi_pass unix:/dev/shm/php-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
try_files $uri = 404;
}
location ~.*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$ {
expires 30d;
}
location ~.*\.(js|css)$ {
expires 12h;
}
}
4、web端配置
-------------------------------------------------------------------------人生有所缺憾,才会让人向往完美----------------------------------------------------------