背景:
網路安全法第三章第二十一條明確規定“采取監測、記錄網路運行狀態、網路安全事件的技術措施,并按照規定留存相關的網路日志不少于六個月”,
為了滿足合規性的要求,應當建設相應的日志采集存盤系統,
市面上不少日志系統價格不菲,所以考慮在Centos 7.6環境下,基于MariaDB 和 Rsyslog,搭建開源免費的日志采集分析系統LogAnalyzer,
當然啦,ELK也可以,Prometheus + Grafana也OK,
本文參考了不少網路資料,感謝熱愛分享的人們!
-------------------------------------------------------------------------------------------------------------------------------------------------------------
軟體:
① VMware Workstation 15 Player
② CentOS-7-x86_64-Minimal-1810.iso
③ loganalyzer-4.1.11.tar.gz
④ loganalyzer-4.1.11中文語言包.zip
-------------------------------------------------------------------------------------------------------------------------------------------------------------
1、創建新虛擬機

2、稍后安裝作業系統

3、選擇Linux,版本為CentOS 7 64位

4、填寫虛擬機名稱:CentOS7,位置為C:\vm

5、設定磁盤大小為10G,選擇將虛擬磁盤存盤為單個檔案

6、點擊完成

7、點擊編輯虛擬機設定

8、設定記憶體為2048MB

9、設定CD/DVD,使用的ISO檔案為CentOS-7-x86_64-Minimal-1810.iso

10、設定網路配接器,網路連接為橋接模式

11、播放虛擬機

12、鍵盤上下鍵選中Install CentOS 7

13、出現VMware Tools,點擊以后提醒我

14、選中語言為中文

15、點擊系統,選擇安裝位置

16、使用自動配置磁區,點擊完成

17、點擊開始安裝

18、點擊ROOT密碼進行設定

19、設定ROOT密碼為123456

20、正在安裝

21、安裝完成后重啟虛擬機

22、重啟后,輸入賬號:root,輸入密碼:123456進入系統

23、輸入:cd /,輸入:ip addr查看網路配置

24、輸入:cd /etc/sysconfig/network-scripts/,輸入:ls查看目錄

25、輸入:vi ifcfg-ens33,默認配置如下:

修改為如下:
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.20.123
NETMASK=255.255.255.0
GATEWAY=192.168.20.240

輸入:wq,進行保存
26、輸入:service network restart,重啟網路服務

27、嘗試ping一下百度,輸入:ping www.baidu.com,發現ping不通,懷疑是DNS問題

28、需要設定DNS,
輸入:vi /etc/resolv.conf

29、填寫DNS內容,
輸入:nameserver 114.114.114.114
輸入:nameserver 8.8.8.8

輸入:wq,進行保存
30、再次重啟網路服務,
輸入:service network restart
31、再次輸入:ping www.baidu.com,這下能ping通了

32、查看rsyslog是否安裝,以及CentOS版本資訊,
輸入:cd /,輸入:rpm –qa | grep rsyslog
輸入:cat /etc/redhat-release

33、關閉防火墻,
輸入:systemctl stop firewalld.service
輸入:systemctl disable firewalld.service
輸入:systemctl status firewalld.service

34、關閉selinux,輸入:vi /etc/selinux/config,修改后重啟作業系統

默認如下

設定SELINUX=disabled

35、查看MariaDB是否安裝,
輸入:cd /
輸入:rpm –qa | grep mariadb
發現只有mariadb-libs

36、安裝MariaDB服務,
輸入:yum -y install mariadb mariadb-server

37、再次查看MariaDB安裝情況,輸入:rpm –qa | grep mariadb

38、啟動MariaDB服務,并設定為開機啟動,
輸入:systemctl start mariadb.service,
輸入:systemctl enable mariadb

39、設定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

41、創建rsyslog資料庫(用來存放LogAnalyzer系統的配置資訊),字符編碼設定為utf-8,
輸入:create database rsyslog character set utf8 collate utf8_bin;

42、查看當前有幾個資料庫,
輸入:show databases;

43、為rsyslog資料庫創建本地用戶rsyslog,設定密碼為rsyslog,權限為全部權限,
輸入:grant all privileges on rsyslog.* to ‘rsyslog’@’localhost’ identified by ‘rsyslog’;flush privileges;

44、輸入:exit
退出MariaDB

45、安裝rsyslog的MySQL擴展程式包rsyslog-mysql,
輸入:yum -y install rsyslog-mysql

46、將rsyslog的MySQL表匯入創建的rsyslog資料庫,
輸入:mysql -uroot -p < /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql

47、查看當前有幾個資料庫,輸入:show databases;
多了一個Syslog資料庫

48、使用Syslog資料庫,輸入:use Syslog;
查看Syslog資料庫下有幾個表,輸入:show tables;
顯然SystemEvents表用來存放日志記錄

49、為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,保存并退出
51、啟動rsyslog服務并設定為開機啟動,
輸入:systemctl restart rsyslog.service
輸入:systemctl enable rsyslog.service

52、安裝LAMP環境,
輸入:yum install httpd php php-mysql php-gd –y

53、創建相應的目錄用來存放loganalyzer的解壓檔案和運行后生成的日志,
輸入:mkdir -p /var/www/html/log
輸入:mkdir -p /var/log/httpd/log
54、把loganalyzer-4.1.11.tar.gz上傳到/opt目錄下,并解壓,
輸入:tar –zxvf loganalyzer-4.1.11.tar.gz

55、輸入:cd loganalyzer-4.1.11
輸入:cp -r src/* /var/www/html/log
輸入:cp -r contrib/* /var/www/html/log

56、輸入: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

57、地址欄輸入:http://192.168.20.123/log,
點擊Click here開始安裝

58、第一步,準備作業

59、第二步、驗證檔案權限

60、第三步、基礎配置,設定用戶資料庫,填寫前面創建的rsyslog資料庫,賬號和密碼都是rsyslog

61、第四步、創建表

62、第五步、檢查SQL結果

63、第六步、創建系統的用戶和密碼,這兒都用的rsyslog

64、第七步、創建第一個資料源用來接收syslog資料,選擇資料源型別為資料庫,填寫使用Syslog資料庫的SystemEvents表,賬號密碼也是前面創建并賦了全部權限的rsyslog

65、第八步,前面都操作成功,完成安裝

66、點擊上圖的Finish就能看到首頁

67、點擊Login,輸入賬號和密碼,都是rsyslog

68、登錄后看見下圖

69、系統的基本設定,顯示的字體設定為了Courier New

默認的字符編碼設定為utf-8

70、中文語言包只是對選單等進行了漢化,把中文語言包檔案放入/var/www/html/log/lang目錄下即可

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/259944.html
標籤:訊息安全
上一篇:JavaScript函式
下一篇:【原】無腦操作:Centos 7.6 + MariaDB + Rsyslog + LogAnalyzer環境搭建
