監控服務zabbix部署 zabbix介紹 zabbix是由Alexei Vladishev 開發的一種網路監視、管理系統,基於Server-Client架構。可用於監視各種網路服務、伺服器和網路機器等狀態。 使用各種Database-end 如 MySQL,PostgreSQL,SQlite,O ...
監控服務zabbix部署
目錄
zabbix介紹
- zabbix是由Alexei Vladishev 開發的一種網路監視、管理系統,基於Server-Client架構。可用於監視各種網路服務、伺服器和網路機器等狀態。
- 使用各種Database-end 如 MySQL,PostgreSQL,SQlite,Oracle 或IBMDB2儲存資料。Server端基於C語言、Web管理端frontend則是基於PHP所製作的。
- zabbix可以使用多種方式監視。可以只使用Simple Check不需要安裝
Client端,亦可基於SMTP或HTTP… 各種協議定製監視。 - 在客戶端如UNIX,Windows 中安裝zabbix Agent之後,可監視CPULoad、網路使用狀況、硬碟容量等各種狀態。而就算沒有安裝Agent 在監視對象中,zabbix 也可以經由SNMP、TCP、ICMP、利用IPMI、SSH、telnet 對目標進行監視。
- zabbbix自帶的Item足夠滿足普通小公司的監控需求,對於大公司也可以設定自定義的Item,自動生成報表,也有API可以和其他系統集成。
- zabbix由2部分構成,zabbix server與可選組件zabbix agent。
zabbix特點
zabbix的主要特點:
安裝與配置簡單,學習成本低
支持多語言(包括中文)
免費開源
自動發現伺服器與網路設備
分散式監視以及WEB集中管理功能
可以無agent監視
用戶安全認證和柔軟的授權方式
通過WEB界面設置或查看監視結果
email等通知功能
zabbix主要功能:
CPU負荷
記憶體使用
磁碟使用
網路狀況
埠監視
日誌監視
為何是zabbix不是其他監控
zabbix就是可以滿足理想化的監控系統需求
支持自定義監控腳本,提供需要輸出的值即可
zabbix存儲的資料庫表結構稍有複雜但是邏輯清晰
zabbix存在模板的概念,可以方便的將一組監控項進行部署
zabbix每一個item也就是監控項,都可以看到歷史記錄,且web界面友好
zabbix有強大的Trigger(觸發器)定義規則,可以定義複雜的報警邏輯
zabbix提供了ack報警確認機制
zabbix支持郵件,簡訊,微信等告警
zabbix在觸發告警後,可以遠程執行系統命令
zabbix有原生的PHP繪圖模塊
部署zabbix時為什麼服務端也要安裝部署zabbix
因為服務端在監控其他主機的時候,如果自己出了啥子問題是無法進行自我反應的,所以在監控其他主機的時候,也要進行自我監控,及時反應問題。
zabbix程式組件
zabbix_server,服務端守護進程
zabbix_agentd,agent守護進程
zabbix_proxy,代理伺服器
zabbix_database,存儲系統,mysql,pgsql
zabbix_web,web GUI圖形化界面
zabbix_ get,命令行工具,測試向agent發起數據採集請求
zabbix_sender,命令行工具,測試向server發送數據
zabbix_ java_ gateway,java網關
zabbix配置文件
zabbix配置文件有兩種:
伺服器端配置文件(/usr/local/etc/zabbix_server.conf)
客戶端配置文件(/usr/local/etc/zabbix_agentd.conf)
zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
部署zabbix
因為zabbix是用php語言開發的,所以必須先部署lamp架構,使其能夠支持運行php網頁
需要提前搭建好lamp架構,可以查看 下麵的搭建方法
lamp架構的搭建
mysql官網
此處需要使用的mysql8mysql源碼包
php官網
此處需要使用的php源碼包
zabbix官網
zabbix源碼包
zabbix服務端安裝
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.2.tar.gz
//下載源碼包
--2022-09-01 22:12:50-- https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.2.tar.gz
Resolving cdn.zabbix.com (cdn.zabbix.com)... 172.67.69.4, 104.26.6.148, 104.26.7.148, ...
...
[root@localhost src]# ls
debug kernels zabbix-6.2.2.tar.gz
[root@localhost src]# tar xf zabbix-6.2.2.tar.gz //解壓
[root@localhost src]# cd zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# dnf -y install net-snmp-devel libevent-devel //安裝依賴包
....
tpm2-tss-2.3.2-4.el8.x86_64
unzip-6.0-45.el8_4.x86_64
zip-3.0-23.el8.x86_64
Complete!
[root@localhost zabbix-6.2.2]# useradd -r -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
//創建zabbix系統用戶
[root@localhost zabbix-6.2.2]# mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
//創建zabbix用戶的家目錄
[root@localhost zabbix-6.2.2]# chown -R zabbix.zabbix /usr/lib/zabbix/
//使其屬主屬組都是zabbix
[root@localhost zabbix-6.2.2]# mysql -uroot -p'lnh123' //登錄資料庫,配置資料庫
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.02 sec)
mysql> create user 'zabbix'@'localhost' identified by 'zabbix123!';
Query OK, 0 rows affected (0.03 sec)
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> SET GLOBAL log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@localhost zabbix-6.2.2]# cd /usr/src/zabbix-6.2.2/database/mysql/
[root@localhost mysql]# ls
Makefile.am Makefile.in data.sql double.sql history_pk_prepare.sql images.sql schema.sql
//將此處數據進行導入
[root@localhost mysql]# mysql -uroot -p'lnh123' zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uroot -p'lnh123' zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uroot -p'lnh123' zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uroot -p'lnh123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SET GLOBAL log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> show tables from zabbix;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
....
| widget_field |
+----------------------------+
176 rows in set (0.03 sec)
//查看zabbix資料庫下有哪些表,沒有問題的話是176張表
[root@localhost mysql]# cd /usr/src/zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
//編譯zabbix
...
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
[root@localhost zabbix-6.2.2]# make install
zabbix服務端配置
[root@localhost zabbix-6.2.2]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
[root@localhost etc]# vim zabbix_server.conf.d/
# DBPassword= //在這行下麵添加前面設置的mysql裡面用戶密碼
DBPassword=zabbix123! //添加
zabbix配置web界面
[root@localhost etc]# cd
[root@localhost ~]# cd /usr/src/zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# ls
AUTHORS Makefile README compile config.status database m4 sass
COPYING Makefile.am aclocal.m4 conf config.sub depcomp man src
ChangeLog Makefile.in bin config.guess configure include misc ui
INSTALL NEWS build config.log configure.ac install-sh missing
[root@localhost zabbix-6.2.2]# vim /usr/local/apache/conf/extra/httpd-vhosts.conf
//配置apache虛擬主機,可以註釋之前的配置
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName zabbix.example.com
ErrorLog "logs/zabbix.example.com-error_log"
CustomLog "logs/zabbix.example.com-access_log" common
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
<Directory "/usr/local/apache/htdocs/zabbix">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
[root@localhost zabbix-6.2.2]# cd /usr/src/zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# ls
AUTHORS Makefile README compile config.status database m4 sass
COPYING Makefile.am aclocal.m4 conf config.sub depcomp man src
ChangeLog Makefile.in bin config.guess configure include misc ui
INSTALL NEWS build config.log configure.ac install-sh missing
[root@localhost zabbix-6.2.2]# cd ui/
[root@localhost ui]# ls //此處是php代碼
actionconf.php composer.lock imgstore.php report2.php
api_jsonrpc.php conf include report4.php
app data index.php robots.txt
assets disc_prototypes.php index_http.php setup.php
audio favicon.ico index_sso.php sysmap.php
auditacts.php graphs.php items.php sysmaps.php
browserwarning.php history.php js templates.php
chart.php host_discovery.php jsLoader.php toptriggers.php
chart2.php host_prototypes.php jsrpc.php tr_events.php
chart3.php hostinventories.php local trigger_prototypes.php
chart4.php hostinventoriesoverview.php locale triggers.php
chart6.php httpconf.php maintenance.php vendor
chart7.php httpdetails.php map.php zabbix.php
composer.json image.php modules
[root@localhost ui]# cd -
/usr/src/zabbix-6.2.2
[root@localhost zabbix-6.2.2]# cd
[root@localhost ~]# cd /usr/src/zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# mkdir /usr/local/apache/htdocs/zabbix //創建zabbix的web站點目錄
[root@localhost zabbix-6.2.2]# cp -a /usr/src/zabbix-6.2.2/ui/* /usr/local/apache/htdocs/zabbix/
//將zabbix的web界面php代碼複製到站點目錄
[root@localhost zabbix-6.2.2]# chown -R apache.apache /usr/local/apache/htdocs/
//使其屬主屬組是apache
[root@localhost zabbix-6.2.2]# ll /usr/local/apache/htdocs/
total 8
-rw-r--r--. 1 apache apache 45 Jun 12 2007 index.html
drwxr-xr-x. 2 apache apache 23 Sep 1 21:29 runtime
drwxr-xr-x. 13 apache apache 4096 Sep 1 23:19 zabbix
[root@localhost zabbix-6.2.2]# chmod 777 /usr/local/apache/htdocs/zabbix/conf/
//設置zabbix/conf目錄的許可權,讓zabbix有許可權生成配置文件zabbix.conf.php
[root@localhost zabbix-6.2.2]# ll -d /usr/local/apache/htdocs/zabbix/conf/
drwxrwxrwx. 3 apache apache 94 Aug 29 15:05 /usr/local/apache/htdocs/zabbix/conf/
[root@localhost zabbix-6.2.2]# httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'ServerName' directive globally to suppress this message
Syntax OK
[root@localhost zabbix-6.2.2]# systemctl restart httpd.service
//重啟httpd
[root@localhost zabbix-6.2.2]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost zabbix-6.2.2]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost zabbix-6.2.2]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost zabbix-6.2.2]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
//修改/etc/php.ini的配置
[root@localhost zabbix-6.2.2]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
//重啟php-fpm
[root@localhost ~]# zabbix_server
[root@localhost ~]# zabbix_agentd
//啟動zabbix_server和zabbix_agentd
在物理機上做hosts功能變數名稱映射
在我的電腦裡面進行映射(C:\Windows\System32\drivers\etc)
去瀏覽器訪問,輸入zabbix.example.com,看到如下頁面,然後點擊next step
用戶名Admin 密碼 zabbix
部署完成
[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf/
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf/
drwxr-xr-x. 3 apache apache 117 Sep 1 23:41 /usr/local/apache/htdocs/zabbix/conf/
//恢復zabbix/conf目錄的許可權為755