zoukankan      html  css  js  c++  java
  • Centos7搭建日志服务器rsyslog+loganalyzer

    一、系统环境

    Rsyslog Server OS:CentOS 7

    Rsyslog Server IP:172.28.194.118

    Rsyslog Version: rsyslog-7.4.7-12.el7.x86_64

    LogAnalyzer Version: loganalyzer-4.1.7.tar.gz

    rsyslog-8.24.0-12.el7.x86_64(centos7默认安装)

    二、准备环境

    2.1  关闭防火墙:

    #systemctl stop firewalld
    2.2 将SELINUX设置为disabled
    setenforce 0
    sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g’ /etc/selinux/config

    三、配置LAMP环境

    3.1 配置LAMP

    yum -y install httpd mysql* php*

    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

    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 'Lanqing@123'; (修改密码)

    3.2 配置Apache和PHP

    yum install httpd -y

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

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

    systemctl start httpd.service

    systemctl enable httpd.service

    systemctl start mysqld.service

    systemctl enable mysqld.service

    3.4 测试PHP环境
    [root@localhost ~]# cd /var/www/html/
    [root@localhost html]# vim index.php

    <?php

    phpinfo();

    ?>

    打开浏览器访问:http://172.28.194.118/index.php

     

    四、安装服务器端软件

    4.1 检查是否安装了rsyslog软件

    rpm -qa|grep rsyslog

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

    yum install rsyslog-mysql –y

    五、配置服务器端

    5.1 导入rsyslog-mysql 数据库文件

    cd /usr/share/doc/rsyslog-8.24.0

    mysql -uroot -p<mysql-createDB.sql

    5.2 登录数据库查看

    mysql -uroot –p

     

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

    mysql> grant all on Syslog.* to rsyslog@‘localhost’ identified by 'Lanqing@123'

    mysql> flush privileges;

    mysql> exit

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

    以下为重点需要修改的地方!!!!!

    vi /etc/rsyslog.conf

     

    # Provides UDP syslog reception

    $ModLoad imudp

    $UDPServerRun 514

     

    # Provides TCP syslog reception

    $ModLoad imtcp

    $InputTCPServerRun 514

     

    $ModLoad ommysql

    *.* :ommysql:localhost,Syslog,rsyslog,Vxichina@123

    # Use default timestamp format

    $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

     

    $template Remote,"/var/log/data/%fromhost-ip%/%fromhost-ip%_%$YEAR%-%$MONTH%-%$DAY%.log"

    :fromhost-ip, !isequal, "127.0.0.1" ?Remote

     

    #Standard Redhat syslog settings

    .info;mail.none;authpriv.none;cron.none /var/log/messages

    authpriv. /var/log/secure

    mail.* -/var/log/maillog

    cron.* /var/log/cron

    .emerg *

    uucp,news.crit /var/log/spooler

    # Save boot messages also to boot.log

    local7.*                                                /var/log/boot.log

     

    $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

    客户端配置:(服务端可以不配置)

    再末尾添加服务器IP地址(接收日志的服务器IP)

    #vi /etc/rsyslog.conf
    *.* @172.28.194.118

    vi /etc/bashrc

    在文件尾部增加一行

    export PROMPT_COMMAND=’{ msg=$(history 1 | { read x y; echo KaTeX parse error: Expected 'EOF', got '}' at position 4: y; }̲);logger "[euid…(whoami)]":(whoami):[‘pwd‘]&quot; (who am i):[`pwd`]&quot;(whoami):[‘pwd‘]"msg"; }’

    #source /etc/bashrc  -----------------使其生效

    六、安装LogAnalyzer

    cd /home/rsyslog_server/tools/

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

    tar zxf loganalyzer-4.1.7.tar.gz

    cd loganalyzer-4.1.7

    mkdir -p /var/www/html/loganalyzer

    cp -rf src/* /var/www/html/loganalyzer/

    cp -rf contrib/* /var/www/html/loganalyzer

    重启服务

    systemctl restart rsyslog.service 

    systemctl start mysqld.service

    systemctl start httpd.service

    七、在浏览器中进行安装LogAnalyzer
    7.1 输入http://172.28.194.118/loganalyzer/,点击here

    !!!***File does NOT exist!!***!!!!!!!!!!

    提示错误:缺少config.php 文件,并且权限要设置为666,可以使用contrib目录下的configure.sh 脚本生成。

    需要在/var/www/html/loganalyzer/ 下创建config.php 文件,可以通过configure.sh文件生成

    cd /var/www/html/loganalyzer/

    sh configure.sh

     

    刷新网页恢复正常,点击next!!

    按照下图修改,一定要注意不要修改错了。

     

     

    设置管理账号密码!!!!

     

    这里 SystemEvents   S E 是大写的,SE一定要大写!!!!,下图的是小的events 有问题。

     

     

    ——————————————配置完成—————————————————————

  • 相关阅读:
    1.33 (累积互素数)
    1.33 (过滤累积和 求区间内所有素数之和)
    1.32 (更高层次的抽象! 乘法与加法本来就是一回事)
    1.31 (另一种求圆周率的算法)
    1.30 (递归的sum变迭代)
    习题1.29 (积分方法的优化---simpson规则)
    1.3.1 (对过程的抽象)
    SICP习题 1.23(素数查找的去偶数优化)
    SICP习题 1.22(素数)
    pom.xml
  • 原文地址:https://www.cnblogs.com/lanqing/p/10899867.html
Copyright © 2011-2022 走看看