【原】無腦操作:Centos 7.6 + MariaDB + Rsyslog + LogAnalyzer環境搭建

背景:

網路安全法第三章第二十一條明確規定「採取監測、記錄網路運行狀態、網路安全事件的技術措施,並按照規定留存相關的網路日誌不少於六個月」。

為了滿足合規性的要求,應當建設相應的日誌採集存儲系統。

市面上不少日誌系統價格不菲,所以考慮在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、地址欄輸入://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目錄下即可