zabbix監控服務部署


zabbix監控服務部署

1. zabbix介紹

Zabbix 能監控各種網絡參數,保證服務器系統的安全運營;並提供靈活的通知機制以讓系統管理員快速定位、解決存在的各種問題。是一個基於 Web 界面的提供分布式系統監視以及網絡監視功能的企業級的開源解決方案。

1.1 zabbix的組件

zabbix主要有以下功能組件組成:

官方文檔:https://www.zabbix.com/documentation/4.0/zh/manual/introduction/overview

Server

Zabbix server 是 Zabbix軟件的核心組件,agent 向其報告可用性、系統完整性信息和統計信息。server也是存儲所有配置信息、統計信息和操作信息的核心存儲庫。

Agent

Zabbix agents 部署在被監控目標上,用於主動監控本地資源和應用程序,並將收集的數據發送給 Zabbix server。

Proxy

Zabbix proxy 可以代替 Zabbix server采集性能和可用性數據。Zabbix proxy在Zabbix的部署是可選部分;但是proxy的部署可以很好的分擔單個Zabbix server的負載。

數據庫

​ 所有配置信息以及 Zabbix 采集到的數據都被存儲在數據庫中。

Web 界面

​ 該界面是 Zabbix server 的一部分,通常(但不一定)和 Zabbix server 運行在同一台物理機器上。

1.2 zabbix的進程

默認情況下 zabbix 包含6個進程:zabbix_agentd、zabbix_get、zabbix_proxy、zabbix_sender、zabbix_server,另外一個zabbix_java_gateway是可選的,這個需要單獨安裝。

zabbix_agentd

  客戶端守護進程,此進程收集客戶端數據,例如cpu負載、內存、硬盤使用情況等。

zabbix_get

  zabbix 工具,單獨使用的命令,通常在 server 或者 proxy 端執行獲取遠程客戶端信息的命令。通常用於排錯。例如在 server 端獲取不到客戶端的內存數據,可以使用 zabbix_get 獲取客戶端的內容的方式來做故障排查。

zabbix_sender

  zabbix 工具,用於發送數據給 server 或者 proxy,通常用於耗時比較長的檢查。很多檢查非常耗時間,導致 zabbix 超時。於是在腳本執行完畢之后,使用 sender 主動提價數據。

zabbix_server

  zabbix 服務端守護進程。zabbix_agentd、zabbix_get、zabbix_sender、zabbix_proxy、zabbix_java_gateway的數據最終都是提交到server(說明:當然不是數據都是主動提交給zabbix_server,也有的是 server 主動去取數據)

zabbix_proxy

  zabbix 代理守護進程。功能類似server,唯一不同的是它只是一個中轉站,它需要把收集到的數據提交/被提交到 server 里。

zabbix_java_gateway

  zabbix2.0之后引入的一個功能。顧名思義:Java網絡,類似agentd,但是只用於 Java 方面。需要特別注意的是,它只能主動去獲取數據,而不能被動獲取數據。它的數據最終會給到 server 或者proxy。

1.3 zabbix常用術語

官方文檔: https://www.zabbix.com/documentation/4.0/zh/manual/definitions

主機(host)

- 你想要監控的聯網設備,有IP/DNS。

主機組(host group)

- 主機的邏輯組;可能包含主機和模板。一個主機組里的主機和模板之間並沒有任何直接的關聯。通常在給不同用戶組的主機分配權限時候使用主機組。

監控項(item)

- 你想要從主機接收的特定數據,一個度量(metrics)/指標數據。

值預處理(value preprocessing)

- 存入數據庫之前,轉化/預處理接收到的指標數據

觸發器(trigger)

- 觸發器是一個邏輯表達式,用來定義問題閾值和“評估”監控項接收到的數據

當接收到的數據高於閾值時,觸發器從“OK”變成“Problem”狀態。當接收到的數據低於閾值時,觸發器保留/返回“OK”的狀態。

事件(event)

- 發生的需要注意的事件,例如觸發器狀態改變、自動發現/監控代理自動注冊

事件標簽(event tag)

- 提前設置的事件標記*,可以用於事件關聯,權限細化設置等。

事件關聯(event correlation)

- 自動靈活的、精確的關聯問題和解決方案

比如說,你可以定義觸發器A告警的異常可以由觸發器B解決,觸發器B可能采用完全不同的數據采集方式。

異常(problems)

- 處在“異常”狀態的觸發器

動作(action)

- 預先定義的應對事件的動作*

一個動作由操作(例如發出通知)和條件(什么時間進行操作)組成

媒介(media)

- 發送告警通知的方式、途徑

告警通知(notification)

- 通過預先設定好的媒介途徑發送事件信息給用戶。

遠程命令(remote command)

- 預定義好的,滿足特定條件的情況下,可以在被監控主機上自動執行的命令。

模版(template)

- 被應用到一個或多個主機上的一整套實體組合(如監控項,觸發器,圖形,聚合圖形,應用,LLD,Web場景等)。

模版的應用使得主機上的監控任務部署快捷方便;也可以使監控任務的批量修改更加簡單。模版是直接關聯到每台單獨的主機上。

應用(application)

- 監控項的邏輯分組

Web場景(web scenario)

- 檢查網站可瀏覽性的一個或多個HTTP請求

前端(frontend)

- Zabbix提供的web界面,5.0變成了ui

儀表板(dashboard)

- 自定義的web前端模塊中,用於重要的概要和可視化信息展示的單元, 我們稱之為組件(widget)。

組件(widget)

- Dashboard中用來展示某種信息和數據的可視化組件(概覽、map、圖表、時鍾等)。

Zabbix API

- Zabbix API允許用戶使用JSON RPC協議來創建、更新和獲取Zabbix對象(如主機、監控項、圖表等)信息或者執行任何其他的自定義的任務

Zabbix server

- Zabbix軟件的核心進程,執行監控操作,與Zabbix proxies和Agents進行交互、觸發器計算、發送告警通知;也是數據的中央存儲庫

Zabbix agent

- 部署在監控對象上的進程,能夠主動監控本地資源和應用

Zabbix proxy

- 代替Zabbix Server采集數據,從而分擔Zabbix Server負載的進程

加密(encryption)

- 使用TLS(Transport Layer Security )協議*支持Zabbix組建之間的加密通訊(server, proxy, agent, zabbix_sender 和 zabbix_get工具) 。

2. zabbix工作原理

監控系統運行的大概流程是這樣的:

zabbix agent 需要安裝到被監控的主機上,它負責定期收集各項數據,並發送到 zabbix server 端,zabbix server 將數據存儲到數據庫中,zabbix web 根據數據在前端進行展示和繪圖。這里 agent 收集數據分為主動和被動兩種模式:

主動:agent 請求server 獲取主動的監控項列表,並主動將監控項內需要檢測的數據提交給server / proxy

被動:server 向 agent 請求獲取監控項的數據,agent 返回數據。

我們需要監控那些內容

硬件監控 溫度,硬件故障等
系統監控 CPU, 內存,硬盤,網卡流量,TCP狀態,進程數
應用監控 Nginx. Tomcat. PHP、 MySQL、 Redis等
日志監控 系統日志服務日志訪問日志錯誤日志
安全監控 WAF,敏感文件監控
API監控 可用性,接口請求,響應時間
業務監控 例如電商網站,每分鍾產生多少訂單、注冊多少用戶、多少活躍用戶、推廣活動效果
流量分析 根據流量獲取用戶相關信息,例如用戶地理位置、某頁面訪問狀況、頁面停留時間等

3. zabbix監控架構

在實際監控架構中,zabbix根據網絡環境、監控規模等 分了三種架構:server-client、master-node-client、server-proxy-client 三種。

1、server-client 架構

  zabbix的最簡單的架構,監控服務器和被監控機之間不經過任何代理,直接由 zabbix server 和 zabbix agentd之間進行數據交互。適用於網絡比較簡單,設備比較少的監控環境。

2、server-proxy-client 架構

  其中 proxy 是server、client 之間溝通的一個橋梁,proxy 本身沒有前端,而且其本身並不存放數據,只是將 agentd 發來的數據暫時存放,而后再提交給server,該架構經常是和 master-node-client 架構做比較的架構,一般適用於跨機房、跨網絡的中型網絡架構的監控。

3、master-node-client 架構

  該架構是 zabbix 最復雜的監控架構,適用於跨網絡、跨機房、設備較多的大環境。每個node 同時也是一個 server 端,node下面可以接 proxy,也可以直接接client。node有自己的配置文件和數據庫,其要做的是將配置信息和監控數據向 master 同步,master 的故障或損壞不影響 node 其下的架構的完整性。

img

4. zabbix配置文件

zabbix配置文件種類:

  • 服務器端配置文件(/usr/local/etc/zabbix_server.conf)
  • 客戶端配置文件(/usr/local/etc/zabbix_agentd.conf)
  • zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)

服務器端配置文件zabbix_server.conf常用配置參數:

參數 作用
LogFile 設置服務端日志文件存放路徑
ListenIP 設置服務端監聽IP
ListenPort 設置服務端監聽的端口號
PidFile 設置服務端進程號文件存放路徑
DBHost 指定zabbix的數據庫服務器IP
DBName 指定zabbix使用的數據庫庫名
DBUser 指定zabbix數據庫登錄用戶
DBPassword 指定zabbix數據庫登錄密碼
DBPort 指定zabbix數據庫端口號
User 設置zabbix以什么用戶的身份運行
AlertScriptsPath 設置告警腳本存放路徑
ExternalScripts 外部腳本存放路徑

客戶端配置文件zabbix_agentd.conf常用配置參數:

參數 作用
Server 指定zabbix服務器的IP或域名
ServerActive 指定zabbix服務器的IP或域名
Hostname 指定本機的主機名,此項必須與web界面配置項一致
UnsafeUserParameters 是否啟用自定義監控項,可選值為{1 | 0}
UserParameter 指定自定義監控腳本參數
LogFile 設置客戶端日志文件存放路徑

zabbix代理配置文件zabbix_proxy.conf

參數 作用
ProxyMode Proxy工作模式,默認為主動模式,主動發送數據至Server
Server 指定Server端地址
ServerPort Server端PORT
Hostname Proxy端主機名
ListenPort Proxy端監聽端口
DataSenderFrequency Proxy向Server發送數據的時間間隔

5. 部署zabbix5.0服務端

環境說明:

服務端IP 要安裝的應用
192.168.32.140 lamp架構
zabbix server
zabbix agent

因為zabbix是用php語言開發的,所以必須先部署lamp架構,使其能夠支持運行php網頁

lamp架構部署 : https://www.cnblogs.com/shipment/p/13265611.html

zabbix5.0官方安裝文檔:https://www.zabbix.com/documentation/current/manual/installation/install

5.1 zabbix服務端安裝

//安裝依賴包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel
......

//下載zabbix
[root@localhost ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.2.tar.gz
......

//解壓
[root@localhost ~]# tar xf zabbix-5.0.2.tar.gz 
[root@localhost ~]# cd zabbix-5.0.2
[root@localhost ~/zabbix-5.0.2]# ls
aclocal.m4  ChangeLog     config.sub    database  install-sh   man      README
AUTHORS     compile       configure     depcomp   m4           misc     sass
bin         conf          configure.ac  include   Makefile.am  missing  src
build       config.guess  COPYING       INSTALL   Makefile.in  NEWS     ui

//創建zabbix用戶
[root@localhost ~/zabbix-5.0.2]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost ~/zabbix-5.0.2]# id zabbix
uid=305(zabbix) gid=305(zabbix) groups=305(zabbix)

//配置zabbix數據庫
[root@localhost ~/zabbix-5.0.2]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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.

#utf-8是Zabbix支持的唯一編碼,要使Zabbix服務器/代理與MySQL數據庫正常工作,需要字符集UTF 8和UTF 8_bin排序規則。
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

mysql>  grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@localhost ~/zabbix-5.0.2]# ls
aclocal.m4  ChangeLog     config.sub    database  install-sh   man      README
AUTHORS     compile       configure     depcomp   m4           misc     sass
bin         conf          configure.ac  include   Makefile.am  missing  src
build       config.guess  COPYING       INSTALL   Makefile.in  NEWS     ui
[root@localhost ~/zabbix-5.0.2]# cd database/mysql/
data.sql     double.sql   images.sql   Makefile.am  Makefile.in  schema.sql   
[root@localhost ~/zabbix-5.0.2]# cd database/mysql/
[root@localhost ~/zabbix-5.0.2/database/mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost ~/zabbix-5.0.2/database/mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost ~/zabbix-5.0.2/database/mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.


//編譯安裝zabbix
[root@localhost ~/zabbix-5.0.2/database/mysql]# cd ../../
[root@localhost ~/zabbix-5.0.2]# ./configure --enable-server \
 --enable-agent \
 --with-mysql \
 --with-net-snmp \
 --with-libcurl \
 --with-libxml2
......

[root@localhost ~/zabbix-5.0.2]# make install

5.2 zabbix服務端配置

[root@localhost ~]# ls /usr/local/etc/
zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d

//修改服務端配置文件
//設置數據庫信息
[root@localhost ~]# vim /usr/local/etc/zabbix_server.conf
....
DBPassword=zabbix123!       //設置zabbix數據庫連接密碼


//啟動zabbix_server和zabbix_agentd
[root@localhost ~]# zabbix_server 
[root@localhost ~]# zabbix_agentd 
[root@localhost ~]# ss -tanl
State       Recv-Q Send-Q    Local Address:Port                   Peer Address:Port              
LISTEN      0      100           127.0.0.1:25                                *:*                  
LISTEN      0      128                   *:10050                             *:*                  
LISTEN      0      128                   *:10051                             *:*                  
LISTEN      0      128           127.0.0.1:9000                              *:*                  
LISTEN      0      128                   *:22                                *:*                  
LISTEN      0      100               [::1]:25                             [::]:*                  
LISTEN      0      80                 [::]:3306                           [::]:*                  
LISTEN      0      128                [::]:80                             [::]:*                  
LISTEN      0      128                [::]:22                             [::]:* 

//修改/etc/php.ini的配置並重啟php-fpm
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

[root@localhost ~/zabbix-5.0.2]# ls
aclocal.m4  ChangeLog     config.log     configure.ac  include     Makefile     misc     sass
AUTHORS     compile       config.status  COPYING       INSTALL     Makefile.am  missing  src
bin         conf          config.sub     database      install-sh  Makefile.in  NEWS     ui
build       config.guess  configure      depcomp       m4          man          README
[root@localhost ~/zabbix-5.0.2]# cd ui/
[root@localhost ~/zabbix-5.0.2/ui]# mkdir /usr/local/apache/htdocs/zabbix
[root@localhost ~/zabbix-5.0.2/ui]# cp -a . /usr/local/apache/htdocs/zabbix
[root@localhost ~/zabbix-5.0.2/ui]# chown -R apache.apache /usr/local/apache/htdocs
[root@localhost ~/zabbix-5.0.2/ui]# ls /usr/local/apache/htdocs/zabbix/

//配置apache虛擬主機
[root@localhost ~]# vim /etc/httpd24/httpd.conf
//在配置文件的末尾加如下內容
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName www.test.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
    <Directory "/usr/local/apache/htdocs">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>


//設置zabbix/conf目錄的權限,讓zabbix有權限生成配置文件zabbix.conf.php
[root@localhost ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx 3 1000 1000 94 Jul  6 05:54 /usr/local/apache/htdocs/zabbix/conf

//重啟apache
[root@localhost ~/zabbix-5.0.2/ui]# apachectl restart
[root@localhost ~/zabbix-5.0.2/ui]# ss -tanl
State       Recv-Q Send-Q    Local Address:Port                   Peer Address:Port              
LISTEN      0      100           127.0.0.1:25                                *:*                  
LISTEN      0      128                   *:10050                             *:*                  
LISTEN      0      128                   *:10051                             *:*                  
LISTEN      0      128           127.0.0.1:9000                              *:*                  
LISTEN      0      128                   *:22                                *:*                  
LISTEN      0      100               [::1]:25                             [::]:*                  
LISTEN      0      80                 [::]:3306                           [::]:*                  
LISTEN      0      128                [::]:80                             [::]:*                  
LISTEN      0      128                [::]:22                             [::]:* 

//配置zabbix開機自啟
[root@localhost ~/zabbix-5.0.2/misc/init.d/fedora/core]# pwd
/root/zabbix-5.0.2/misc/init.d/fedora/core
[root@localhost ~/zabbix-5.0.2/misc/init.d/fedora/core]# ls
zabbix_agentd  zabbix_server
//拷貝啟動腳本(如果報錯,就將啟動腳本軟連接到/usr/local/sbin/)
[root@localhost ~/zabbix-5.0.2/misc/init.d/fedora/core]# cp -a . /etc/init.d/
[root@localhost ~/zabbix-5.0.2/misc/init.d/fedora/core]# ls /etc/init.d/
functions  mysqld  netconsole  network  php-fpm  README  zabbix_agentd  zabbix_server

//添加開機自啟
[root@localhost ~/zabbix-5.0.2/misc/init.d/fedora/core]# chkconfig --add zabbix_server 
[root@localhost ~/zabbix-5.0.2/misc/init.d/fedora/core]# chkconfig --add zabbix_agentd 
[root@localhost ~/zabbix-5.0.2/misc/init.d/fedora/core]# chkconfig zabbix_server on
[root@localhost ~/zabbix-5.0.2/misc/init.d/fedora/core]# chkconfig zabbix_agentd on
[root@localhost ~/zabbix-5.0.2/misc/init.d/fedora/core]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
php-fpm        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
zabbix_agentd  	0:off	1:off	2:on	3:on	4:on	5:on	6:off
zabbix_server  	0:off	1:off	2:on	3:on	4:on	5:on	6:off

5.3 zabbix web界面安裝

  • 修改/etc/hosts文件(windows在 C:\Windows\System32\drivers\etc\hosts),添加域名與IP的映射
  • 在瀏覽器上訪問域名,本文設置的域名為www.test.com,你需要修改成你自己的域名
  • 恢復zabbix/conf目錄的權限為755

192.168.32.140 www.test.com

在瀏覽器上訪問域名或ip進行安裝:

image-20200715222210927

下一步

image-20200715222246494

下一步

image-20200715222544194

輸入Zabbix服務器的name是可選的,但是如果提交,它將顯示在菜單欄和頁面標題中。

image-20200715223042762

image-20200715223202099

image-20200715223217870

恢復zabbix/conf目錄的權限為755:

[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-xr-x 2 apache apache 104 Aug 17 13:05 /usr/local/apache/htdocs/zabbix/conf

5.4 zabbix 登錄

zabbix默認登錄用戶名和密碼:

用戶名 密碼
Admin zabbix

image-20200715223241291

image-20200715224325794

5.5 解決zabbix中文圖形亂碼問題

在C盤中搜索字體

我這里選擇等線簡體,復制到桌面,用Xftp工具上傳到服務器

[root@localhost /usr/local/apache/htdocs/zabbix/assets/fonts]# ls
DejaVuSans.ttf  Deng.ttf
#備份原本的字體
[root@localhost /usr/local/apache/htdocs/zabbix/assets/fonts]# mv DejaVuSans.ttf DejaVuSans.ttf.back 
將新字體重命名為原字體的名字
[root@localhost /usr/local/apache/htdocs/zabbix/assets/fonts]# mv Deng.ttf DejaVuSans.ttf

刷新web端查看(如果有顯示異常,重啟zabbix_server后在查看)

切換會英文也沒有顯示問題

在切回中文


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM