1.基本环境搭建
1.1 系统版本
cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)
1.2 关闭防火墙
systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启动
1.3 关闭selinux
vim /etc/selinux/configSELINUX=disabled
2.安装数据库
yum进行安装: yum install mariadb-server mariadb -y启动数据库: systemctl start mariadb.service查看状态: systemctl status mariadb.service设置开机自启: systemctl enable mariadb.service设置密码: mysqladmin -u root password '123456'修改数据文件存储位置: systemctl stop mariadb.servicemkdir /mysqldatacp -rp /var/lib/mysql/* /mysqldata/ cp -p /etc/my.cnf{,.bak}vim /etc/my.cnf修改datadir参数datadir=/mysqldata重启数据库:systemctl start mariadb.service
3.安装Apache及PHP
yum install httpd php php-gd php-xml php-mysql# systemctl start httpd.service# systemctl enable httpd.service测试php环境cd /var/www/htmlvim index.php 浏览器打开192.168.101.128 进行查看
4.服务器端配置软件rsyslog
#检查是否安装软件(系统默认安装) rpm -qa rsyslog #安装rsyslog 连接MySQL数据库的模块yum install rsyslog-mysql -y#导入日志数据库cd /usr/share/doc/rsyslog-7.4.7/mysql -u root -p < mysql-createDB.sql mysql -u root -p #登入数据库MariaDB [(none)]> show databases; #显示现有数据库 MariaDB [(none)]> use Syslog; MariaDB [Syslog]> show tables;#创建rsyslog用户,密码为123456MariaDB [Syslog]>create user 'rsyslog'@'localhost' identified by '123456'; #授予Syslog库下所有表的权限给rsyslog数据库用户MariaDB [Syslog]>grant all on Syslog.* to 'rsyslog'@'localhost';MariaDB [Syslog]>flush privileges;#插入来源ip的字段MariaDB [Syslog]>ALTER TABLE `SystemEvents` ADD COLUMN `FromIP` varchar(100) NULL AFTER `FromHost`;#修改rsyslog 配置文件cd /etc/rsyslog.dvim loganalyzer.conf$ModLoad immark # immark是模块名,支持日志标记$ModLoad imudp# imupd是模块名,支持udp协议$UDPServerRun 514#允许514端口接收使用UDP和TCP协议转发过来的日志$template insertpl,"insert into SystemEvents (Message, Facility, FromHost, FromIP, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%', %syslogfacility%, '%HOSTNAME%', '%fromhost-ip%', %syslogpriority%, '%timereported:::date-mysql%', '%timegenerated:::date-mysql%', %iut%, '%syslogtag%')",SQL$ModLoad ommysql *.warn;authpriv.* :ommysql:localhost,Syslog,rsyslog,123456;insertplsystemctl restart rsyslog.service#在服务器端验证日志是否写入数据库中:logger -p warn "nihao" tail -f /var/log/messages #本地日志中保留一份#在服务端mysql中查看,日志成功存放在数据库中mysql -u rsyslog -pmysql> use Syslog;mysql> select * from SystemEvents\G;验证成功!!!
5.客户端配置软件rsyslog
#检查是否安装软件(系统默认安装) rpm -qa rsyslog #修改rsyslog 配置文件 cd /etc/rsyslog.dvim client.conf*.warn;authpriv.* @192.168.101.128:514systemctl restart rsyslog.service在客户端验证,日志是否存放在服务器端数据库中:logger -p warn "nihaoma1" tail -f /var/log/messages #本地日志存放一份在服务端mysql中查看:mysql -u rsyslog -pmysql> use Syslog;mysql> select * from SystemEvents\G;验证成功!!!
编辑/etc/bashrc,将客户端执行的所有命令写入系统日志/var/log/messages中(可以选择)
# vi /etc/bashrc export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }' #在结尾处加上此内容设置使其生效# source /etc/bashrc
6.服务器端loganalyzer日志分析工具的搭建
wget http://download.adiscon.com/loganalyzer/loganalyzer-4.1.5.tar.gz tar -zxvf loganalyzer-4.1.5.tar.gz mkdir -p /var/www/html/loganalyzer/ cp -rp loganalyzer-4.1.5/src/* /var/www/html/loganalyzer/ cd /var/www/html/loganalyzer/ touch config.phpchmod 666 config.php
下面打开网页192.168.101.128/loganalyzer进行配置
下面开始配置loganalyzer显示来源ip
重新登入浏览器: 则显示来源ip
至此rsyslog与loganalyzer已配置完成。
最后详细loganalyzer操作,请参考