CentOS7.9安装rsyslog+loganalyzer日志服务器详细配置


1、CentOS7.9安装rsyslog+loganalyzer日志服务器详细配置

https://blog.csdn.net/alanpo_/article/details/107619133?spm=1001.2101.3001.6650.17&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-17-

CentOS7+Rsyslog+MySQL 搭建 Rsyslog 日志服务器

 https://blog.csdn.net/u010383467/article/details/107434225?ops_request_misc=&request_id=&biz_id=102&utm_term=centos%20%E5%AE%89%E8%A3%85rsyslog%20%E8%BF%9E%E6%8E%A5mysql&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-3-107434225.142^v46^pc_rank_34_2&spm=1018.2226.3001.4187

https://blog.csdn.net/weixin_31789689/article/details/108556277?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166236952216782395349015%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=166236952216782395349015&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~pc_rank_v39-7-108556277-null-null.142^v46^pc_rank_34_2&utm_term=centos%20%E5%AE%89%E8%A3%85rsyslog%20%E8%BF%9E%E6%8E%A5mysql&spm=1018.2226.3001.4187

 一、简介:

随着机房内的服务器和网络设备增加,日志管理和查询就成了让系统管理员头疼的事。

系统管理员遇到的常见问题如下:

1、日常维护过程中不可能登录到每一台服务器和设备上去查看日志;

2、网络设备上的存储空间有限,不可能存储日期太长的日志,而系统出现问题又有可能是很久以前发生的某些操作造成的;

3、在某些非法入侵的情况下,入侵者一般都会清除本地日志,清除入侵痕迹;

4、zabbix等监控系统无法代替日志管理,无法监控如系统登录、计划任务执行等项目。

基于上述原因,在当前的网络环境中搭建一台用于日志集中管理的Rsyslog日志服务器就显得十分有必要了。

Rsyslog服务的优点如下:

1、Rsyslog服务器可以大多数的网络设备支持,在网络设备的系统设备选项中大多都有远程日志服务的配置选项。只需要填写上IP地址和端口(大多数设备已经默认是514了),然后确定就可以了;

2、Linux服务器只需要在本地的Rsyslog服务配置中加入简单的一行就可以将日志发送到日志服务器,布署和配置起来十分简单;

3、通过软件(如evtsys)也可以支持Windows服务器,布署和配置也不是很难,但是有些软件是要收费的;

4、搭配前端的loganalyzer等软件,可以轻松实现图形化管理和查询日志。

二、系统环境及软件版本:

Rsyslog_server: CentOS7.9

Rsyslog_server IP:172.18.10.253

Rsyslog_client: CentOS7.9+ Windows10

所用软件:

Rsyslog Version: rsyslog-8.24.0-55.el7.x86_64

LogAnalyzer Version: loganalyzer-3.6.5.tar.gz

MySQL Version:MySQL5.7

Httpd Version:httpd-2.4.6-40.el7.centos.x86_64

PHP Version:php-5.4.16-36.el7_1.x86_64

三、环境准备:

3.1 关闭防火墙:

systemctl stop firewalld

3.2 将SELINUX设置为disabled

setenforce 0

sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g’ /etc/selinux/config

 

四、配置LAMP环境:

4.1 安装MySQL,由于CentOS7默认会安装Mariadb,因此使用MySQL官方提供快速的安装方法,地址:MySQL :: A Quick Guide to Using the MySQL Yum Repository

#mkdir /home/rsyslog_server/tools -p        #创建下载文件存放目录

#cd /home/rsyslog_server/tools

#yum install wget -y

#wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

#rpm -Uvh mysql57-community-release-el7-8.noarch.rpm        #安装MySQL官方yum仓库

#yum install mysql-community-server -y         #安装MySQL

 安装不成功,有如下提示

Failing package is: mysql-community-common-5.7.38-1.el7.x86_64

GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

 出现上述提示原因是Mysql的GPG升级了,需要重新获取

执行: rpm –import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

 再次进行服务安装:yum install mysql-community-server -y

#systemctl start mysqld.service

#systemctl status mysqld.service

#grep ‘temporary password’ /var/log/mysqld.log                        #查看初始密码

#mysql -u root -p

>ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘P@ssw0rd’;    #更改密码,密码需要符合以下规则:至少一个大写字母,一个小写字母,一个数字,一个特殊字符,而且密码长度需要超过8位

>exit

4.2 安装Apache及PHP

#yum install httpd -y

#yum install php php-gd php-xml php-mysql -y

4.3 启动服务并加入开机自启动:

#systemctl start httpd.service

#systemctl enable httpd.service

#systemctl start mysqld.service

#systemctl enable mysqld.service

4.4 测试PHP环境

#vi index.php

<?php

phpinfo()

?>

在浏览器中输入http://172.18.10.253/index.php,若显示以下内容,则配置成功。

 五、检查并安装服务端软件

5.1 检查是否安装了rsyslog软件

#rpm -qa rsyslog                  #CentOS7默认会安装rsyslog

5.2 安装rsyslog 连接MySQL数据库的模块

#yum install rsyslog-mysql -y     #rsyslog使用此模块将数据传入MySQL数据库,必须安装

六、配置服务器端

6.1 导入rsyslog-mysql 数据库文件

#cd /usr/share/doc/rsyslog-8.24.0/

#mysql -uroot -p <mysql-createDB.sql

Enter password:

6.2 登录数据库查看:

mysql> show databases;

mysql> show tables;

导入数据库操作创建了Syslog 库并在该库中创建了两张空表SystemEvents 和SystemEventsProperties。

6.3 在MySQL下创建rsyslog用户并授权:

mysql> grant all on Syslog.* to rsyslog@’localhost’ identified by ‘P@ssw0rd’;

mysql> flush privileges;

mysql> exit

6.4 配置服务端支持rsyslog-mysql 模块,并开启UDP服务端口获取网内其他LINUX系统日志;

#vi /etc/rsyslog.conf                             #按如下进行更改

#### MODULES ####

$Modload ommysql

*.* :ommysql:localhost,Syslog,rsyslog,MyNewPass4!        #localhost 表示本地主机,Syslog 为数据库名,rsyslog 为数据库的用户,123456为该用户密码。   

$ModLoad immark                                # immark是模块名,支持日志标记

$ModLoad imudp                                 #imupd是模块名,支持udp协议

$UDPServerRun 514                              #允许514端口接收使用UDP和TCP协议转发过来的日志

# rsyslog configuration file

# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html

#### MODULES ####
$Modload ommysql
*.* :ommysql:localhost,Syslog,rsyslog,P@ssw0rd

# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
#$ModLoad imklog # reads kernel messages (the same are read from journald)
#$ModLoad immark  # provides –MARK– message capability

# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

# Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514

#### GLOBAL DIRECTIVES ####

# Where to place auxiliary files
$WorkDirectory /var/lib/rsyslog
$AllowedSender udp, 172.18.0.0/16

# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$template Remote,”/opt/PA/rsyslog/logs%fromhost-ip%/%fromhost-ip%_%$YEAR%-%$MONTH%-%$DAY%-%$HOUR%.log”
:fromhost-ip, !isequal, “127.0.0.1” ?Remote

# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on

# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf

# Turn off message reception via local log socket;
# local messages are retrieved through imjournal now.
$OmitLocalLogging on

# File to store the position in the journal
$IMJournalStateFile imjournal.state

#### RULES ####

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                                 /dev/console

# Log anything (except mail) of level info or higher.
# Don’t log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                /var/log/messages

# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog

# Log cron stuff
cron.*                                                  /var/log/cron

# Everybody gets emergency messages
*.emerg                                                 :omusrmsg:*

# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler

# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log

# ### begin forwarding rule ###
# The statement between the begin … end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g   # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList   # run asynchronously
#$ActionResumeRetryCount -1    # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###
6.5 重启rsyslog服务

#systemctl restart rsyslog.service

七、配置客户端

7.1 检查客户端有没有安装rsyslog

#rpm -qa rsyslog

7.2 配置rsyslog客户端发送本地日志到服务端

#vi /etc/rsyslog.conf

*.* @172.18.10.253:514        #在文件结尾处增加此内容

7.3 重启rsyslog服务

#systemctl restart rsyslog.service

7.4 编辑/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

八、测试rsyslog_server可否正常接收rsyslog_client的日志

rsyslog_client执行以下操作:

rsyslog_server查看:

说明服务端可以正常接收客户端的日志。

九、安装LogAnalyzer

#cd /home/rsyslog_server/tools/

#wget http://download.adiscon.com/loganalyzer/loganalyzer-4.1.12.tar.gz

由于下载不了直接从官网下载上传到服务器:Download – Adiscon LogAnalyzer

 #tar zxvf loganalyzer-4.1.12.tar.gz

#cd loganalyzer-4.1.12

#mkdir -p /var/www/html/loganalyzer

#cp -a src/* /var/www/html/loganalyzer/

十、在浏览器中进行安装LogAnalyzer

10.1 打开浏览器,输入http://172.18.10.253/loganalyzer

提示无配置文件,点击here按钮生成;

10.2 点击next进行系统环境测试:

此处提示没有config.php文件,使用contrib中的configure.sh脚本可生成;

#cd contrib/

#cp configure.sh /var/www/html/loganalyzer/

#cd /var/www/html/loganalyzer/

#sh configure.sh

#ls

此部分操作在/var/www/html/loganalyzer/目录下创建config.php文件并配置权限为666,也可以使用mkdir及chmod命令执行。

#chmod 666 config.php

10.3 点ReCheck继续下一步,填写数据库信息

基本配置

10.4点击next生成数据库中的表;

 10.5 检查SQL结果

10.6创建管理用户

如无法创建先修改logcon_users,允许last_login为空值,如下图:(如无次操作将导致用户无法建立)然后进行创建账号

10.7创建第一个系统日志source

10.8完成

 二、测试

LogAnalyzer 首页

http://172.18.10.253/loganalyzer/index.php

点击任何一条记录,查看详情

查看Statistics

 登录测试

登陆成功

在Admin Center 里可以进行一些系统设置

 Rsyslog + LogAnalyzer 日志服务器部署完毕,可根据需要进行设置。
————————————————
版权声明:本文为CSDN博主「Arnold.Shen」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sgj584520/article/details/126014911


 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/287835.html

(0)
上一篇 2022年9月6日 03:42
下一篇 2022年9月6日 03:42

相关推荐

发表回复

登录后才能评论