實操:基於LNMP搭建zabbix監控


前言:
服務器:
192.168.247.160 client 安裝zabbix-agent,被監控

192.168.247.142 server 安裝zabbix-server提供監控服務,也可以安裝agent監控自己

zabbix是一個高度集成的網絡監控套件,通過一個軟件包即可提供如下特性

  • 數據收集:
    1.可用性及性能檢測
    2.支持SNMP(trapping及polling)、IPMI、JMX監控
    3.自定義檢測
    4.自定義間隔收集數據
    5.server/proxy/agents
  • 靈活的閾值定義
    允許靈活的自定義閾值,在zabbix種被稱爲觸發器(trigger),存儲在後端數據庫中
  • 高級告警配置
    1.可以自定義告警升級(escalation)、接收者及告警方式
    2.告警信息可以配置並允許使用宏(macro)變量
    3.通過遠程命令實行自動化動作(action)
  • 實時繪圖
    通過內置的繪圖方法實現監控數據實時繪圖
  • 擴展的圖形化顯示
    1.允許自定義創建多監控項視圖
    2.生成網絡拓撲(network maps)
    3.自定義的面板(screen)和slide shows,並允許在dashboard頁面顯示
    4.生成監控報告
  • 歷史數據存儲
    1.數據存儲在數據庫中
    2.歷史數據可配置
    3.內置數據清理機制
  • 配置簡單
    1.被監控主機通過監控設備方式添加
    2.一次配置,終生監控——除非調整或刪除
    3.監控設備允許使用模板來添加監控
  • 模板使用
    1.模板中可以添加組監控
    2.模板允許集成
  • 網絡自動發現
    1.自動發現網絡設備
    2.agent自動註冊
    3.自動發現文件系統、網卡設備、SNMP OID等
  • 快速的web接口
    1.web前端採用php編寫
    2.訪問無障礙
  • zabbix API
    zabbix API 提供程序級別的訪問接口,第三方程序可以很快接入
  • 權限系統
    1.安全的權限認證
    2.用戶可以限制允許維護的列表
  • 全特性、agent易擴展
    1.在監控目標上部署
    2.支持Linux及windows
  • 二進制守護進程
    1.C開發,高性能,低內存消耗
    2.易移植
  • 具備應對複雜環境情況
    通過zabbix proxy 可以非常容易地創建遠程監控

①zabbix server

  • zabbix server是zabbix 服務端守護進程。zabbix_agentd、zabbix_proxy的數據最終都是提交到server
  • 當然並不是所有數據都主動提交給zabbix_server,也有的是server主動去拿數據
    ②zabbix agent
  • zabbix_agentd是客戶端守護進程,此進程主要用戶收集客戶端數據,例如CPU負載、內存、硬盤使用情況等
    ③zabbix proxy
  • zabbix_proxy是zabbix代理守護進程,功能類似server。不同的是,zabbix_proxy只是一箇中轉站,他需要把收集到的數據提交或者被提交到Server
    proxy也需要數據庫,用於分佈式監控,zabbix最大監控節點一般爲300左右,面對上千級別的集羣時,就需要proxy

一:環境準備:

關閉網絡管理器

[root@localhost ~]# hostnamectl set-hostname server
[root@localhost ~]# su
[root@server ~]# 
[root@server ~]# systemctl stop NetworkManager
[root@server ~]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
[root@server ~]# setenforce 0
setenforce: SELinux is disabled
[root@server ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
[root@server ~]# iptables -F

[root@nginx ~]# hostnamectl set-hostname client
[root@nginx ~]# su
[root@client ~]# systemctl stop NetworkManager
[root@client ~]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
[root@client ~]# setenforce 0
[root@client ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
[root@client ~]# iptables -F
[root@client ~]# 

二:zabbix概述

2.1 查看官網

https://www.zabbix.com/
在這裏插入圖片描述

  • 選擇中文,確認
    在這裏插入圖片描述

  • 右上角下載
    在這裏插入圖片描述

  • 會出現選項,按照選擇選好之後,下面就是安裝步驟介紹
    在這裏插入圖片描述

具體的接下來會做演示

2.2 zabbix與nagios

早幾年前流行的監控是nagios

Nagios是一款開源的免費網絡監視工具,能有效監控Windows、Linux和Unix的主機狀態,交換機路由器等網絡設備,打印機等。在系統或服務狀態異常時發出郵件或短信報警第一時間通知網站運維人員,在狀態恢復後發出正常的郵件或短信通知。

nagios的插件特別多,所以有的工程師會用cacti

Cacti是一套基於PHP,MySQL,SNMP及RRDTool開發的網絡流量監測圖形分析工具。

cacti的視覺感會更好一點

nagios的功能性會比較全,但是組件很多,麻煩

但自從zabbix的出現,就取代了nagios和cacti

2.3 zzbbix介紹

zabbix是一個基於WEB界面的提供分佈式系統監視以及網絡監視功能的企業級的開源解決方案。

zabbix能監視各種網絡參數,保證服務器系統的安全運營;並提供靈活的通知機制以讓系統管理員快速定位/解決存在的各種問題。

zabbix由2部分構成,zabbix server與可選組件zabbix agent。

zabbix server可以通過SNMP,zabbix agent,ping,端口監視等方法提供對遠程服務器/網絡狀態的監視,數據收集等功能,它可以運行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平臺上。

zabbix可以做分佈式監控,依賴於proxy

要藉助proxy去做分佈式

zabbix監控的服務器有一個上限值,300-500,一般做300左右,

zabbix由兩個部分構成,zabbix server與可選組件zabbix agent

zabbix agent 用來安裝在被監控端

像普羅米修斯監控用來管理K8S

zabbix可以自動發現服務機制

  • zabbix可以監控的方向有很多
    在這裏插入圖片描述
    也可以監控網絡設備,防火牆

2.4 zabbix軟件包

4.0是用的最穩定版本

5.0 2020年才推出

lts指的是測試

4.4跟4.0沒有區別

阿里雲平臺可以選擇postgreSQL

5.0可以支持nginx

4.0其實也可以安裝在nginx
在這裏插入圖片描述

這種瀏覽模式用到的是異步刷新,ajax,把下面的做了一個div塊,是前端的一個技術

三:基於LNMP搭建zabbix

php72w-mysql是驅動,讓php可以去找mysql進行增刪改查

中間也會加一箇中間件redis,在與其他組件進行交互時,會增加一個kafka,rabbitmq

client作爲被監控端

3.1 創建nginx的repo

[root@server ~]# yum install wget -y
[root@server ~]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
--2020-05-21 20:43:23--  http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
Resolving nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|62.210.92.35|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4680 (4.6K) [application/x-redhat-package-manager]
Saving to: ‘nginx-release-centos-7-0.el7.ngx.noarch.rpm’

100%[===============================================================================================>] 4,680       2.63KB/s   in 1.7s   

2020-05-21 20:43:25 (2.63 KB/s) - ‘nginx-release-centos-7-0.el7.ngx.noarch.rpm’ saved [4680/4680]
[root@server ~]# ls
anaconda-ks.cfg  nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@server ~]# vim /etc/yum.conf 
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
[root@server ~]# cd /var/cache/yum/$basearch/$releasever
[root@server yum]# ls
x86_64
[root@server yum]# cd x86_64/
[root@server x86_64]# ls
7
[root@server x86_64]# cd 7/
[root@server 7]# ls
base  docker-ce-stable  extras  timedhosts  timedhosts.txt  updates
[root@server 7]# pwd
/var/cache/yum/x86_64/7

手動創建nginx yum安裝源

[root@server 7]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
[root@server 7]# yum list

3.2 yum 安裝nginx

[root@server 7]# yum install nginx -y
Installed:
  nginx.x86_64 1:1.18.0-1.el7.ngx                                                          

Complete!
[root@server 7]# systemctl start ngginx
Failed to start ngginx.service: Unit not found.
[root@server 7]# systemctl start nginx
[root@server 7]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@server 7]# netstat -natp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      125691/nginx: maste 

3.3 安裝mariadb

[root@server 7]# yum install mariadb mariadb-server -y
[root@server 7]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@server 7]# systemctl start mariadb
[root@server 7]# netstat -natp | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      128096/mysqld       

初始化數據庫

[root@server 7]# mysql_secure_installation 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
Enter current password for root (enter for none): //回車
OK, successfully used password, moving on...

Set root password? [Y/n] y
New password: 123123
Re-enter new password: 123132
Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove anonymous users? [Y/n] n
 ... skipping.

Disallow root login remotely? [Y/n] n
 ... skipping.

Remove test database and access to it? [Y/n] n
 ... skipping.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

Thanks for using MariaDB!

本地驗證登錄數據庫

[root@server 7]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> quit
Bye

3.4 安裝php

[root@server ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#或者yum install epel-release -y
Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
warning: /var/tmp/rpm-tmp.ooODVn: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:epel-release-7-12                ################################# [100%]
[root@server ~]# ll /etc/yum.repos.d/	#此時增加epel*.repo
-rw-r--r--  1 root root 1050 Sep 18  2019 epel.repo
-rw-r--r--  1 root root 1149 Sep 18  2019 epel-testing.repo
[root@server ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.CrKvHr: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:webtatic-release-7-3             ################################# [100%]
[root@server ~]# ll /etc/yum.repos.d/	#增加webtatic*.rpeo
-rw-r--r--  1 root root  963 Oct  9  2014 webtatic-archive.repo
-rw-r--r--  1 root root  865 Oct  9  2014 webtatic.repo
-rw-r--r--  1 root root  963 Oct  9  2014 webtatic-testing.repo


php72w php

php72w-devel php的開發工具包

php72w-fpm php的fpm接收動態模塊

php72w-gd php的處理圖片的擴展庫

php72w-mbstring php的擴展多字節

php72w-mysql php連接mysql的組件

[root@server ~]# yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql

查看php版本

[root@server ~]# php -v
PHP 7.2.27 (cli) (built: Jan 26 2020 15:49:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

3.5 配置php配置文件以使nginx支持php

[root@server ~]# vim /etc/php-fpm.d/www.conf 
  8 user = nginx
 10 group = nginx

3.6 配置nginx.conf,使nginx能識別php

[root@server ~]# vim /etc/nginx/conf.d/default.conf 
  8     location / {
  9         root   /usr/share/nginx/html;
 10         index  index.html index.htm index.php;
 11     }
  • 配置php請求被傳送到後端的php-fpm模塊

默認情況下php模塊是被註釋的

[root@server ~]# vim /etc/nginx/conf.d/default.conf 
 30     location ~ \.php$ {
 31         root           /nginx/html;
 32         fastcgi_pass   127.0.0.1:9000;
 33         fastcgi_index  index.php;
 34         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 35         include        fastcgi_params;
 36     }

#把fastcgi_param種的/scripts改爲$document_root

#root 是配置php程序放置服務的根目錄站點

3.7 配置php.ini

執行時間是在一個程序執行過程中能等待的多長時間

從zabbix檢測到這個服務掉線時,到發送數據給工程師,讓工程師知曉,如果時間太短,會在時間結束後,直接把這個進程斷掉,防止進程卡死,如果生產環境中的業務很多,佔用很多流程,可以適當放寬

接收數據等待時間要一致

[root@server ~]# vim /etc/php.ini
 202 short_open_tag = On	#支持php短標籤
 359 expose_php = off		#隱藏php版本
 ####———————以下爲zabbix配置要求,優化配置———————
 368 max_execution_time = 300	#執行時間
 378 max_input_time = 300		#接收數據等待時間
 389 memory_limit = 128M		#每個腳本佔用內存
 656 post_max_size = 16M		#post數據大小,post 提交數據安全,get提交不安全,get會把數據卸載url上,post可以適當放寬
 799 upload_max_filesize = 2M	#下載文件大小
 800 always_populate_raw_post_data = -1		#這一行添加進去
 #可以用$HTTP_RAW_POST_DATA接收post raw data(原始未處理數據)
 877 date.timezone = Asia/Shanghai	#時區
[root@server ~]# systemctl start php-fpm
[root@server ~]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

3.8 重啓一下nginx服務

[root@server ~]# systemctl restart nginx

3.9 創建站點

[root@server ~]# mkdir -p /nginx/html
[root@server ~]# vim /nginx/html/index.php
<?
  phpinfo();
?>
[root@server ~]# netstat -natp | grep fpm
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      48176/php-fpm: mast 

在這裏插入圖片描述

如果配置文件中語法有問題,服務時開不了的

3.10 測試php連接數據庫

[root@server ~]# vim /nginx/html/index.php
<?php
 $link=mysqli_connect('127.0.0.1','root','123123');
 if ($link) echo "lianjiechenggong";
 else echo "lianjieshibai";
?>

備註:mysql_connect擴展自PHP 5.5.0 起已廢棄,改用mysqli或pdo_mysql

connect 是php的函數

刷新一下
在這裏插入圖片描述

3.11 創建數據庫的zabbix用戶

進入數據庫,給zabbix用戶權限

爲zabbix創建數據庫

  • collate的作用

對於mysql種那些字符類型的列,如VARCHAR、CHAR、TEXT類型的列,都需要有一個collate類型來告知mysql如何對該列進行排序和比較。collate會影響到order by的語句順序,會影響到where條件中大於小於號篩選出來的結果

[root@server ~]# mysql -uroot -p
Enter password: 123123
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> grant all privileges on *.* to 'zabbix'@'%' identified by 'zabbix123';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| zabbix             |
+--------------------+
5 rows in set (0.00 sec)

3.12 修改php的測試頁,測試zabbix用戶連接mysql

[root@server ~]# vim /nginx/html/index.php
<?php
 $link=mysqli_connect('127.0.0.1','zabbix','zabbix123');
 if ($link) echo "lianjiechenggong"; 
 else echo "lianjieshibai";
?>

清空下歷史記錄
在這裏插入圖片描述

3.13 出現報錯,本地直接測試

[root@server ~]# mysql -uzabbix -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)

3.14 登錄數據庫,刪除空用戶

[root@server ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
MariaDB [(none)]> select user,host from mysql.user
    -> ;
+--------+-----------+
| user   | host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
|        | localhost |
| root   | localhost |
|        | server    |
| root   | server    |
+--------+-----------+
7 rows in set (0.00 sec)
MariaDB [(none)]> drop user ''@localhost
    -> ;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> drop user ''@server;
Query OK, 0 rows affected (0.00 sec)
flush privileges;

3.15 再次測試

[root@server ~]# mysql -u zabbix -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

MariaDB [(none)]> use zabbix;
Database changed
MariaDB [zabbix]> show tables
    -> ;
Empty set (0.01 sec)

3.16 開始部署zabbix server

在這裏插入圖片描述
在這裏插入圖片描述

[root@server ~]# rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.pPAy7B: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-4.4-1.el7         ################################# [100%]
[root@server ~]# yum list	#不適用yum clean all ,因爲開啓了yum緩存
[root@server ~]# yum install zabbix-server-mysql zabbix-agent zabbix-web-mysql -y	
#zabbix-web-mysql在4.4的nginx版本沒有提示安裝,4.0的zabbix需要安裝
Error downloading packages:
  zabbix-web-4.4.8-1.el7.noarch: [Errno 256] No more mirrors to try.
  zabbix-server-mysql-4.4.8-1.el7.x86_64: [Errno 256] No more mirrors to try.
  zabbix-agent-4.4.8-1.el7.x86_64: [Errno 256] No more mirrors to try.

3.17 出現報錯,提示再次嘗試,再次安裝

[root@server ~]# yum install zabbix-server-mysql zabbix-agent zabbix-web-mysql -y
嘗試到第二次,只差兩個沒有安裝了
Error downloading packages:
  zabbix-web-4.4.8-1.el7.noarch: [Errno 256] No more mirrors to try.
  zabbix-server-mysql-4.4.8-1.el7.x86_64: [Errno 256] No more mirrors to try.
#繼續重複執行下載任務
Installed:
  zabbix-agent.x86_64 0:4.4.8-1.el7          zabbix-server-mysql.x86_64 0:4.4.8-1.el7     
  zabbix-web-mysql.noarch 0:4.4.8-1.el7     

Dependency Installed:
  OpenIPMI.x86_64 0:2.0.27-1.el7             OpenIPMI-libs.x86_64 0:2.0.27-1.el7          
  OpenIPMI-modalias.x86_64 0:2.0.27-1.el7    apr.x86_64 0:1.4.8-5.el7                     
  apr-util.x86_64 0:1.5.2-6.el7              dejavu-fonts-common.noarch 0:2.33-6.el7      
  dejavu-sans-fonts.noarch 0:2.33-6.el7      fontpackages-filesystem.noarch 0:1.44-8.el7  
  fping.x86_64 0:3.10-4.el7                  httpd.x86_64 0:2.4.6-93.el7.centos           
  httpd-tools.x86_64 0:2.4.6-93.el7.centos   libevent.x86_64 0:2.0.21-4.el7               
  mailcap.noarch 0:2.1.41-2.el7              net-snmp-libs.x86_64 1:5.7.2-48.el7_8        
  php72w-bcmath.x86_64 0:7.2.27-1.w7         php72w-ldap.x86_64 0:7.2.27-1.w7             
  php72w-xml.x86_64 0:7.2.27-1.w7            unixODBC.x86_64 0:2.3.1-14.el7               
  zabbix-web.noarch 0:4.4.8-1.el7           

Complete!
[root@server ~]# 

重試了十幾次,下載成功

  • 下面的是一個安裝腳本,僅供參考
#!/bin/bash
#這個是阿里雲的源
echo -e "請給出要安裝的zabbix版本號,建議使用4.x的版本  \033[31musage:./zabbix_aliyun.sh 4.0|4.4|4.5 \033[0m"
echo "例如要安裝4.4版本,在命令行寫上 ./zabbix_aliyun.sh 4.4"
if [ -z $1 ];then
    exit
fi
VERSION=$1
if [ -f /etc/yum.repos.d/zabbix.repo ];then
    rm -rf /etc/repos.d/zabbix.repo
fi
rpm -qa | grep zabbix-release && rpm -e zabbix-release
rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/$VERSION/rhel/7/x86_64/zabbix-release-$VERSION-1.el7.noarch.rpm
sed -i "s@zabbix/.*/rhel@zabbix/$VERSION/rhel@g" /etc/yum.repos.d/zabbix.repo
sed -i '[email protected]@mirrors.aliyun.com/zabbix@g' /etc/yum.repos.d/zabbix.repo
[ $? -eq 0 ] && echo "阿里雲的zabbix源替換成功" || exit 1
yum clean all
yum makecache fast

下面的源是阿里雲的zabbix源

baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/$basearch/  
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/

3.18 導入數據庫腳本

[root@server ~]# cd /etc/zabbix/
[root@server zabbix]# tree .
.
├── web
│   └── maintenance.inc.php
├── zabbix_agentd.conf
├── zabbix_agentd.d
└── zabbix_server.conf

2 directories, 3 files
[root@server zabbix]# zcat /usr/share/doc/zabbix-server-mysql-4.4.8/
AUTHORS        ChangeLog      COPYING        create.sql.gz  NEWS           README
[root@server zabbix]# zcat /usr/share/doc/zabbix-server-mysql-4.4.8/create.sql.gz | mysql -uzabbix -p zabbix
Enter password: 

zact代表不執行解壓,直接看

這樣就可以解壓到內存當中,不佔用空間

  • 到數據庫內查看
[root@server zabbix]# mysql -uzabbix -pzabbix123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [zabbix]> show tables
    -> ;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
······························

退出數據庫

3.19 修改服務端server配置文件

[root@server zabbix]# vim /etc/zabbix/zabbix_server.conf 
 38 LogFile=/var/log/zabbix/zabbix_server.log
 49 LogFileSize=0	#日誌容量沒有上限
 72 PidFile=/var/run/zabbix/zabbix_server.pid
 82 SocketDir=/var/run/zabbix
 91 DBHost=localhost	#開啓
100 DBName=zabbix
116 DBUser=zabbix
124 DBPassword=zabbix123	#修改本行
356 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
473 Timeout=4
516 AlertScriptsPath=/usr/lib/zabbix/alertscripts
527 ExternalScripts=/usr/lib/zabbix/externalscripts
563 LogSlowQueries=3000		#慢日誌

慢日誌,漫長操作的動作,會被記錄到慢日誌,記錄了執行速度特別慢的SQL語句

3.20 修改zabbix字體

[root@server zabbix]# vim /usr/share/zabbix/include/defines.inc.php 
#使用末行模式
:% s /graphfont/kaiti/g
[root@server zabbix]# mkdir fonts
[root@server zabbix]# ll
total 36
drwxr-xr-x 2 root   root       6 May 21 23:01 fonts
drwxr-x--- 2 apache apache    33 May 21 22:48 web
-rw-r--r-- 1 root   root   13936 Apr 27 18:23 zabbix_agentd.conf
drwxr-xr-x 2 root   root       6 Apr 27 18:22 zabbix_agentd.d
-rw-r----- 1 root   zabbix 19778 May 21 23:00 zabbix_server.conf
[root@server zabbix]# cd fonts/
[root@server fonts]# ll
total 12440
-rw-r--r-- 1 root root 12736196 May 21 23:04 STKAITI.TTF
[root@server fonts]# pwd
/etc/zabbix/fonts
[root@server fonts]# pwd
/nginx/html/zabbix/fonts
[root@server fonts]# cp /etc/zabbix/fonts/STKAITI.TTF .

3.21 給zabbix相關權限

[root@server fonts]# cp -r /usr/share/zabbix /nginx/html/
[root@server fonts]# chown -R zabbix:zabbix /etc/zabbix/
[root@server fonts]# chown -R zabbix:zabbix /usr/share/nginx/
[root@server fonts]# chown -R zabbix:zabbix /usr/lib/zabbix/
[root@server fonts]# chmod -R 755 /etc/zabbix/web/
[root@server fonts]# chmod -R 777 /var/lib/php/session/
[root@server nginx]# chown -R zabbix:zabbix /nginx/
[root@server ~]# chown -R zabbix:zabbix /nginx/

3.22 開啓zabbix服務

[root@server fonts]# systemctl start zabbix-server
[root@server fonts]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@server fonts]# systemctl start zabbix-agent
[root@server fonts]# systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.

3.23 查看端口號

[root@server fonts]# netstat -natp | grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      6048/zabbix_agentd  
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      5671/zabbix_server  
tcp6       0      0 :::10050                :::*                    LISTEN      6048/zabbix_agentd  
tcp6       0      0 :::10051                :::*                    LISTEN      5671/zabbix_server 

3.24 重啓之前的服務,php-fpm、nginx

[root@server fonts]# systemctl restart php-fpm
[root@server fonts]# systemctl restart nginx

3.25 訪問192.168.247.142/zabbix/

訪問結果發現404報錯

3.26 修改nginx配置文件

  8     location / {
  9         root   /nginx/html;		#修改站點爲/nginx/html
 10         index  index.html index.htm index.php;
 11     }

然後重啓,

[root@server ~]# systemctl restart nginx

可以了

備註:業務站點爲了穩定,可以不用修改站點目錄,以免混淆

3.27 網頁在線安裝zabbix

  • 下一步
    在這裏插入圖片描述

  • 下一步
    在這裏插入圖片描述

  • 數據庫密碼,zabbix用戶的密碼
    在這裏插入圖片描述

  • 下一步,名字改爲gsy

在這裏插入圖片描述

  • 下一步

在這裏插入圖片描述

  • 出現報錯
    在這裏插入圖片描述

  • 說少一個文件

在這裏插入圖片描述

  • 點擊下載,將這個文件導入到指定路徑
    在這裏插入圖片描述
Download the configuration file
Save it as "/etc/zabbix/web/zabbix.conf.php"

在這裏插入圖片描述

  • 點擊完成finsh

備註:給這個/etc/zabbix/web/zabbix.conf.php文件一個zabbix的權限

[root@server web]# chown zabbix.zabbix zabbix.conf.php 
可以重新啓動一下zabbix-server
systemctl restart zabbix-server

在這裏插入圖片描述

3. 28 進入登錄界面

用戶默認:Admin

密碼默認:zabbix
在這裏插入圖片描述
在這裏插入圖片描述

3.29 設置語言環境

在這裏插入圖片描述
在這裏插入圖片描述

  • 點擊更新

在這裏插入圖片描述

四:配置代理端,即被監控服務端

被監控的服務端都需要安裝zabbix-agent

在這裏插入圖片描述
在這裏插入圖片描述
宏函數官方文檔:
https://www.zabbix.com/documentation/4.0/zh/manual/config/macros/macro_functions
用戶宏變量官方文檔:
https://www.zabbix.com/documentation/4.0/zh/manual/config/macros/usermacros
自動發現宏(LLD)
https://www.zabbix.com/documentation/4.0/zh/manual/config/macros/lld_macros

4.1 下載zabbix-agent

[root@client ~]# rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.QTmVVB: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-4.4-1.el7         ################################# [100%]
[root@client ~]# yum list
[root@client ~]# yum install -y zabbix-agent

4.2 修改agent配置文件

[root@client ~]# vim /etc/zabbix/zabbix_agentd.conf 
 13 PidFile=/var/run/zabbix/zabbix_agentd.pid
 32 LogFile=/var/log/zabbix/zabbix_agentd.log
 43 LogFileSize=0
 98 Server=192.168.247.142	#指向zabbix-server服務端
139 ServerActive=192.168.247.142	#指向zabbix-server服務端
150 Hostname=client1	#zabbix-agent名稱
290 Include=/etc/zabbix/zabbix_agentd.d/*.conf
[root@client ~]# setenforce 0
[root@client ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
[root@client ~]# systemctl stop NetworkManager
[root@client ~]# systemctl disable NetworkManager
[root@client ~]# iptables -F
[root@client ~]# systemctl start zabbix-agent.service
[root@client ~]# systemctl enable zabbix-agent.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@client ~]# netstat -natp | grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      48909/zabbix_agentd 
tcp6       0      0 :::10050                :::*                    LISTEN      48909/zabbix_agentd 

五:增加被監控主機

配置——主機——創建主機

添加主機
在這裏插入圖片描述

可以手動添加,也可以做一個自動發現機制

  • 創建主機
    在這裏插入圖片描述

  • 點擊添加
    在這裏插入圖片描述
    在這裏插入圖片描述

六:添加模板

在這裏插入圖片描述

點擊下面主機
在這裏插入圖片描述

選擇監聽服務,http 和ssh
在這裏插入圖片描述
在這裏插入圖片描述

點擊更新
在這裏插入圖片描述

七:查看client的服務

[root@client ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-05-21 15:41:55 CST; 17h ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 985 (sshd)
   CGroup: /system.slice/sshd.service
           └─985 /usr/sbin/sshd -D

May 21 15:41:55 nginx systemd[1]: Starting OpenSSH server daemon...
May 21 15:41:55 nginx sshd[985]: Server listening on 0.0.0.0 port 22.
May 21 15:41:55 nginx sshd[985]: Server listening on :: port 22.
May 21 15:41:55 nginx systemd[1]: Started OpenSSH server daemon.
May 21 15:51:16 nginx sshd[2480]: Accepted password for root from 192.168.247.1 port 64983 ssh2
May 21 20:19:03 client sshd[128870]: Accepted password for root from 192.168.247.1 port 50651 ssh2
May 22 08:26:39 client sshd[112471]: Accepted password for root from 192.168.247.1 port 59045 ssh2
Hint: Some lines were ellipsized, use -l to show in full.
[root@client ~]# systemctl status httpd
Unit httpd.service could not be found.

八:測試zabbix監控

8.1 回到首頁,查看監控項目

一般是隔300S監控一次
在這裏插入圖片描述

8.2 出現報警,把sshd也停掉測試

[root@client ~]# systemctl stop sshd

等一會

8.3 此時點擊client01

在這裏插入圖片描述

8.4 可以使用PING、traceroute去測試網絡狀態

在這裏插入圖片描述
在這裏插入圖片描述

zabbix-server缺少traceroute工具

[root@server ~]# yum install traceroute -y

在這裏插入圖片描述

8.5 此時ssh服務檢測到

在這裏插入圖片描述

8.6 開啓sshd服務

[root@client ~]# systemctl start sshd
[root@client ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-05-22 09:48:46 CST; 4s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 75812 (sshd)
   CGroup: /system.slice/sshd.service
           └─75812 /usr/sbin/sshd -D

May 22 09:48:46 client systemd[1]: Starting OpenSSH server daemon...
May 22 09:48:46 client sshd[75812]: Server listening on 0.0.0.0 port 22.
May 22 09:48:46 client sshd[75812]: Server listening on :: port 22.
May 22 09:48:46 client systemd[1]: Started OpenSSH server daemon.

8.7 等到下一個監控週期查看是否取消掉

在這裏插入圖片描述

8.8 監控問題消失

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章