本次實驗,我們主要在centos 7 系統上部署zabbix監控,并實作監控交換機,監控Apache服務器,實作郵箱報警等操作
LNMP環境構建
| 軟體包 | 下載地址 |
|---|---|
| nginx-1.8.0.tar.gz | http://nginx.org/download/ |
| mysql-5.6.26.tar.gz | http://dev.mysql.com/downloads/mysql/ |
| php-5.6.13.tar.bz2 | http://php.net/downloads.php |
Nginx的安裝
構建的 程序中提前關閉防火墻以及selinux
[root@zabbix-server ~]# mkdir /lnmp //新建一個存放原始碼包的目錄
[root@zabbix-server ~]# cd /lnmp/
[root@zabbix-server lnmp]# ls //下載對應的軟體包
mysql-5.6.26.tar.gz nginx-1.8.0.tar.gz php-5.6.13.tar.bz2
[root@zabbix-server lnmp]# yum install gcc gcc-c++ autoconf automake libtool make zlib zlib-devel openssl openssl-devel pcre* pcre-devel -y //解決相關依賴關系
[root@zabbix-server lnmp]# useradd -s /sbin/nologin -M nginx
[root@zabbix-server lnmp]# tar -xf nginx-1.8.0.tar.gz //解壓Nginx原始碼包
[root@zabbix-server lnmp]# cd nginx-1.8.0/
[root@zabbix-server nginx-1.8.0]# ./configure --perfix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre //編譯
[root@zabbix-server nginx-1.8.0]# make && make install //安裝操作
[root@zabbix-server ~]# vim /usr/local/nginx/conf/nginx.conf //編輯Nginx的組態檔
4 user nginx nginx;
43 location / {
44 root html;
45 index index.php index.html index.htm;
46 }
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
70 include fastcgi_params;
71 }
72
[root@zabbix-server ~]# /usr/local/nginx/sbin/nginx //啟動Nginx服務器
[root@zabbix-server ~]# ss -tan | grep 80
LISTEN 0 128 *:80 *:*
瀏覽器訪問測驗

mysql的安裝
注:安裝mysql不能夠用GCC等編譯工具來進行編譯了,需要使用cmake 來進行編譯,我們直接執行以下命令即可
[root@zabbix-server ~]# yum install -y cmake ncurses-devel //安裝mysql需要用到這兩個軟體包
編譯安裝程序:
[root@zabbix-server lnmp]# tar -xf mysql-5.6.26.tar.gz
[root@zabbix-server lnmp]# useradd -s /sbin/nologin -M mysql
[root@zabbix-server lnmp]# cd mysql-5.6.26/
[root@zabbix-server mysql-5.6.26]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL-USER=mysql
[root@zabbix-server mysql-5.6.26]# make -j 2 && make install //執行安裝程序
[root@zabbix-server ~]# chown -R mysql:mysql /usr/local/mysql/ //賦權操作
[root@zabbix-server ~]# cd /usr/local/mysql/
[root@zabbix-server mysql]# mkdir date //創建一個存放資料的目錄(因為該目錄已經存在了一個data目錄,所以命名為date)
[root@zabbix-server mysql]# chown -R mysql:mysql date/
[root@zabbix-server mysql]# cd support-files/ //進入這個目錄
[root@zabbix-server support-files]# cp -a my-default.cnf /etc/my.cnf //復制操作
cp:是否覆寫"/etc/my.cnf"? y
[root@zabbix-server support-files]# cp -a mysql.server /etc/init.d/mysqld
[root@zabbix-server support-files]# chmod a+x /etc/init.d/mysqld
[root@zabbix-server support-files]# vim /etc/init.d/mysqld
46 basedir=/usr/local/mysql
47 datadir=/usr/local/mysql/date
[root@zabbix-server support-files]# chkconfig mysqld on //設定為開機自動啟動
[root@zabbix-server support-files]# usr/local/mysql/scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/date //初始化資料庫
[root@zabbix-server mysql]# ln -s /usr/local/mysql/bin/* /bin/ //連接mysql的命令到/bin目錄下 這樣可以全域使用mysql相關命令
[root@zabbix-server mysql]# /etc/init.d/mysqld start //啟動資料庫
Starting MySQL. SUCCESS!
[root@zabbix-server mysql]# ss -tan | grep 3306
LISTEN 0 80 [::]:3306 [::]:*
[root@zabbix-server ~]# mysql_secure_installation //初始化資料庫,至自定義密碼
[root@zabbix-server ~]# mysql -uroot -p //登錄驗證
Enter password:
PHP的安裝
解決相關依賴關系:
[root@zabbix-server ~]# yum -y install gcc gcc-c++ libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel libicu-devel freetype-devel openldap-devel openldap openldap-devel php-pear sqlite-devel
安裝libmcrypt
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt 軟體包下載地址
[root@zabbix-server /]# tar -xf libmcrypt-2.5.8.tar.bz2
[root@zabbix-server libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt //編譯安裝
[root@zabbix-server libmcrypt-2.5.8]# make && make install
[root@zabbix-server ~]# vim /etc/ld.so.conf //編輯這個檔案,添加兩個lib庫的位置
/usr/local/libmcrypt/lib
/usr/local/mysql/lib
[root@zabbix-server ~]# ldconfig //執行這個生效
[root@zabbix-server ~]# echo "ldconfig" >> /etc/rc.local //寫入到開機自動執行
安裝PHP
[root@zabbix-server lnmp]# tar -xf php-5.6.13.tar.bz2
[root@zabbix-server lnmp]# cd php-5.6.13/
[root@zabbix-server php-5.6.13]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-mysqlnd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --with-gettext --with-mcrypt=/usr/local/libmcrypt //編譯
[root@zabbix-server php-5.6.13]# make -j 2 && make install //執行安裝
[root@zabbix-server php-5.6.13]# cp -a php.ini-development /usr/local/php/php.ini //復制PHP.ini 檔案
[root@zabbix-server etc]# pwd
/usr/local/php/etc //進入這個目錄
[root@zabbix-server etc]# ls
pear.conf php-fpm.conf.default
[root@zabbix-server etc]# cp php-fpm.conf.default php-fpm.conf
[root@zabbix-server php-5.6.13]# cp -a sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //復制啟動及腳本檔案
[root@zabbix-server php-5.6.13]# chmod a+x /etc/init.d/php-fpm
[root@zabbix-server php-5.6.13]# /etc/init.d/php-fpm start
Starting php-fpm done
[root@zabbix-server php-5.6.13]# ss -tan | grep 9000
LISTEN 0 128 127.0.0.1:9000 *:*
測驗Nginx能否識別PHP檔案
[root@zabbix-server ~]# echo "<?php phpinfo; ?>" >> /usr/local/nginx/html/index.php

搭建zabbix 監控
https://cdn.zabbix.com/zabbix/sources zabbix原始碼包下載地址
搭建程序如下
[root@zabbix-server ~]# mkdir /zabbix //創建一個目錄
[root@zabbix-server ~]# cd /zabbix/
[root@zabbix-server zabbix]# tar -xf zabbix-4.2.4.tar.gz //上傳zabbix 原始碼包,并進行解壓操作
[root@zabbix-server zabbix-4.2.4]# useradd -s /sbin/nologin -M zabbix //創建zabbix用戶
[root@zabbix-server zabbix-4.2.4]# yum install -y net-snmp-devel libevent libevent-devel //依賴關系解決
[root@zabbix-server zabbix-4.2.4]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-mysql //編譯安裝
[root@zabbix-server zabbix-4.2.4]# make install //直接make install 即可
匯入資料庫
[root@zabbix-server ~]# mysql -uroot -p //登錄資料庫
mysql> create database zabbix character set utf8 collate utf8_bin; //創建zabbix資料庫
Query OK, 1 row affected (0.00 sec)
mysql> create user 'zabbix'@'localhost' identified by 'zabbix'; //創建zabbix用戶
Query OK, 0 rows affected (0.09 sec)
mysql> grant all privileges on *.* to 'zabbix'@'localhost' with grant option; //為zabbix賦權
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; //重繪資料庫
Query OK, 0 rows affected (0.00 sec)
匯入資料庫操作
[root@zabbix-server ~]# cd /zabbix/zabbix-4.2.4/
[root@zabbix-server zabbix-4.2.4]# mysql -uzabbix -p zabbix < database/mysql/schema.sql
Enter password:
[root@zabbix-server zabbix-4.2.4]# mysql -uzabbix -p zabbix < database/mysql/images.sql
Enter password:
[root@zabbix-server zabbix-4.2.4]# mysql -uzabbix -p zabbix < database/mysql/data.sql
Enter password:
編輯zabbix-server 配置 檔案
[root@zabbix-server ~]# vim /usr/local/zabbix/etc/zabbix_server.conf
85 DBHost=localhost //本地系統的名稱
94 DBName=zabbix //資料庫的名稱
110 DBUser=zabbix //資料庫用戶名
118 DBPassword=zabbix //資料庫用戶名的密碼
[root@zabbix-server ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
113 Server=127.0.0.1 //zabbix_server 服務器的地址
154 ServerActive=127.0.0.1
165 Hostname=Zabbix server
[root@zabbix-server ~]# /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
我們可以使用這個命令檢測我們的配置是否有誤
zabbix 優化操作
[root@zabbix-server zabbix-4.2.4]# cd misc/init.d/fedora/core
[root@zabbix-server core]# ls
zabbix_agentd zabbix_server
[root@zabbix-server core]# cp -a * /etc/init.d/
[root@zabbix-server core]# chmod a+x /etc/init.d/zabbix_*
[root@zabbix-server core]# vim /etc/init.d/zabbix_server
[root@zabbix-server core]# vim /etc/init.d/zabbix_agentd
編輯這個兩個檔案 都修改為:
22 BASEDIR=/usr/local/zabbix //編輯這一行
啟動操作
[root@zabbix-server core]# /etc/init.d/zabbix_server start
Reloading systemd: [ 確定 ]
Starting zabbix_server (via systemctl): [ 確定 ]
[root@zabbix-server core]# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd (via systemctl): [ 確定 ]
[root@zabbix-server core]# netstat -lnupt | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 59561/zabbix_agentd
通過以上啟動我們發現只啟動了zabbix_agentd 埠,zabbix_server 端沒有啟動,現在我們來解決:
[root@zabbix-server ~]# find / -name mysql.sock //搜索這個檔案的路徑
/tmp/mysql.sock
[root@zabbix-server ~]# vim /usr/local/zabbix/etc/zabbix_server.conf //編輯主組態檔
DBSocket= /tmp/mysql.sock //添加這個即可 DBS為大寫
[root@zabbix-server ~]# netstat -lnupt | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 59561/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 78386/zabbix_server
最后兩個服務就啟動完成了
復制zabbix的頁面到Nginx的發布目錄中
[root@zabbix-server php]# cd /zabbix/zabbix-4.2.4/frontends/php/
[root@zabbix-server php]# cp -r * /usr/local/nginx/html/
cp:是否覆寫"/usr/local/nginx/html/index.php"? y
瀏覽器端配置安裝

點擊next step

這里出現了很多fail,這個解決方法在我的上一篇博客中寫的有,這里就不做寫了
以上問題解決以后點擊next step

然后在點擊next step

默認不配置,點擊next step

出來了以下的錯誤,這個錯誤在上一篇博客也有解決方案,這里也不做多的講解了

最后解決完成以后的界面圖如下:

登錄界面(用戶名 Admin 密碼 zabbix )

登錄之后的界面是這樣子的

將當前頁面調為中文設定

解決圖形界面中文亂碼的問題

操作如下:
Win+R >fonts >拷貝微軟雅黑字體改名為 msyh.ttf >/usr/local/nginx/html/assets/fonts
vim /usr/local/nginx/html/include/defines.inc.php
修改 zabbix php 頁面配置,改為 msyh
define('ZBX_GRAPH_FONT_NAME', 'msyh');
改了之后的效果如下

添加被監控端(centos 7 作為httpd服務器)
被監控端需要安裝 zabbix-agent
下載地址:http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/
安裝程序:
[root@zabbix-agent zabbix-4.2.4]# yum install -y curl curl-devel net-snmp net-snmp-devel perl-DBI pcre* gcc gcc-c++ //先解決依賴關系
[root@zabbix-agent ~]# wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.2.4/zabbix-4.2.4.tar.gz //下載對應的軟體包
[root@zabbix-agent ~]# tar -xf zabbix-4.2.4.tar.gz //解壓操作
[root@zabbix-agent zabbix-4.2.4]# useradd -s /sbin/nologin -M zabbix
[root@zabbix-agent zabbix-4.2.4]# ./configure --prefix=/usr/local/zabbix --enable-agent //然后在來進行編譯安裝即可
[root@zabbix-agent zabbix-4.2.4]# make install
[root@zabbix-agent ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf //編輯組態檔
94 Server=192.168.1.100
135 ServerActive=192.168.1.100
[root@zabbix-agent ~]#cd zabbix-4.2.4/misc/init.d/fedora/core //進入這個目錄
[root@zabbix-agent core]# cp -a zabbix_agentd /etc/init.d/ //復制zabbix.agentd 檔案到指定目錄下
[root@zabbix-agent core]# chmod a+x /etc/init.d/zabbix_agentd
[root@zabbix-agent core]# vi /etc/init.d/zabbix_agentd
22 BASEDIR=/usr/local/zabbix
[root@zabbix-agent ~]# /etc/init.d/zabbix_agentd start //啟動測驗
Reloading systemd: [ 確定 ]
Starting zabbix_agentd (via systemctl): [ 確定 ]
[root@zabbix-agent ~]# ss -tan | grep 10050
LISTEN 0 128 *:10050 *:*
配置httpd服務器
[root@zabbix-agent ~]# yum install -y httpd
[root@zabbix-agent ~]# systemctl start httpd
[root@zabbix-agent ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@zabbix-agent ~]# echo "this is httpd server " >> /var/www/html/index.html
[root@zabbix-agent ~]# curl localhost
this is httpd server
zabbix-server 端測驗能否獲取到zabbix-agnet 端的資訊
[root@zabbix-server ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.1.10 -p10050 -ksystem.uname
Linux zabbix-agent 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64
引數詳解:
-s 指定客戶端的IP地址
-p 指定埠號
-k 回傳的型別
瀏覽器端添加被監控主機

點擊創建主機

然后在點擊模板即可

最后出現這個代表以及成功監控這一臺主機了

匯入Apache相關功能的模塊
下載這個壓縮包: https://github.com/lorf/zapache/archive/master.zip

然后我們點擊匯入按鈕

我們點擊這個

然后點擊模板

然后我們就可以通過圖形這個選項 來監控httpd服務的各項狀態了

監控華為交換機
在ensp軟體中構建如下的網路結構拓撲圖

SW1的配置
[SW1]int Vlanif if //進入vlanif 1
[SW1-Vlanif1]ip address 192.168.1.150 24 //配置IP地址
[SW1]ping 192.168.1.100 //連通測驗zabbix-server 服務器
PING 192.168.1.100: 56 data bytes, press CTRL_C to break
Reply from 192.168.1.100: bytes=56 Sequence=1 ttl=64 time=60 ms
Reply from 192.168.1.100: bytes=56 Sequence=2 ttl=64 time=20 ms
Reply from 192.168.1.100: bytes=56 Sequence=3 ttl=64 time=30 ms
Reply from 192.168.1.100: bytes=56 Sequence=4 ttl=64 time=30 ms
Reply from 192.168.1.100: bytes=56 Sequence=5 ttl=64 time=10 ms
[SW1]snmp-agent //開啟snmp服務
[SW1]snmp-agent community read zabbix@123
[SW1]snmp-agent sys-info version all
[SW1]snmp-agent target-host inform address udp-domain 192.168.1.100 udp-port 161
params securityname zabbix@123 v2c
[SW1]snmp-agent trap enable
Warning: All switches of SNMP trap/notification will be open. Continue? [Y/N]:y
zabbix-server 端的配置
[root@zabbix-server ~]# yum install -y net-snmp* //安裝snmp相關的工具
[root@zabbix-server ~]# systemctl start snmpd //啟動snmpd服務
[root@zabbix-server ~]# systemctl enable snmpd //設定為開機自動啟動
Created symlink from /etc/systemd/system/multi-user.target.wants/snmpd.service to /usr/lib/systemd/system/snmpd.service.
然后在zabbix-server端測驗一下能否識別交換機
[root@zabbix-server ~]# snmpwalk -v 2c -c zabbix@123 192.168.1.150 system
SNMPv2-MIB::sysDescr.0 = STRING: S5700-28C-HI
Huawei Versatile Routing Platform Software
VRP (R) software,Version 3.30 (S5700 V200R001C00)
Copyright (C) 2007 Huawei Technologies Co., Ltd.
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.2011.2.23.169
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (271054) 0:45:10.54
SNMPv2-MIB::sysContact.0 = STRING: R&D Beijing, Huawei Technologies co.,Ltd.
SNMPv2-MIB::sysName.0 = STRING: SW1
SNMPv2-MIB::sysLocation.0 = STRING: Beijing China
SNMPv2-MIB::sysServices.0 = INTEGER: 78
回傳以上資訊就代表可以識別
zabbix-server 瀏覽器端的配置

點擊創建主機

然后點擊模板

然后點擊宏

最后出現這個就代表成功了

監控mysql資料庫
我們在centos 7 上安裝mariadb資料庫來進行測驗
[root@zabbix-agent ~]# yum install -y mariadb mariadb-server //安裝資料庫
[root@zabbix-agent ~]# systemctl start mariadb //啟動資料庫
[root@zabbix-agent ~]# mysql_secure_installation //初始化資料庫
[root@zabbix-agent ~]# mysql -uroot -p //登錄資料庫
創建一個用于監控專用的用戶
MariaDB [(none)]> grant usage on *.* to zabbix@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
復制zabbix自帶的mysql監控模板
[root@zabbix-agent ~]# cd zabbix-4.2.4/conf/zabbix_agentd
[root@zabbix-agent zabbix_agentd]# ls
userparameter_examples.conf userparameter_mysql.conf
[root@zabbix-agent zabbix_agentd]# cp -r userparameter_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d/ //復制到這個目錄下
[root@zabbix-agent zabbix_agentd]# vi /usr/local/zabbix/etc/.my.cnf //編輯一個腳本檔案
#Zabbix Agent
[mysql]
host=zabbix-agent //被監控的主機名稱
user=zabbix //監控的用戶 就是上面我們創建的哪一個
password=123 //密碼
socket= /var/lib/mysql/mysql.sock //這個檔案要根據你安裝的資料庫所在來定
[mysqladmin]
host=zabbix-agent
user=zabbix
password=123
socket= /var/lib/mysql/mysql.sock
[root@zabbix-agent zabbix_agentd]# vi /usr/local/zabbix/etc/zabbix_agentd.conf //然后再次修改zabbix的組態檔
去掉注釋,修改為正確的路徑
265 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
[root@zabbix-agent zabbix_agentd]# vi /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf //修改mysql的模板檔案
將里面的 所有的 /var/lib/zabbix 通通改為/usr/loca/zabbix/etc 文中一共有三處需要改
[root@zabbix-agent zabbix_agentd]# /etc/init.d/zabbix_agentd restart //重啟生效
Restarting zabbix_agentd (via systemctl): [ 確定 ]
[root@zabbix-agent zabbix_agentd]# ss -tan | grep 10050
LISTEN 0 128 *:10050 *:*
zabbix-server 端測驗能否獲取到資料
[root@zabbix-server ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.1.10 -p 10050 -k mysql.ping
1 //回傳1代表成功
zabbix-server 瀏覽器端配置

點擊我們之前已經創建好的主機

添加完成以后這里就會多出一個mysql的監控項

驗證測驗是否有成功監控到mysql資料庫

聯合163郵箱實作報警
自行注冊一個163郵箱然后開啟如下的服務

zabbix-server 端的配置
[root@zabbix-server ~]# yum install -y mailx //安裝這個軟體
[root@zabbix-server ~]# vi /etc/mail.rc //然后編輯這個組態檔
set from=xxx@163.com //郵箱名稱
set smtp=smtp.163.com
set smtp-auth-user=xxx@163.com
set smtp-auth-password=授權碼
set smtp-auth=login
[root@zabbix-server ~]# echo "zabbix test mail" | mailx -s "zabbix server " zabbix_123@163.com
注:
echo 輸出的是內容 -s 指定的標題
驗證是否有收到我們發送的郵件

然后撰寫一個腳本檔案
[root@zabbix-server ~]# cd /usr/local/zabbix/share/zabbix/alertscripts/
[root@zabbix-server alertscripts]# vim sendmail.sh
#!/bin/bash
messages=`echo $3 | tr '\r\n' '\n'`
subject=`echo $2 | tr '\r\n' '\n'`
echo "${messages}" | mailx -s "${subject}" $1 >>/tmp/sendmail.log 2>&1
[root@zabbix-server alertscripts]# chown zabbix.zabbix sendmail.sh //賦權操作
[root@zabbix-server alertscripts]# chmod a+x sendmail.sh
[root@zabbix-server ~]# vim /usr/local/zabbix/etc/zabbix_server.conf //修改主組態檔
AlerScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
添加一行這個代碼
[root@zabbix-server ~]# /usr/local/zabbix/share/zabbix/alertscripts/sendmail.sh zabbix_123@163.com "zabbix mail" "come on bady"
發送一個代碼來進行測驗
驗證測驗

配置zabbix web 監控項郵件報警

點擊創建媒介型別

{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
添加完成以后是這樣的

然后進行下一步操作

然后點擊Admin 這個用戶

然后我們在來進行創建發送郵件的動作

點擊創建動作按鈕

然后點擊操作

默認接受人內容標題: 故障{TRIGGER.STATUS},服務器:{HOSTNAME1}發生:{TRIGGER.NAME}故障!
默認資訊內容:
告警主機:{HOSTNAME1}
告警時間:{EVENT.DATE} {EVENT.TIME}
告警等級:{TRIGGER.SEVERITY}
告警資訊:{TRIGGER.NAME}
告警專案:{TRIGGER.KEY1}
問題詳情:{ITEM.NAME}:{ITEM.VALUE}
當前狀態:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
然后點擊恢復操作

默認接收人:已恢復!{TRIGGER.STATUS}, 服務器:{HOSTNAME1}: {TRIGGER.NAME}
恢復資訊:
告警主機:{HOSTNAME1}
告警時間:{EVENT.DATE} {EVENT.TIME}
告警等級:{TRIGGER.SEVERITY}
告警資訊: {TRIGGER.NAME}
告警專案:{TRIGGER.KEY1}
問題詳情:{ITEM.NAME}:{ITEM.VALUE}
當前狀態:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件 ID:{EVENT.ID}
添加完成以后的樣子是這樣的

測驗是否會通過郵箱報警
我們關閉centos 7 系統上的httpd服務器,看看會不會給我發送資訊來提示
[root@zabbix-agent ~]# systemctl stop httpd
監控開始報錯

郵箱測驗

至此,整個環境以及監控的各項主機郵箱報警的搭建就到此完成了,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/155767.html
標籤:其他
