
第一章中簡單講述了zabbix的作業流程、作業模式,zabbix的幾大核心組件,想要學習zabbix,首先需要安裝一套zabbix環境,
這章重點講述zabbix的簡單安裝
一、zabbix的安裝方式主要有以下幾種:
使用yum方式安裝
使用原始碼方式進行安裝
使用容器方式進行安裝
鑒于使用yum安裝方式簡單,此文章使用yum方式安裝
二、檢查環境,由于系統防火墻與selinux后期會影響使用zabbix,如果想要不影響,就需要設定特定的規則,這里兩臺主機就直接關閉
# systemctl disable firewalld && systemctl stop firewalld /關閉防火墻并設定開機不自啟/
1. # systemctl status firewalld /查看服務狀態/
2. ● firewalld.service - firewalld - dynamic firewall daemon
3. Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
4. Active: inactive (dead) #未激活狀態
5. Docs: man:firewalld(1)
7. Dec 25 21:31:39 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
8. Dec 25 21:31:40 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
9. Dec 26 13:31:08 master systemd[1]: Stopping firewalld - dynamic firewall daemon...
10. Dec 26 13:31:09 master systemd[1]: Stopped firewalld - dynamic firewall daemon.
11. Dec 26 13:40:31 master systemd[1]: Starting firewalld - dynamic firewall daemon...
12. Dec 26 13:40:31 master systemd[1]: Started firewalld - dynamic firewall daemon.
13. Dec 26 13:40:33 master systemd[1]: Stopping firewalld - dynamic firewall daemon...
14. Dec 26 13:40:34 master systemd[1]: Stopped firewalld - dynamic firewall daemon.
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config /替換selinux文本/
1. [root@master ~]# cat /etc/selinux/config
3. # This file controls the state of SELinux on the system.
4. # SELINUX= can take one of these three values:
5. # enforcing - SELinux security policy is enforced.
6. # permissive - SELinux prints warnings instead of enforcing.
7. # disabled - No SELinux policy is loaded.
8. SELINUX=disabled /關閉狀態/
9. # SELINUXTYPE= can take one of three values:
10. # targeted - Targeted processes are protected,
11. # minimum - Modification of targeted policy. Only selected processes are protected.
12. #mls - Multi Level Security protection.
13. SELINUXTYPE=targeted
三、安裝zabbix服務
01.由于centos7.x系統中并沒有zabbix相關源,所以我們首先安裝官方zabbix源,以便后續安裝zabbix相關組件,在這里我們安裝zabbix-3.4版本
zabbix源地址:http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
1. [root@master ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
2. Retrieving http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
3. warning: /var/tmp/rpm-tmp.Ehmx3n: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
4. Preparing... ################################# [100%]
5. Updating / installing...
6. 1:zabbix-release-3.4-2.el7 ################################# [100%]
02.在master端安裝zabbix-server-mysql zabbix-web-mysql zabbix-get等組件,在zabbix3.x版本中,并沒有單獨的zabbix-server包,安裝好zabbix-server-mysql即為安裝好zabbix-server
[root@master ~]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-get
03.啟動zabbix-server服務
[root@master ~]# systemctl start zabbix-server /啟動服務/
[root@master ~]# systemctl status zabbix-server /查看狀態/
-
● zabbix-server.service - Zabbix Server -
Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; disabled; vendor preset: disabled) -
Active:
active (running)since Sat 2020-12-26 16:02:49 CST; 17s ago -
Process: 10043 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS) -
Main PID: 10045 (zabbix_server) -
CGroup: /system.slice/zabbix-server.service -
└─10045 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf -
Dec 26 16:02:49 master systemd[1]: Starting Zabbix Server...
*Dec 26 16:02:49 master systemd[1]: Started Zabbix Server.
04.agent端安裝zabbix-agent zabbix-sender
[root@agent ~]# yum -y install zabbix-agent zabbix-sender
05.由于zabbix監控是基于LAMP或LNMP架構,并且zabbix服務的作業流程也需要資料庫的管理,由于zabbix包中在我們下載的時候已經包含啦httpd與PHP服務,所以在這里我們就只需要安裝配置資料庫
由于mariadb與mysql大同小異,所以我們使用mariadb服務來作為zabbix連接的資料庫
[root@master ~]# yum -y install mariadb mariadb-server /安裝資料庫/
[root@master ~]# systemctl start mariadb /開啟服務/
[root@master ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. /設定開機自啟/
[root@master ~]# mysql_secure_installation /根據需求初始化資料庫/
06.安裝完zabbix包后,默認含有zabbix相關的資料表,后續需要匯入表到資料庫中,所以在這里解壓出來
默認在/usr/share/doc/zabbix-server-mysql-3.4.15路徑下有一個create.sql.gz壓縮包

解壓后成以下狀態

進入資料庫,創建用戶,分配用戶權限,匯入資料表
MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by 'zabbix'; /創建用戶分配權限/
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges; /重繪/
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; /創建資料庫/
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> use zabbix; /進入資料庫/
Database changed
MariaDB [zabbix]> source create.sql /匯入表/
/可看到已經存在表/
07.在zabbix_server.conf中編輯資料庫配置
[root@master ~]# vim /etc/zabbix/zabbix_server.conf
常常修改引數如下,更據實際需求進行修改
1.DBHost=localhost
/zabbix資料庫所在主機IP,由于此處資料庫與zabbix安裝在一起,所以填寫為localhost/
2. DBName=zabbix
/通過DBName指定zabbix資料庫對應名稱/
3. DBUser=zabbix
/通過DBUser指定zabbix資料庫對應用戶/
4. DBPassword=zabbix
/指定zabbix資料庫對應密碼/
5. ListenPort=10051
/指定zabbix模式監聽埠/
6. SourceIP=10.192.113.70
/指定服務端的源IP,當服務端有多個IP時,可以使用此方法設定服務端與agent端通訊的IP/
7. LogType=file
/通過LogType引數,可以指定通過哪種方式記錄日志,此引數可以設定為三種值,system、file、console,system表示將日志發往syslog,file表示使用指定的檔案作為日志檔案,console表示將日志發往控制臺,默認為file,/
8. LogFileSize=0
/指明日志檔案達到多大時自動滾動,單位為MB,如果設定LogFileSize為50,表示日志大小達到50MB滾動一次,設定為0表示日志檔案不會滾動,所有日志保存在一個檔案中,/
9. DebugLevel=3
/義日志的詳細程度,即為日志級別,/
10.DBPort=3306
/定義資料庫監聽埠/
11.DBSocket=/var/lib/mysql/mysql.sock
/通過DBSocket指定資料庫本地套接字檔案位置/
08.重啟zabbix服務并且查看10051埠已經監聽到
[root@master ~]# systemctl restart zabbix-server

09.由于zabbix-web管理需要PHP頁面,配置PHP
Zabbix前端的Apache組態檔位于 /etc/httpd/conf.d/zabbix.conf ,一些PHP設定已經完成了配置
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value always_populate_raw_post_data -1
#php_value date.timezone Europe/Riga
依據所在時區,你可以取消 “date.timezone” 設定的注釋,并正確配置它,在組態檔更改后,需要重啟Apache Web服務器,

[root@master ~]# systemctl restart httpd
10.初始化zabbix配置
瀏覽器訪問: http://server-IP/zabbix 進行zabbix初始化操作
完成以上步驟后,可以進入到zabbix安裝步驟,點擊下一步
之后會進入zabbix自動檢查安裝環境是否滿足要求,如果出現不滿足要求的情況,需要進一步處理,若沒問題,點擊下一步
進入到zabbix配置資料庫連接,配置資料庫相關資訊,埠填寫0表示使用默認埠(3306埠),填寫完成后,點擊下一步
填寫zabbix server的詳細資訊,包括IP地址,埠號,以及server名稱等,填寫完成后點擊下一步,
檢查配置無錯誤后,點擊下一步
初始化配置已經完成,而且配置資訊都被保存到了"/etc/zabbix/web/zabbix.conf.php" 組態檔中,如果想要更改配置,可以通過修改此檔案完成,初始化已經完成,點擊結束即可,
點擊完成按鈕后,可以看到zabbix的登錄頁面,默認的管理員用戶為Admin,密碼為zabbix,輸入用戶名密碼后登錄
登錄完成后,可以看到zabbix的儀表盤
zabbix前端支持中文切換,點擊下圖紅標
在出現的畫面中,語言選擇中文,點擊更新即可
以上操作完成后就能正確看到中文界面啦
后續學習持續
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/240801.html
標籤:其他
下一篇:[轉載]分享三篇非常好的學習心得










