Zabbix企業級分散式監控
阿新 • • 發佈:2022-03-13
Zabbix 部署實施
實驗環境介紹
主機 | 系統和版本 | 配置 | IP | 元件 |
---|---|---|---|---|
server | CentOS7.9 | 1C/2G | 192.168.23.101 | Zabbix Server、MySQL |
proxy | CentOS7.9 | 1C/2G | 192.168.23.102 | Zabbix Proxy、MySQL |
agent1 | CentOS7.9 | 1C/1G | 192.168.23.103 | Zabbix Agent |
agent2 | CentOS7.9 | 1C/1G | 192.168.23.104 | Zabbix Agent |
實驗步驟
- 安裝部署前環境準備
- 部署 LNMP + Zabbix Server
- 部署 Zabbix Agent
- 部署 Zabbix Proxy
- Zabbix Web 前端配置
- Zabbix 主要功能配置
準備實驗環境
先進行環境初始化,然後YUM源安裝,再安裝MySQL。
-
環境初始化
所有節點操作
-
機器之間內網互通,防火牆如 Firewalld 等請在部署時關閉;
-
關閉 SELinux;
-
安裝時間同步伺服器。
修改主機名
# 192.168.10.101主機 hostnamectl set-hostname server # 192.168.10.102主機 hostnamectl set-hostname proxy # 192.168.10.103主機 hostnamectl set-hostname agent1 # 192.168.10.104主機 hostnamectl set-hostname agent2
關閉防火牆
systemctl stop firewalld systemctl disable firewalld
關閉SELinux
setenforce 0 sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
配置時間同步伺服器
yum install chrony -y systemctl enable chronyd systemctl start chronyd chronyc sources
-
-
YUM源安裝
所有節點操作
rpm -Uvh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
-
安裝資料庫
server節點操作
yum install -y mariadb-server systemctl start mariadb systemctl enable mariadb mysql #初始密碼為空 MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin; #建立 zabbix 庫,並指定字符集為utf8 MariaDB [(none)]> USE mysql; #切換進myql庫 MariaDB [mysql]> UPDATE mysql.user SET password = PASSWORD('zabbix') WHERE user = 'root'; #設定root 賬戶密碼為'zabbix' MariaDB [mysql]> GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@'localhost' IDENTIFIED BY 'zabbix'; #授權zabbix 賬戶使用密碼'zabbix'本地訪問 zabbix 資料庫,如果沒有zabbix這個庫的話會自行建立的 MariaDB [mysql]> GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@'%' IDENTIFIED BY 'zabbix'; #授權zabbix 賬戶使用密碼'zabbix'遠端訪問 zabbix 資料庫,如果沒有zabbix這個庫的話會自行建立的 MariaDB [mysql]> FLUSH PRIVILEGES; #更新資料庫 mysql> quit;
部署LNMP + Zabbix Server
server節點操作
安裝Nginx、php-fpm
yum install -y nginx php-fpm
安裝基於MySQL的zabbix server和zabbix web
yum install -y zabbix-server-mysql-3.2.11 yum install -y zabbix-web-mysql
初始化zabbix資料庫
zcat /usr/share/doc/zabbix-server-mysql-3.2.*/create.sql.gz | mysql -uzabbix -p zabbix
登入資料表查看錶結構
mysql -uroot -p Enter password: #密碼為zabbix MariaDB [(none)]> show databases; MariaDB [(none)]> use zabbix; MariaDB [zabbix]> show tables; MariaDB [zabbix]> quit;
編輯 Zabbix Server 配置檔案,修改資料庫連線資訊
vim /etc/zabbix/zabbix_server.conf 省略部分內容.......` DBHost=localhost #zabbix資料庫地址為本地 DBName=zabbix #zabbix資料庫的名字為zabbix DBUser=zabbix #zabbix資料庫的使用者為zabbix DBPassword=zabbix #這裡輸入的密碼是實際登入資料庫的密碼為zabbix
啟動 zabbix-server
systemctl start zabbix-server systemctl enable zabbix-server
編輯 Nginx 配置檔案
在 Nginx 配置檔案中,新增如下部分內容,新增 php 模組支援。
vim /etc/nginx/nginx.conf server { listen 80 default_server; listen [::]:80 default_server; server_name _; index index.html index.php; #新增 php 模組支援。 root /usr/share/nginx/html; location / { } location ~ \.php$ { fastcgi_buffer_size 128k; fastcgi_buffers 32 32k; include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
編輯 php.ini 檔案
在 php.ini 檔案中,修改如下配置項,因為在登入zabbix圖形介面時會有檢測,如果監測不通過就沒法登入zabbixvim /etc/php.ini 省略部分內容........ post_max_size = 16M max_execution_time = 300 #最長執行時間 max_input_time = 300 #最大輸入時間 memory_limit = 128M #記憶體限制 upload_max_filesize = 2M #上傳最大檔案大小 date.timezone = Asia/Shanghai #日期時區
複製 Web 目錄
拷貝 Zabbix Server 的 Web 目錄至 Nginx 主目錄。cp -rp /usr/share/zabbix /usr/share/nginx/html/
啟動 Nginx 及 php-fpm
systemctl start nginx php-fpm systemctl enable nginx php-fpm
安裝Zabbix Web 端
在瀏覽器中訪問 http://192.168.23.101/zabbix,將會進入到 Zabbix 安裝引導頁面,如下圖所示。