zabbix生產環境案例(三)

#生產環境案例(三)php

連接:https://pan.baidu.com/s/1q5YwJMTcZLcS5OQ0iOu44A 提取碼:8gdi 複製這段內容後打開百度網盤手機App,操做更方便哦html

##1. Zabbix生產環境監測案例概述 ###1.1 項目規劃java

主機分組node

  • 交換機
  • Nginx
  • Tomcat
  • MySQL
  • Apache
  • PHP-fpm
  • redis
  • memcache

監控對象識別:mysql

  • 使用SNMP監控交換
  • 使用IPMI監控服務器硬件
  • 使用Agent監控服務器
  • 使用JMX監控JAVA
  • 監控MySQL
  • 監控Web狀態
  • 監控Nginx狀態
  • 監控Apache狀態
  • 監控Tomcat狀態 ###1.2 SNMP監控流程
  • 交換機上開啓snmp
  • 在zabbix上添加監控(設置SNMP interfaces)
  • 關聯監控模版 ###1.3 IPMI 建議使用自定義item監控服務器硬件,在本地執行ipmitool命令來獲取數據

能夠在本地執行ipmitool命令獲取數據(命令須要安裝) ###1.4 JMX(使用Zabbix Java Gateway代理) 用來獲取java數據,本次的實戰內容 ###1.5 實戰監控Nginx,Apache,MySQL,PHP-fpm 今天的實戰內容,請同窗們注意總結過程 ###1.6 Zabbix的Web監測 今天的實戰內容,請同窗們注意總結過程linux

##2. Zabbix監控MySQL數據庫操做實戰ios

咱們須要部署一個MySQL服務和一個zabbix-agentd客戶端 ###2.1 Zabbix-Agen端編寫監控腳本 在nginx服務器(192.168.200.90)上安裝一個MySQL 下面是監控mysql狀態的一個shell腳本,內容以下:nginx

[root@Zabbix-Agen /]# mkdir -p /server/scripts
[root@Zabbix-Agen /]# cd /server/scripts/
[root@Zabbix-Agen scripts]# cat check_mysql.sh 
#!/bin/bash
# author:Mr.yang

MySQL_USER="root"
MySQL_PWD="971108"
MySQL_HOST="127.0.0.1"
MySQL_PORT="3306"
MySQL_CONN="/usr/local/mysql/bin/mysqladmin -u${MySQL_USER} -h${MySQL_HOST} -P${MySQL_PORT} -p${MySQL_PWD}"
if [ $# -ne "1" ];then
    echo "arg error!"
fi
case $1 in
	Uptime)
		result=`${MySQL_CONN} status | cut -f2 -d":" | cut -f1 -d "T"`
		echo $result
        ;;
    Com_update)
        result=`${MySQL_CONN} extended-status | grep -w "Com_update" | cut -d"|" -f3`
        echo $result
		;;
	Slow_querles)
		result=`${MySQL_CONN} status | cut -f5 -d":" | cut -f1 -d"O"`
		echo $result
        ;;
    Com_select)
        result=`${MySQL_CONN} extended-status | grep -w "Com_select" | cut -d "|" -f3`
        echo $result
		;;
	Com_rollback)
		result=`${MySQL_CONN} extended-status | grep -w "Com_rollback" | cut -d"|" -f3`
		echo $result
        ;;
    Questions)
        result=`${MySQL_CONN} status | cut -f4 -d":" | cut -f1 -d"S"`
        echo $result
		;;
	Com_insert)
		result=`${MySQL_CONN} extended-status | grep -w "Com_insert" | cut -d"|" -f3`
		echo $result
        ;;
    Com_delete)
        result=`${MySQL_CONN} extended-status | grep -w "Com_delete" | cut -d"|" -f3`
        echo $result
		;;
	Com_commit)
		result=`${MySQL_CONN} extended-status | grep -w "Com_commit" | cut -d"|" -f3`
		echo $result
        ;;
    Bytes_sent)
        result=`${MySQL_CONN} extended-status | grep -w "Bytes_sent" | cut -d"|" -f3`
        echo $result
		;;
	Bytes_received)
		result=`${MySQL_CONN} extended-status | grep -w "Bytes_received" | cut -d"|" -f3`
		echo $result
        ;;
    Com_begin)
        result=`${MySQL_CONN} extended-status | grep -w "Com_begin" | cut -d"|" -f3`
        echo $result
		;;
	*)
		echo "Usage:$0(Uptime|Com_update|Slow_querles|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)"
        ;;
esac

###2.2 在zabbix-agent端建立自定義鍵值配置文件c++

#建立mysql.status的鍵值
[root@Zabbix-Agen scripts]# chmod +x check_mysql.sh
[root@Zabbix-Agen scripts]# chown zabbix.zabbix check_mysql.sh
[root@Zabbix-Agen scripts]# cd /etc/zabbix/zabbix_agentd.d/

#刪除舊鍵值模版
[root@Zabbix-Agen zabbix_agentd.d]# ls
userparameter_mysql.conf
[root@Zabbix-Agen zabbix_agentd.d]# rm -rf userparameter_mysql.conf 

#建立mysql.ping和mysql.version的鍵值
[root@Zabbix-Agen zabbix_agentd.d]# cat mysql_status.conf 
UserParameter=mysql.status[*],/server/scripts/check_mysql.sh $1
UserParameter=mysql.ping,/usr/local/mysql/bin/mysqladmin -uroot -p971108 ping | grep -c alive
UserParameter=mysql.version,/usr/local/bin/mysql -V

#重啓zabbix-agentd服務
[root@Zabbix-Agen zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent:                                [  OK  ]
Starting Zabbix agent:                                          [  OK  ]

###2.3 在zabbix-server端測試鍵值git

[root@Zabbix-Server /]# zabbix_get -s 192.168.200.90 -p 10050 -k "mysql.status[Uptime]"
855
[root@Zabbix-Server /]# zabbix_get -s 192.168.200.90 -p 10050 -k "mysql.status[Com_commit]"
0
[root@Zabbix-Server /]# zabbix_get -s 192.168.200.90 -p 10050 -k "mysql.status[Bytes_sent]"
8926
[root@Zabbix-Server /]# zabbix_get -s 192.168.200.90 -p 10050 -k "mysql.status[Bytes_received]"
667
[root@Zabbix-Server /]# zabbix_get -s 192.168.200.90 -p 10050 -k "mysql.ping"
1
[root@Zabbix-Server /]# zabbix_get -s 192.168.200.90 -p 10050 -k "mysql.version"
/usr/local/bin/mysql  Ver 14.14 Distrib 5.5.32, for linux2.6 (x86_64) using readline 5.1

###2.4 在zabbix-server端Web前臺引入zabbix監控MySQL的模版

zabbix自帶監控MySQL的模版,咱們只須要將模版引入到主機便可 配置-->主機-->選擇主機-->模板,而後將MySQL模版鏈接到此主機便可

image_1cnt4ff2m172hq2dk454uo1b7m9.png-63.9kB

image_1cnt4novj1p5u1anl1u51k541gmu1g.png-34.5kB

image_1cnt4ogav6vu11r66c71q2cb21t.png-19.8kB

image_1cnt4r7f4c5oq6q1vc0k261puh2a.png-127.4kB 從圖中能夠發現模版裏的鍵值都是咱們以前已經定義好了的鍵值。 ##3.Zabbix監控Apache、Nginx操做實戰 ###3.1 實戰監控Apache ####3.1.1 安裝依賴軟件包

[root@Zabbix-Apache ~]# yum -y install gcc gcc-c++ make cmake unzip tree
[root@Zabbix-Apache ~]# rpm -qa gcc gcc-c++ make cmake unzip tree
gcc-c++-4.4.7-4.el6.x86_64
tree-1.5.3-2.el6.x86_64
make-3.81-20.el6.x86_64
gcc-4.4.7-4.el6.x86_64
cmake-2.6.4-5.el6.x86_64
unzip-6.0-1.el6.x86_64

####3.1.2 源碼編譯構建apache服務

#爲了不衝突,若系統中已經安裝httpd服務,務必刪除
[root@Zabbix-Apache ~]# rpm -q httpd
package httpd is not installed

#源碼構建apache
[root@Zabbix-Apache yuanmabao]# pwd
/root/yuanmabao
[root@Zabbix-Apache yuanmabao]# tar xf httpd-2.2.17.tar.gz -C /usr/src/
[root@Zabbix-Apache yuanmabao]# cd /usr/src/httpd-2.2.17/
[root@Zabbix-Apache httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi && make && make install
#如下省略。。。
[root@Zabbix-Apache httpd-2.2.17]# cd /usr/local/httpd/
[root@Zabbix-Apache httpd]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules
[root@Zabbix-Apache httpd]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[root@Zabbix-Apache httpd]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@Zabbix-Apache httpd]# chmod +x /etc/init.d/httpd
[root@Zabbix-Apache httpd]# cd /usr/local/httpd/htdocs/
[root@Zabbix-Apache htdocs]# echo "`hostname -I` I am apache" > index.html
[root@Zabbix-Apache htdocs]# cat index.html
192.168.200.91  I am apache
[root@Zabbix-Apache htdocs]# cd /usr/local/httpd/conf
[root@Zabbix-Apache conf]# awk '/#ServerName/{print NR,$0}' httpd.conf
97 #ServerName www.example.com:80
[root@Zabbix-Apache conf]# sed -i -e '97 s/#//;s/example/yunjisuan/' httpd.conf
[root@Zabbix-Apache conf]# sed -n '97p' httpd.conf
ServerName www.yunjisuan.com:80
[root@Zabbix-Apache conf]# /etc/init.d/httpd start
[root@Zabbix-Apache conf]# netstat -antup | grep httpd
tcp        0      0 :::80                       :::*                        LISTEN      53295/httpd
[root@Zabbix-Apache conf]# echo "`hostname -I` www.yunjisuan.com" >> /etc/hosts
[root@Zabbix-Apache conf]# tail -1 /etc/hosts
192.168.200.91  www.yunjisuan.com
[root@Zabbix-Apache conf]# curl www.yunjisuan.com
192.168.200.91  I am apache

####3.1.3 開啓apache狀態頁 要打開apache的ServerStatus頁面,須要在httpd.conf文件最下邊加入代碼段

[root@Zabbix-Apache conf]# pwd
/usr/local/httpd/conf
[root@Zabbix-Apache conf]# tail -7 /usr/local/httpd/conf/httpd.conf 
ExtendedStatus On
<location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</location>
#最後,重啓動apache便可
[root@Zabbix-Apache conf]# /etc/init.d/httpd restart

####3.1.4 下載apache zabbix模版並解壓

#從以下地址下載apache zabbix模版:
[root@Zabbix-Apache ~]# wget https://github.com/lorf/zapache/archive/master.zip

#解壓zip格式壓縮文件
[root@Zabbix-Apache ~]# unzip master
[root@Zabbix-Apache ~]# ls -d zapache-master/
zapache-master/
[root@Zabbix-Apache ~]# tree zapache-master/
zapache-master/
├── httpd-server-status.conf.sample
├── README.md
├── userparameter_zapache.conf.sample
├── zapache
├── zapache-template-active.xml
└── zapache-template.xml

0 directories, 6 files
  • 此模版文件中包含了監控apache的腳本文件,zabbix的apache模版文件,還有客戶端zabbix自定義傳key文件。
  • 首先將zapache放到須要監控的apache服務器上的/etc/zabbix/scripts目錄下,若是沒有scripts目錄,自行建立一個便可。而後執行受權: ####3.1.5 Zabbix-Apache端的agent安裝
[root@Zabbix-Apache ~]# wget http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-agent-3.2.4-1.el6.x86_64.rpm
[root@Zabbix-Apache ~]# rpm -ivh zabbix-agent-3.2.4-1.el6.x86_64.rpm
[root@Zabbix-Apache ~]# cd /etc/zabbix/
[root@Zabbix-Apache zabbix]# cat -n zabbix_agentd.conf | sed -n '13p;32p;95p;103p;120p;136p;147p;265p;284p'
    13  PidFile=/var/run/zabbix/zabbix_agentd.pid
    32  LogFile=/var/log/zabbix/zabbix_agentd.log
    95  Server=192.168.200.89     #這裏要取消本地
   103  ListenPort=10050
   120  StartAgents=3
   136  ServerActive=192.168.200.89:10051
   147  Hostname=192.168.200.91
#這裏要修改爲本身的名字,好比:主機IP
   265  Include=/etc/zabbix/zabbix_agentd.d/
   284  UnsafeUserParameters=1
[root@Zabbix-Apache /]# setenforce 0
[root@Zabbix-Apache /]# /etc/init.d/zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]
[root@Zabbix-Apache /]# netstat -antup | grep zabbix_agent
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      53511/zabbix_agentd 
tcp        0      0 :::10050                    :::*                        LISTEN      53511/zabbix_agentd
[root@Zabbix-Apache ~]# cd zapache-master/
[root@Zabbix-Apache zapache-master]# cd ~
[root@Zabbix-Apache ~]# mkdir -p /etc/zabbix/scripts/
[root@Zabbix-Apache ~]# cp /root/zapache-master/zapache /etc/zabbix/scripts/
[root@Zabbix-Apache ~]# chmod 755 /etc/zabbix/scripts/zapache
[root@Zabbix-Apache ~]# ll -d /etc/zabbix/scripts/zapache
-rwxr-xr-x. 1 root root 6110 Sep 21 22:48 /etc/zabbix/scripts/zapache
[root@Zabbix-Apache ~]# cd /etc/zabbix/scripts/
[root@Zabbix-Apache scripts]# ./zapache
zapache version: 1.5
usage:
  ./zapache [<url>] TotalAccesses                 - Check total accesses.
  ./zapache [<url>] TotalKBytes                   - Check total KBytes.
  ./zapache [<url>] CPULoad                       - Check CPU load.
  ./zapache [<url>] Uptime                        - Check uptime.
  ./zapache [<url>] ReqPerSec                     - Check requests per second.
  ./zapache [<url>] BytesPerSec                   - Check Bytes per second.
  ./zapache [<url>] BytesPerReq                   - Check Bytes per request.
  ./zapache [<url>] BusyWorkers                   - Check busy workers.
  ./zapache [<url>] IdleWorkers                   - Check idle workers.
  ./zapache [<url>] version                       - Version of this script.
  ./zapache [<url>] ping                          - Check if Apache is up.
  ./zapache [<url>] WaitingForConnection          - Check Waiting for Connection processess.
  ./zapache [<url>] StartingUp                    - Check Starting Up processess.
  ./zapache [<url>] ReadingRequest                - Check Reading Request processess.
  ./zapache [<url>] SendingReply                  - Check Sending Reply processess.
  ./zapache [<url>] KeepAlive                     - Check KeepAlive Processess.
  ./zapache [<url>] DNSLookup                     - Check DNSLookup Processess.
  ./zapache [<url>] ClosingConnection             - Check Closing Connection Processess.
  ./zapache [<url>] Logging                       - Check Logging Processess.
  ./zapache [<url>] GracefullyFinishing           - Check Gracefully Finishing Processess.
  ./zapache [<url>] IdleCleanupOfWorker           - Check Idle Cleanup of Worker Processess.
  ./zapache [<url>] OpenSlotWithNoCurrentProcess  - Check Open Slots with No Current Process.
  • 接着將userparameter_zapache.conf.sample文件放到/etc/zabbix/zabbix_agentd.d目錄下,並重命名爲userparameter_zapache.conf文件,而後修改鍵值命令的路徑。
  • 最後,重啓zabbix-agent服務
[root@Zabbix-Apache ~]# cd ~/zapache-master/
[root@Zabbix-Apache zapache-master]# mv userparameter_zapache.conf.sample /etc/zabbix/zabbix_agentd.d/userparameter_zapache.conf
[root@Zabbix-Apache zapache-master]# cd /etc/zabbix/zabbix_agentd.d/
[root@Zabbix-Apache zabbix_agentd.d]# tail -1 userparameter_zapache.conf
UserParameter=zapache[*],/etc/zabbix/scripts/zapache \$1
[root@Zabbix-Apache zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent:                                [  OK  ]
Starting Zabbix agent:                                          [  OK  ]

####3.1.6 測試鍵值

咱們發現腳本須要傳遞兩個參數,即url和選項,而後咱們在zabbix-server端進行鍵值測試

[root@Zabbix-Server ~]# zabbix_get -s 192.168.200.91 -p 10050 -k "zapache[127.0.0.1 TotalAccesses]"
0
[root@Zabbix-Server ~]# zabbix_get -s 192.168.200.91 -p 10050 -k "zapache[www.yunjisuan.com version]"
1.5
[root@Zabbix-Server ~]# zabbix_get -s 192.168.200.91 -p 10050 -k "zapache[www.yunjisuan.com ping]"
1

####3.1.7 在zabbix-server的Web頁面上監控apache (1)建立一個監控apache的主機

image_1cntgb55a1ir71lncnua1piq1trjgp.png-44.1kB

image.png-24kB

(2)導入帶有apache監控項的模版

zabbix默認並無監控apache的監控項模版。咱們須要將它導入到apache中。在以前解壓出來的目錄中,有待導入的web模版

[root@Zabbix-Apache ~]# tree zapache-master/
zapache-master/
├── httpd-server-status.conf.sample
├── README.md
├── zapache
├── zapache-template-active.xml    #Web模版
└── zapache-template.xml           #Web模版

0 directories, 5 files

咱們將這兩個.xml後綴的拷貝到windows上,而後從Web界面導入進去

image_1cnvj12b94gl12kl15bda7m1mg9.png-22.3kB

image_1cnvj1lmh7gj84s1cqeq3s1vkrm.png-39.5kB

image_1cnvj27nr1v3mbotsfagfg53n13.png-50.8kB

image_1cnvj2mlnb2j1krefv31ftk1rqo1g.png-50.6kB

導入之後Web端就有監控apache的監控項模版了

(3)將模版連接到apache主機

image_1cnvj3mhv1jmq1rhq1e21uf5ts51t.png-37.7kB

image_1cnvj44pkoml3ek1291k9b1qgl2a.png-29.8kB

image_1cnvj4jmdkjf1q0fbcdo3d13ub2n.png-35.5kB ###3.2 實戰監控nginx ####3.2.1用本地yum倉庫安裝依賴包

[root@Zabbix-Apache /]# yum install -y pcre-devel openssl-devel gcc gcc-c++ make 
[root@yangwenbo /]# rpm -qa pcre-devel openssl-devel gcc gcc-c++ make
openssl-devel-1.0.1e-15.el6.x86_64
gcc-4.4.7-4.el6.x86_64
gcc-c++-4.4.7-4.el6.x86_64
pcre-devel-7.8-6.el6.x86_64
make-3.81-20.el6.x86_64

####3.2.2 安裝Nginx

#源碼編譯Nginx
[root@Zabbix-Apache yuanmabao]# pwd
/yuanmabao
[root@Zabbix-Apache yuanmabao]# useradd -s /sbin/nologin -M www
[root@Zabbix-Apache yuanmabao]# tar xf nginx-1.10.2.tar.gz -C /usr/src/
[root@Zabbix-Apache yuanmabao]# cd /usr/src/nginx-1.10.2/
[root@Zabbix-Apache nginx-1.10.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module && make && make install
##編譯省略。。。
[root@Zabbix-Apache nginx-1.10.2]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
#建立nginx配置文件模版
[root@Zabbix-Apache nginx-1.10.2]# cd /usr/local/nginx/conf/
[root@Zabbix-Apache conf]# cat nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
    location / {
        root   html;
        index  index.php index.html index.htm;
    }
    location = /nginx-status {   #在nginx的配置文件中,添加status配置
                stub_status on;
                access_log off;
                allow 127.0.0.1;
                allow 192.168.200.89;     #zabbix服務器地址通常是Zabbix_Server地址
                deny all;
        }
    location ~ \.php$ {
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
[root@Zabbix-Apache conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@Zabbix-Apache conf]# /usr/local/nginx/sbin/nginx 
[root@Zabbix-Apache conf]# netstat -antup | grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1279/nginx

####3.2.3訪問設置好的nginx-status連接(以前已配好,這只是模版)

#在zabbix-server上經過以下方式獲取nginx狀態頁面信息:
[root@Zabbix-Server ~]# curl 192.168.200.91/nginx-status
Active connections: 1 
server accepts handled requests
 15 15 15 
Reading: 0 Writing: 1 Waiting: 0

nginx status詳細說明以下:
Active connections:對後端發起的活動鏈接數;
accepts:nginx總共處理了多少個鏈接;
handled:nginx成功建立了幾回握手;
requests:nginx總共處理了多少請求。
Reading:nginx讀取客戶端的header數;
Writing:nginx返回給客戶端的header數;
Waiting:nginx請求處理完成,正在等待下一請求指令的鏈接

####3.2.4 在Zabbix-Apache端編寫nginx狀態監控腳本

[root@Zabbix-Apache ~]# cd /etc/zabbix/scripts/
[root@Zabbix-Apache scripts]# cat nginx_status.sh 
#!/bin/bash
# Set Variables

HOST="127.0.0.1"
PORT="80"

#Functions to return nginx stats

function active(){
    /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null | grep "Active" | awk '{print $NF}'
}

function reading(){
    /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null | grep "Reading" | awk '{print $2}'
}

function writing(){
    /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null | grep "Writing" | awk '{print $4}'
}

function accepts(){
    /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null | awk 'NR==3' | awk '{print $1}'
}

function handled(){
    /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null | awk 'NR==3' | awk '{print $2}'
}

function requests(){
    /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null | awk 'NR==3' | awk '{print $3}'
}

function ping(){
    /sbin/pidof nginx | wc -l
}

# Run the requested function

$1

####3.2.5 給腳本可執行權限而且受權

[root@Zabbix-Apache scripts]# chmod +x nginx_status.sh
[root@Zabbix-Apache scripts]# chown zabbix.zabbix nginx_status.sh

####3.2.6 在zabbix-Apache端配置nginx鍵值配置文件

[root@Zabbix-Apache ~]# cd /etc/zabbix/zabbix_agentd.d
[root@Zabbix-Apache zabbix_agentd.d]# cat nginx.conf 
UserParameter=nginx.active,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | grep "Active" | awk '{print $NF}'
UserParameter=nginx.status[*],/etc/zabbix/scripts/nginx_status.sh $1
[root@Zabbix-Apache zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent:                                [  OK  ]
Starting Zabbix agent:                                          [  OK  ]

####3.2.7 在zabbix-server端測試鍵值

[root@Zabbix-Server ~]# zabbix_get -s 192.168.200.91 -k "nginx.status[reading]" -p 10050
0
[root@Zabbix-Server ~]# zabbix_get -s 192.168.200.91 -k "nginx.status[active]" -p 10050
1
[root@Zabbix-Server ~]# zabbix_get -s 192.168.200.91 -k "nginx.status[reading]" -p 10050
0
[root@Zabbix-Server ~]# zabbix_get -s 192.168.200.91 -k "nginx.status[writing]" -p 10050
1
[root@Zabbix-Server ~]# zabbix_get -s 192.168.200.91 -k "nginx.status[ping]" -p 10050
1

####3.2.8 接下來咱們須要在Web端導入nginx監控模版 image_1cnvj6itm8pf8bao9q1b0s1v9k44.png-22.5kB

image_1cnvj72pm8tl1ups1b07o4e102n4h.png-55.3kB

image_1cnvj7ld41f561elpiuicsq18rm4u.png-41.3kB ####3.2.9 異常調試

若是Zabbix圖形界面一直沒有獲取到數據,能夠經過在zabbix server上執行zabbix_get手動測試: 
/usr/local/zabbix/bin/zabbix_get -s 192.168.200.91 -p 10050 -k "nginx.status[active]" 
若是獲取數據有問題,會給出相應提示,若是可以獲取到數據,那就沒問題了。

##4.Zabbix監控Tomcat操做實戰

zabbix監控tomcat,須要zabbix_server開啓java poller,zabbix_java開啓javaGateway,端口10052,Tomcat JMX開啓12345端口,提供性能數據。

數據獲取流程爲:java poller<-->javaGateway:10052<-->Tomcat:12345

image_1cnvkjkb11e0b14tn1uth1uou19kg19.png-89.3kB ###4.1 部署java環境jdk ####4.1.1 jdk的解壓安裝

[root@Zabbix-Tomcat yuanmabao]# pwd
/root/yuanmabao
[root@Zabbix-Tomcat yuanmabao]# tar xf jdk-8u60-linux-x64.tar.gz -C /usr/local/
[root@Zabbix-Tomcat yuanmabao]# ln -s /usr/local/jdk1.8.0_60 /usr/local/jdk

####4.1.2 配置java環境變量

[root@Zabbix-Tomcat yuanmabao]# sed -i.ori '$a export JAVA_HOME=/usr/local/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar' /etc/profile

[root@Zabbix-Tomcat yuanmabao]# tail -3 /etc/profile
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

####4.1.3 讓java環境變量馬上生效

[root@Zabbix-Tomcat yuanmabao]# source /etc/profile

####4.1.4 檢查java環境安裝狀況

[root@Zabbix-Tomcat yuanmabao]# source /etc/profile
[root@Zabbix-Tomcat yuanmabao]# which java
/usr/local/jdk/bin/java
[root@Zabbix-Tomcat yuanmabao]# java -version   #出現如下信息表示部署成功
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

###4.2 安裝Tomcat ####4.2.1 解壓安裝Tomcat

[root@Zabbix-Tomcat yuanmabao]# pwd
/root/yuanmabao
[root@Zabbix-Tomcat yuanmabao]# tar xf apache-tomcat-8.0.27.tar.gz -C /usr/local/
[root@Zabbix-Tomcat yuanmabao]# ln -s /usr/local/apache-tomcat-8.0.27/ /usr/local/tomcat

####4.2.2 配置Tomcat環境變量

[root@Zabbix-Tomcat yuanmabao]# echo 'export TOMCAT_HOME=/usr/local/tomcat' >> /etc/profile
[root@Zabbix-Tomcat yuanmabao]# source /etc/profile

####4.2.3 對jdk及Tomcat安裝目錄遞歸受權root

[root@Zabbix-Tomcat yuanmabao]# chown -R root.root /usr/local/jdk/ /usr/local/tomcat/
[root@Zabbix-Tomcat yuanmabao]# ll -d /usr/local/jdk/ /usr/local/tomcat/
drwxr-xr-x. 8 root root 4096 Aug  5  2015 /usr/local/jdk/
drwxr-xr-x. 9 root root 4096 Sep 22 01:56 /usr/local/tomcat/

####4.2.4 檢查環境變量配置狀況

[root@Zabbix-Tomcat yuanmabao]# tail -4 /etc/profile
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
export TOMCAT_HOME=/usr/local/tomcat

###4.3 啓動Tomcat 啓動程序:/usr/local/tomcat/bin/startup.sh 關閉程序:/usr/local/tomcat/bin/shutdown.sh

[root@Zabbix-Tomcat yuanmabao]# cd 
[root@Zabbix-Tomcat ~]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/jdk
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

[root@Zabbix-Tomcat ~]# netstat -antup | grep java
tcp        0      0 :::8080                     :::*                        LISTEN      1365/java           
tcp        0      0 ::ffff:127.0.0.1:8005       :::*                        LISTEN      1365/java           
tcp        0      0 :::8009                     :::*                        LISTEN      1365/java

###4.4 訪問網站192.168.200.92:8080(注意要關閉防火牆) ###4.5 Zabbix-Tomcat端的agent安裝

[root@Zabbix-Tomcate ~]# wget http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-agent-3.2.4-1.el6.x86_64.rpm
[root@Zabbix-Tomcat ~]# rpm -ivh zabbix-agent-3.2.4-1.el6.x86_64.rpm
[root@Zabbix-Tomcat ~]# cd /etc/zabbix/
[root@Zabbix-Tomcat zabbix]# cat -n zabbix_agentd.conf | sed -n '13p;32p;95p;103p;120p;136p;147p;265p;284p'
    13  PidFile=/var/run/zabbix/zabbix_agentd.pid
    32  LogFile=/var/log/zabbix/zabbix_agentd.log
    95  Server=192.168.200.89     #這裏要取消本地
   103  ListenPort=10050
   120  StartAgents=3
   136  ServerActive=192.168.200.89:10051
   147  Hostname=192.168.200.92
#這裏要修改爲本身的名字,好比:主機IP
   265  Include=/etc/zabbix/zabbix_agentd.d/
   284  UnsafeUserParameters=1
[root@Zabbix-Tomcat /]# setenforce 0
[root@Zabbix-Tomcat /]# /etc/init.d/zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]
[root@Zabbix-Tomcat /]# netstat -antup | grep zabbix_agent
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      53511/zabbix_agentd 
tcp        0      0 :::10050                    :::*                        LISTEN      53511/zabbix_agentd

###4.6 配置Tomcat JMX

#配置jmx,在須要監控的tomcat服務器上,編輯catalina.sh,加入以下配置
[root@Zabbix-Tomcat ~]# sed -n '249p' /usr/local/tomcat/bin/catalina.sh
CATALINA_OPTS="-server -Xms256m -Xmx512m -XX:PermSize=64M -XX:MaxPermSize=128m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.200.92 -Dcom.sun.management.jmxremote.port=12345"

這裏須要注意,必須增長-Djava.rmi.server.hostname選項,而且後面的IP就是tomcat服務器的IP ###4.7 重啓Tomcat

[root@Zabbix-Tomcat ~]# /usr/local/tomcat/bin/shutdown.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/jdk
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@Zabbix-Tomcat ~]# netstat -antup | grep java
[root@Zabbix-Tomcat ~]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/jdk
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

[root@Zabbix-Tomcat ~]# netstat -antup | grep java
tcp        0      0 :::8080                     :::*                        LISTEN      2135/java           
tcp        0      0 ::ffff:127.0.0.1:8005       :::*                        LISTEN      2135/java           
tcp        0      0 :::8009                     :::*                        LISTEN      2135/java

###4.8 在zabbix-server端編譯zabbix,加入java支持

在zabbix server服務器上,編譯安裝zabbix-server,須要加上--enable-java,以支持jmx監控,若是以前的zabbix server沒加此選項,那麼須要從新編譯安裝,編譯參數以下:

./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy --enable-java --with-libxml2

特別提示:在啓用--enable-java編譯zabbix以前,zabbix server服務器上須要安裝JDK,並須要設置JAVA_HOME,以讓系統可以識別到jdk的路徑 ####4.8.1 在zabbix-server端安裝JDK (1) jdk的解壓安裝

[root@Zabbix-Server yuanmabao]# pwd
/root/yuanmabao
[root@Zabbix-Server yuanmabao]# tar xf jdk-8u60-linux-x64.tar.gz -C /usr/local/
[root@Zabbix-Server yuanmabao]# ln -s /usr/local/jdk1.8.0_60/ /usr/local/jdk

(2) 配置java環境變量

[root@Zabbix-Server yuanmabao]# sed -i.ori '$a export JAVA_HOME=/usr/local/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar' /etc/profile

[root@Zabbix-Server yuanmabao]# tail -3 /etc/profile
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

(3) 讓java環境變量馬上生效

[root@Zabbix-Server yuanmabao]# source /etc/profile

(4) 檢查java環境安裝狀況

[root@Zabbix-Server yuanmabao]# which java
/usr/local/jdk/bin/java
[root@Zabbix-Server yuanmabao]# java -version   #出現如下信息表示部署成功
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

####4.8.2 從新編譯zabbix-server服務器端 (1) 從新編譯zabbix-server服務器端以前

[root@Zabbix-Server ~]# ll /usr/local/zabbix/sbin/
total 8596
-rwxr-xr-x. 1 root root 1165774 Sep 20 21:23 zabbix_agentd
-rwxr-xr-x. 1 root root 3668935 Sep 20 21:23 zabbix_proxy
-rwxr-xr-x. 1 root root 3962949 Sep 20 21:23 zabbix_server

(2) 開始從新編譯zabbix-server服務器端

[root@Zabbix-Server ~]# /etc/init.d/zabbix_server stop
Shutting down zabbix_server:                               [  OK  ]
[root@Zabbix-Server ~]# cd /usr/src/zabbix-3.2.4/
[root@Zabbix-Server zabbix-3.2.4]# ./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy --enable-java --with-libxml2 && make && make install
#如下省略。。。

(3) 從新編譯zabbix-server服務器端以後

[root@Zabbix-Server zabbix-3.2.4]# cd /usr/local/zabbix/sbin/
[root@Zabbix-Server sbin]# ll
total 8600
-rwxr-xr-x. 1 root root 1165774 Sep 22 03:38 zabbix_agentd
drwxr-xr-x. 4 root root    4096 Sep 22 03:38 zabbix_java    #多了一個目錄
-rwxr-xr-x. 1 root root 3668935 Sep 22 03:38 zabbix_proxy
-rwxr-xr-x. 1 root root 3962949 Sep 22 03:38 zabbix_server

[root@Zabbix-Server sbin]# cd zabbix_java/
[root@Zabbix-Server zabbix_java]# ll
total 20
drwxr-xr-x. 2 root root 4096 Sep 22 03:38 bin
drwxr-xr-x. 2 root root 4096 Sep 22 03:38 lib
-rw-r--r--. 1 root root  791 Sep 22 03:38 settings.sh   #java gateway配置腳本
-rwxr-xr-x. 1 root root  545 Sep 22 03:38 shutdown.sh   #中止java gateway服務
-rwxr-xr-x. 1 root root 2025 Sep 22 03:38 startup.sh    #啓動java gateway服務

提示:java gateway服務的配置腳本settings.sh不須要修改任何配置。 ####4.8.3 啓動java Gateway服務

[root@Zabbix-Server zabbix_java]# /usr/local/zabbix/sbin/zabbix_java/startup.sh
[root@Zabbix-Server zabbix_java]# netstat -antup | grep 10052
tcp        0      0 :::10052                    :::*                        LISTEN      20838/java

###4.9 修改zabbix server 配置

默認的狀況下,zabbix server未啓用javaPollers,須要修改zabbix_server.conf的以下配置

#修改如下配置文件的內容
[root@Zabbix-Server zabbix_java]# cd /usr/local/zabbix/etc/
[root@Zabbix-Server etc]# cat -n zabbix_server.conf | sed -n '215p;223p;231p'
   215	JavaGateway=127.0.0.1
   223	JavaGatewayPort=10052
   231	StartJavaPollers=5

###4.10 重啓zabbix_server服務並查看已打開的java poller進程

[root@Zabbix-Server zabbix_java]# /etc/init.d/zabbix_server start
Starting zabbix_server:                                    [  OK  ]
[root@Zabbix-Server zabbix_java]# netstat -antup | grep 10051
tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      21053/zabbix_server 
tcp        0      0 192.168.200.89:10051        192.168.200.91:52212        TIME_WAIT   -    

#查看已經打開的java poller進程
[root@Zabbix-Server zabbix_java]#  ps -ef | grep "java poller" | grep -v grep
zabbix    21110  21053  0 03:55 ?        00:00:00 /usr/local/sbin/zabbix_server: java poller #1 [got 0 values in 0.000012 sec, idle 5 sec]
zabbix    21117  21053  0 03:55 ?        00:00:00 /usr/local/sbin/zabbix_server: java poller #2 [got 0 values in 0.000009 sec, idle 5 sec]
zabbix    21118  21053  0 03:55 ?        00:00:00 /usr/local/sbin/zabbix_server: java poller #3 [got 0 values in 0.000005 sec, idle 5 sec]
zabbix    21119  21053  0 03:55 ?        00:00:00 /usr/local/sbin/zabbix_server: java poller #4 [got 0 values in 0.000005 sec, idle 5 sec]
zabbix    21120  21053  0 03:55 ?        00:00:00 /usr/local/sbin/zabbix_server: java poller #5 [got 0 values in 0.000009 sec, idle 5 sec]

###4.11 Zabbix圖形界面配置 ####4.11.1 建立一個主機利用JMX接口監控tomcat被監控端 image_1cnvrj7ja1e5rp6dsl187312a11m.png-27.3kB

image_1co01akuoheu1r221qg1meq1fjqm.png-46.8kB

image_1cnvrq576kr21j2t16qj1rig1ds840.png-30.3kB ####4.11.2 導入zabbix監控tomcat的模版

由於Zabbix自帶的Tomcat模版有兼容性問題,並很差用,所以,咱們導入本身製做的監控項模版

image_1cnvrtaft1mc05p8ak145o1jl84q.png-26.5kB

image_1cnvrv00jpnvgpp156k1vcl8r557.png-41.2kB

image_1cnvs0fu8cs51f861qlv14jvcsl5k.png-58.5kB

image_1cnvs28jl1rvc1uknvqh7tv8p71.png-43.8kB

image_1cnvs3ev31iis191stv2v2b2pl7e.png-34.5kB ####4.11.3 最後咱們關聯模版便可 image_1cnvs6jj51hakdt08ro76u9967r.png-47.9kB

image_1cnvs7c301tabsdqgul1i9tvqc88.png-25.2kB

image_1cnvs9id1v778qh1esourkff18l.png-31.5kB

image_1co00r1sp12q01apkd8k1f10192p9.png-63.1kB ##5.Zabbix監控PHP-FPM操做實戰

php-fpm和nginx同樣內建了一個狀態頁,對於想了解php-fpm的狀態以及監控php-fpm很是有幫助 ###5.1 啓用php-fpm狀態功能 修改php-fpm配置文件,確保以下配置是打開狀態: pm.status_path = /status,具體操做以下

#在Zabbix-server端操做以下
[root@Zabbix-Server ~]# cd /usr/local/php/etc
[root@Zabbix-Server etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php.ini
[root@Zabbix-Server etc]# sed -n '360p' php-fpm.conf
pm.status_path = /status
#重啓php-fpm服務
[root@Zabbix-Server etc]# netstat -antup | grep php-fpm
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      1604/php-fpm        
[root@Zabbix-Server etc]# pkill php-fpm
[root@Zabbix-Server etc]# netstat -antup | grep php-fpm
[root@Zabbix-Server etc]# /usr/local/php/sbin/php-fpm
[root@Zabbix-Server etc]# netstat -antup | grep php-fpm
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      23924/php-fpm

###5.2 nginx配置php-fpm狀態頁面

在nginx配置文件nginx.conf裏配置php狀態頁,操做以下

[root@Zabbix-Server ~]# cd /usr/local/nginx/conf/
[root@Zabbix-Server conf]# cat nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
    location / {
        root   html;
        index  index.php index.html index.htm;
    }
    location = /nginx-status {
                stub_status on;
                access_log off;
        }
    location = /status {        #添加此location
               include fastcgi_params;
               fastcgi_pass 127.0.0.1:9000;
               fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
	  }
    location ~ \.php$ {
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
#重啓動nginx服務
[root@Zabbix-Server conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@Zabbix-Server conf]# /usr/local/nginx/sbin/nginx -s reload

###5.3 狀態頁瀏覽器訪問測試

php-fpm狀態頁比較個性化的一個地方是它能夠帶參數,能夠帶的參數有json、xml、html,使用zabbix或者nagios監控能夠考慮使用xml或者默認方式。

image_1co020imi1fafgus114t1v1010591j.png-15.4kB

#具體含義說明以下
[root@Zabbix-Server conf]# curl 127.0.0.1/status
pool:                 www         #fpm進程池名稱,大多數爲www
process manager:      dynamic     #進程管理方式(static,dynamic or nodemand.dynamic)
start time:           22/Sep/2018:05:49:09 +0800     #啓動日期
start since:          557         #運行時長
accepted conn:        64          #當前FPM進程池接受的請求數
listen queue:         0           #請求等待隊列,若是值不是0,那麼要增長FPM的進程數
max listen queue:     0           #請求等待隊列最高的數量
listen queue len:     128         #socket等待隊列長度
idle processes:       1           #空閒進程數量
active processes:     1           #活躍進程數量
total processes:      2           #總進程數量
max active processes: 2           #最大的活躍進程數量(FPM啓動開始算)
max children reached: 0           #達到最大子進程的次數,若是值不爲0,那麼須要調高最大進程數
slow requests:        0           #當啓用了php-fpm的slow-log功能時,若是出現php-fpm慢請求這個計數器會增長,通常不當的MySQL查詢會觸發這個值

###5.4 其餘狀態參數顯示形式的數據(json,xml,html) ####5.4.1 以xml的格式輸出PHP-fpm狀態頁

[root@Zabbix-Server conf]# curl 127.0.0.1/status?xml
<?xml version="1.0" ?>
<status>
<pool>www</pool>
<process-manager>dynamic</process-manager>
<start-time>1537566549</start-time>
<start-since>1131</start-since>
<accepted-conn>137</accepted-conn>
<listen-queue>0</listen-queue>
<max-listen-queue>0</max-listen-queue>
<listen-queue-len>128</listen-queue-len>
<idle-processes>2</idle-processes>
<active-processes>1</active-processes>
<total-processes>3</total-processes>
<max-active-processes>2</max-active-processes>
<max-children-reached>0</max-children-reached>
<slow-requests>0</slow-requests>

####5.4.2 以json的格式輸出PHP-fpm的狀態頁

[root@Zabbix-Server conf]# curl 127.0.0.1/status?json
{"pool":"www","process manager":"dynamic","start time":1537566549,"start since":1159,"accepted conn":140,"listen queue":0,"max listen queue":0,"listen queue len":128,"idle processes":2,"active processes":1,"total processes":3,"max active processes":2,"max children reach

####5.4.3 以html的格式輸出PHP-fpm的狀態頁

[root@Zabbix-Server conf]# curl 127.0.0.1/status?html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>PHP-FPM Status Page</title></head>
<body>
<table>
<tr><th>pool</th><td>www</td></tr>
<tr><th>process manager</th><td>dynamic</td></tr>
<tr><th>start time</th><td>22/Sep/2018:05:49:09 +0800</td></tr>
<tr><th>start since</th><td>1318</td></tr>
<tr><th>accepted conn</th><td>159</td></tr>
<tr><th>listen queue</th><td>0</td></tr>
<tr><th>max listen queue</th><td>0</td></tr>
<tr><th>listen queue len</th><td>128</td></tr>
<tr><th>idle processes</th><td>2</td></tr>
<tr><th>active processes</th><td>1</td></tr>
<tr><th>total processes</th><td>3</td></tr>
<tr><th>max active processes</th><td>2</td></tr>
<tr><th>max children reached</th><td>0</td></tr>
<tr><th>slow requests</th><td>0</td></tr>
</table>

###5.5 在Zabbix-Server端修改agent配置 ####5.5.1 建立zabbix監控的agent端鍵值配置文件

[root@Zabbix-Server ~]# cd /etc/zabbix/zabbix_agentd.d/
[root@Zabbix-Server zabbix_agentd.d]# cat userparameter_php-fpm.conf 
UserParameter=php-fpm.status[*],/usr/bin/curl -s "http://127.0.0.1/status?xml" | grep "<$1>" | awk -F "[>|<]" '{print $$3}'
#這裏須要注意在腳本里若是寫成$3的話,腳本會認識是一個變量,所以咱們須要用$$3

####5.5.2 重啓動agent客戶端

[root@Zabbix-Server zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent:                                [  OK  ]
Starting Zabbix agent:                                          [  OK  ]
[root@Zabbix-Server zabbix_agentd.d]# netstat -antup | grep zabbix_agent
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      24658/zabbix_agentd 
tcp        0      0 :::10050                    :::*                        LISTEN      24658/zabbix_agentd

###5.6 進行鍵值配置文件測試

[root@Zabbix-Server zabbix_agentd.d]# zabbix_get -s 192.168.200.89 -p 10050 -k "php-fpm.status[process-manager]"
dynamic
[root@Zabbix-Server zabbix_agentd.d]# zabbix_get -s 192.168.200.89 -p 10050 -k "php-fpm.status[start-since]"
2183
[root@Zabbix-Server zabbix_agentd.d]# zabbix_get -s 192.168.200.89 -p 10050 -k "php-fpm.status[active-processes]"
1

###5.7 Zabbix圖形界面導入咱們的監控模版 image.png-26.8kB

image.png-43.6kB

image.png-55.7kB

image.png-41.5kB

image.png-24.6kB ##6. Zabbix的Web監測功能

Zabbix的Web監測功能,沒有任何依賴,不須要agent端,所有依賴於Server的主動監測

###6.1 利用Web監測,監測Server端的nginx首頁 image.png-91.5kB

image.png-51.8kB

image.png-44.3kB

image.png-23.9kB

image.png-29.1kB

image.png-26.8kB

image.png-56.4kB ###6.2 查看監控結果 image.png-34.2kB

相關文章
相關標籤/搜索