背景:php
網絡安全法第三章第二十一條明確規定「採起監測、記錄網絡運行狀態、網絡安全事件的技術措施,並按照規定留存相關的網絡日誌很多於六個月」。html
爲了知足合規性的要求,應當建設相應的日誌採集存儲系統。mysql
市面上很多日誌系統價格不菲,因此考慮在Centos 7.6環境下,基於MariaDB 和 Rsyslog,搭建開源免費的日誌採集分析系統LogAnalyzer。linux
固然啦,ELK也能夠,Prometheus + Grafana也OK。sql
本文參考了很多網絡資料,感謝熱愛分享的人們!數據庫
-------------------------------------------------------------------------------------------------------------------------------------------------------------apache
軟件:安全
① VMware Workstation 15 Player網絡
② CentOS-7-x86_64-Minimal-1810.isotcp
③ loganalyzer-4.1.11.tar.gz
④ loganalyzer-4.1.11中文語言包.zip
-------------------------------------------------------------------------------------------------------------------------------------------------------------
一、建立新虛擬機
二、稍後安裝操做系統
三、選擇Linux,版本爲CentOS 7 64位
四、填寫虛擬機名稱:CentOS7,位置爲C:\vm
五、設置磁盤大小爲10G,選擇將虛擬磁盤存儲爲單個文件
六、點擊完成
七、點擊編輯虛擬機設置
八、設置內存爲2048MB
九、設置CD/DVD,使用的ISO文件爲CentOS-7-x86_64-Minimal-1810.iso
十、設置網絡適配器,網絡鏈接爲橋接模式
十一、播放虛擬機
十二、鍵盤上下鍵選中Install CentOS 7
1三、出現VMware Tools,點擊之後提醒我
1四、選中語言爲中文
1五、點擊系統,選擇安裝位置
1六、使用自動配置分區,點擊完成
1七、點擊開始安裝
1八、點擊ROOT密碼進行設置
1九、設置ROOT密碼爲123456
20、正在安裝
2一、安裝完成後重啓虛擬機
2二、重啓後,輸入帳號:root,輸入密碼:123456進入系統
2三、輸入:cd /,輸入:ip addr查看網絡配置
2四、輸入:cd /etc/sysconfig/network-scripts/,輸入:ls查看目錄
2五、輸入:vi ifcfg-ens33,默認配置以下:
修改成以下:
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.20.123
NETMASK=255.255.255.0
GATEWAY=192.168.20.240
輸入:wq,進行保存
2六、輸入:service network restart,重啓網絡服務
2七、嘗試ping一下百度,輸入:ping www.baidu.com,發現ping不通,懷疑是DNS問題
2八、須要設置DNS,
輸入:vi /etc/resolv.conf
2九、填寫DNS內容,
輸入:nameserver 114.114.114.114
輸入:nameserver 8.8.8.8
輸入:wq,進行保存
30、再次重啓網絡服務,
輸入:service network restart
3一、再次輸入:ping www.baidu.com,這下能ping通了
3二、查看rsyslog是否安裝,以及CentOS版本信息,
輸入:cd /,輸入:rpm –qa | grep rsyslog
輸入:cat /etc/redhat-release
3三、關閉防火牆,
輸入:systemctl stop firewalld.service
輸入:systemctl disable firewalld.service
輸入:systemctl status firewalld.service
3四、關閉selinux,輸入:vi /etc/selinux/config,修改後重啓操做系統
默認以下
設置SELINUX=disabled
3五、查看MariaDB是否安裝,輸入:cd /,輸入:rpm –qa | grep mariadb,發現只有mariadb-libs
3六、安裝MariaDB服務,
輸入:yum -y install mariadb mariadb-server
3七、再次查看MariaDB安裝狀況,輸入:rpm –qa | grep mariadb
3八、啓動MariaDB服務,並設置爲開機啓動,
輸入:systemctl start mariadb.service,
輸入:systemctl enable mariadb
3九、設置MariaDB的密碼,
輸入:cd /root
輸入:/bin/mysql_secure_installation
設置帳號root,密碼123456
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):<– 初次運行直接回車
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <– 是否設置root用戶密碼,輸入y並回車或直接回車
New password: <– 設置root用戶的密碼
Re-enter new password: <– 再輸入一次設置的密碼
Password updated successfully!
Reloading privilege tables…
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] <– 是否刪除匿名用戶,生產環境建議刪除,因此直接回車
… Success!
Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <– 是否禁止root遠程登陸,根據本身的需求選擇y並回車,建議禁止
… Success!
By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] <– 是否刪除test數據庫,直接回車
Dropping test database…
… Success!
Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <– 是否從新加載權限表,直接回車
… Success!
Cleaning up…
All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
40、輸入:mysql -uroot –p123456,進入MariaDB
4一、建立rsyslog數據庫(用來存放LogAnalyzer系統的配置信息),字符編碼設置爲utf-8,
輸入:create database rsyslog character set utf8 collate utf8_bin;
4二、查看當前有幾個數據庫,
輸入:show databases;
4三、爲rsyslog數據庫建立本地用戶rsyslog,設置密碼爲rsyslog,權限爲所有權限,
輸入:grant all privileges on rsyslog.* to ‘rsyslog’@’localhost’ identified by ‘rsyslog’;flush privileges;
4四、輸入:exit
退出MariaDB
4五、安裝rsyslog的MySQL擴展程序包rsyslog-mysql,
輸入:yum -y install rsyslog-mysql
4六、將rsyslog的MySQL表導入建立的rsyslog數據庫,
輸入:mysql -uroot -p < /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
4七、查看當前有幾個數據庫,輸入:show databases;
多了一個Syslog數據庫
4八、使用Syslog數據庫,輸入:use Syslog;
查看Syslog數據庫下有幾個表,輸入:show tables;
顯然SystemEvents表用來存放日誌記錄
4九、爲Syslog數據庫建立本地用戶rsyslog,設置密碼爲rsyslog,權限爲所有權限,
輸入:grant all privileges on Syslog.* to ‘rsyslog’@’%’ identified by ‘rsyslog’;flush privileges;
50、修改rsyslog配置文件,
輸入:vi /etc/rsyslog.conf
默認以下:
修改成以下:
新增:
$ModLoad ommysql
*.*:ommysql:localhost,Syslog,rsyslog,rsyslog
去除以下內容前面的#:
$ModLoad imudp
$UDPServerRun 514
$ModLoad imtcp
$InputTCPServerRun 514
輸入:wq,保存並退出
5一、啓動rsyslog服務並設置爲開機啓動,
輸入:systemctl restart rsyslog.service
輸入:systemctl enable rsyslog.service
5二、安裝LAMP環境,
輸入:yum install httpd php php-mysql php-gd –y
5三、建立相應的目錄用來存放loganalyzer的解壓文件和運行後生成的日誌,
輸入:mkdir -p /var/www/html/log
輸入:mkdir -p /var/log/httpd/log
5四、把loganalyzer-4.1.11.tar.gz上傳到/opt目錄下,並解壓,
輸入:tar –zxvf loganalyzer-4.1.11.tar.gz
5五、輸入:cd loganalyzer-4.1.11
輸入:cp -r src/* /var/www/html/log
輸入:cp -r contrib/* /var/www/html/log
5六、輸入:cd /var/www/html/log
輸入:chmod +x configure.sh secure.sh
輸入:./configure.sh
輸入:./secure.sh
輸入:touch config.php
輸入:chmod 666 config.php
輸入:chown -R apache.apache *
輸入:systemctl start httpd
輸入:systemctl enable httpd
輸入:systemctl status httpd
5七、地址欄輸入:http://192.168.20.123/log,
點擊Click here開始安裝
5八、第一步,準備工做
5九、第二步、驗證文件權限
60、第三步、基礎配置,設置用戶數據庫,填寫前面建立的rsyslog數據庫,帳號和密碼都是rsyslog
6一、第四步、建立表
6二、第五步、檢查SQL結果
6三、第六步、建立系統的用戶和密碼,這兒都用的rsyslog
6四、第七步、建立第一個數據源用來接收syslog數據,選擇數據源類型爲數據庫,填寫使用Syslog數據庫的SystemEvents表,帳號密碼也是前面建立並賦了所有權限的rsyslog
6五、第八步,前面都操做成功,完成安裝
6六、點擊上圖的Finish就能看到首頁
6七、點擊Login,輸入帳號和密碼,都是rsyslog
6八、登陸後看見下圖
6九、系統的基本設置,顯示的字體設置爲了Courier New
默認的字符編碼設置爲utf-8
70、中文語言包只是對菜單等進行了漢化,把中文語言包文件放入/var/www/html/log/lang目錄下便可