1. 程式人生 > 其它 >|NO.Z.00042|——————————|^^ 構建 ^^|——|Zabbix3.2構建.V3|--------------------------------------|2臺server|

|NO.Z.00042|——————————|^^ 構建 ^^|——|Zabbix3.2構建.V3|--------------------------------------|2臺server|



[Applications:Zabbix3.2構建.V3]                                                                       [Applications.LBC&HAC$HPC] [|監控叢集|監控zabbix3.2版本|web初始化設定|中文亂碼|監控本機|zabbix-agent|] [自動發現|nginx併發監控|釘釘告警|2臺server|]








一、監控本機服務
### --- 新增客戶端

[root@server11 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=10.10.10.11                                                          // 伺服器端地址
# ListenPort=10050                                                          // 使用的是tcp的10050埠
ServerActive=10.10.10.11
Hostname=10.10.10.11                                                        // 本機地址,或者可解析的主機名
[root@server11 ~]# systemctl start zabbix-agent
[root@server11 ~]# systemctl enable zabbix-agent

[root@server11 ~]# netstat -antp |grep :10050                               // 監聽狀態,並且是在zabbix把它啟用的。
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      12849/zabbix_agentd 
tcp6       0      0 :::10050                :::*                    LISTEN      12849/zabbix_agentd 
二、在控制頁面把它新增監控上。
### --- 新增主機

~~~     配置——>主機——>建立主機——>主機名稱:zabbix-server(必須英文)
~~~     ——>可見名稱:zabbix伺服器——>群組:Zabbix servers
~~~     ——>agent代理程式的介面:IP地址:10.10.10.11(若是域名需新增DNS伺服器);埠:10050——>
~~~     模本——>連結指示器:
~~~     選擇:Template APP HTTP Service;Template ICMP Ping;Template OS Linux——>新增——>
~~~     主機——>新增——>END
三、新增監控主機/自動發現,nginx併發監控
1、新增監控主機
### --- 在HAserver2:10.10.10.12下原始碼編譯安裝Nginx伺服器並開啟狀態統計模組
### --- 將zabbix-agent-3.2.1-1.el7.x86_64.rpm上傳至伺服器並安裝zabbix-agent.rpm包

[root@serve12 ~]# yum install -y zabbix-agent-3.2.1-1.el7.x86_64.rpm
[root@serve12 ~]# systemctl restart httpd
[root@serve12 ~]# echo "this is zabbix-agent 10.10.10.12" >> /var/www/html/index.html
[root@serve12 ~]# curl localhost
this is zabbix-agent 10.10.10.12
### --- zabbix客戶端配置

[root@serve12 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=10.10.10.11
ServerActive=10.10.10.11
Hostname=10.10.10.12
 
[root@serve12 ~]# systemctl start zabbix-agent.service 
[root@serve12 ~]# systemctl enable zabbix-agent.service 
[root@serve12 ~]# netstat -anpt |grep :10050
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      9731/zabbix_agentd  
tcp6       0      0 :::10050                :::*                    LISTEN      9731/zabbix_agentd  
### --- 在監控控制頁面新增
2、新增主機
### --- 新增主機

~~~     配置——>主機——>建立主機——>主機名稱:zabbix-server(必須英文)
~~~     ——>可見名稱:zabbix伺服器——>群組:Apache
~~~     ——>agent代理程式的介面:IP地址:10.10.10.12(若是域名需新增DNS伺服器);埠:10050——>
~~~     模本——>連結指示器:
~~~     選擇:Template APP HTTP Service;Template ICMP Ping;Template OS Linux——>新增——>
~~~     主機——>新增——>END

一、zabbix監控nginx端伺服器
### --- zabbix客戶端配置
### --- 在HAserver2:10.10.10.12下原始碼編譯安裝Nginx伺服器並開啟狀態統計模組

[root@serve12 ~]# systemctl stop httpd.service                              // 同時佔用80埠,衝突,所以關閉
~~~     將nginx-1.2.6.tar.gz上傳至伺服器

[root@serve12 nginx-1.2.6]# useradd -s /sbin/nologin -M nginx
[root@serve12 ~]# tar -zxvf nginx-1.2.6.tar.gz 
[root@serve12 ~]# cd nginx-1.2.6/
[root@serve12 nginx-1.2.6]# yum install -y pcre pcre-devel zlib zlib-devel 
[root@serve12 nginx-1.2.6]# ./configure --help |grep status
  --with-http_stub_status_module                                            // 查詢狀態統計模組


[root@serve12 nginx-1.2.6]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@serve12 nginx-1.2.6]# make && make install
### --- 寫入網站並啟動nginx

[root@serve12 nginx-1.2.6]# echo "this is HA server2:10.10.10.12 nginx zabbix-agent-web" >> /usr/local/nginx/html/index.html 
[root@serve12 nginx-1.2.6]# /usr/local/nginx/sbin/nginx 
[root@serve12 nginx-1.2.6]# curl localhost
this is HA server2:10.10.10.12 nginx zabbix-agent-web
### --- 修改nginx配置檔案,啟用監控功能;並重載nginx

[root@serve12 ~]# vim /usr/local/nginx/conf/nginx.conf
        location / {
            root   html;
            index  index.html index.htm;                                    // 預設不需更改
        }
        location /nginx-status{                                             // 新增該內容,啟用監控功能
                stub_status on;
        }
[root@serve12 ~]# /usr/local/nginx/sbin/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@serve12 ~]# kill -HUP $( cat /usr/local/nginx/logs/nginx.pid)         // 過載一下nginx
二、通過Chrome訪問:http://10.10.10.12/nginx-status檢視當前的連線狀態
### --- 編寫nginx監控指令碼,在被監控端
~~~     :$s/ngx_status/nginx-status/g                                   // 替換全部內容為nginx-status;共替換了7行

#!/bin/bash

HOST="127.0.0.1"
PORT="80"

#檢測nginx程序是否存在
function ping {
        /sbin/pidof nginx | wc -l
}
#檢測nginx效能
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 waiting {
    /usr/bin/curl "http://$HOST:#PORT/nginx-status/" 2>/dev/null| grep 'Waiting' | awk' {print $6}'
}
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
$1 
### --- 為指令碼賦予可執行許可權,並測試指令碼可否執行

[root@serve12 ~]# chmod a+x nginx-status.sh 
[root@serve12 ~]# bash nginx-status.sh active
1
### --- 在HA  server13下寫入一個迴圈,讓其一直訪問10.10.10.12下的nginx主頁

[root@server13 ~]# while 2>1                                                // 無限迴圈訪問
do
curl 10.10.10.12
done

[root@server13 ~]# while 2>1 ; do curl 10.10.10.12                          // 1s訪問一次;比無限迴圈慢一點
sleep 1s
done
### --- 在HA server12下檢視訪問狀態及當前的請求數。

[root@serve12 ~]# bash nginx-status.sh requests
7443
~~~     開啟授權自定義指令碼的監控。
[root@serve12 ~]# mv nginx-status.sh /etc/zabbix/zabbix_agentd.d/

[root@serve12 ~]# vim /etc/zabbix/zabbix_agentd.conf
UnsafeUserParameters=1                                                              //1表示開啟自定義指令碼監控
UserParameter=nginx.status[*],/etc/zabbix/zabbix_agentd.d/nginx-status.sh $1        //格式:第一個指定的key,就是調取的函式名稱
[root@serve12 ~]# systemctl restart zabbix-agent.service
[root@serve12 ~]# /etc/zabbix/zabbix_agentd.d/nginx-status.sh requests
102549
### --- 此刻雖然授權到了,但是不知道zabbix-agent和指令碼進行互動監控待測試
~~~     說明客戶端已經通過指令碼的形式檢測到指令碼的值了。
### --- 下列在Chrome下配置效能監控匯入效能指令碼的方式檢測。

[root@server11 ~]# yum install -y zabbix-get
[root@server11 ~]# zabbix_get -s 10.10.10.12 -k 'nginx.status[requests]'
151099                                                      
[root@serve12 ~]# /etc/zabbix/zabbix_agentd.d/nginx-status.sh requests
150100  
三、為了讓效能能夠引入的話,需要匯入效能指令碼
### --- 為了讓效能能夠引入的話,需要匯入效能指令碼

~~~     配置——>模板——>匯入:模板:zbx_export_templates.xml——>匯入成功後再點選模板NGINX
~~~     ——>下拉顯示:Template App NGINX——>監控項:會顯示一些列的監控列表:包括觸發器
~~~     ——>配置——>主機——>建立主機——>主機名稱:nginx-1
~~~     ——>可見名稱:nginx伺服器——>新建群組:nginx——>地址:10.10.10.12——>埠:10050
~~~     ——>模板:Template App NGINX,Template ICMPPing,Template OS Linux——>新增
~~~     ——>主機:新增——>END

四、zabbix監控web場景,聚合圖形
1、新增一個新的web場景的功能
### --- 新增一個新的web場景的功能

~~~     配置——>主機——>nginx-1伺服器——>應用集——>建立應用集——>名稱:http-code:新增
~~~     ——>web場景:建立web場景——>名稱:http-code——>應用集:http-code
~~~     ——>客戶端:Chrome 38.0(Windows)——>
~~~     步驟——>新增——>名稱:http-code
~~~     ——>URL:http://10.10.10.12/test.html(建議大家新建一個測試網頁:測試方案一)
~~~     ——>要求的狀態碼:200——>新增——>
~~~     認證——>無
~~~     主機——>新增——>END

### --- 新增一個新的web場景的功能

~~~     觸發器——>建立觸發器——>名稱:web場景檢測異常!!!
~~~     ——>嚴重性:嚴重——>表示式:新增:監控項:Response code for step “http-code" of scenario ”http-code“
~~~     ——>功能:最新 的T值不是N——>N:200——>插入——>
~~~     表示式:{nginx-1:web.test.in[http-code,http-code,bps].time(0)}<>200 and  {nginx-1:web.test.in[http-code,http-code,bps].time(1)}<>200 and  {nginx-1:web.test.in[http-code,http-code,bps].time(2)}<>200 
~~~     ——> 新增——>點選觸發器檢視:——>END
2、測試test網頁是否執行正常:
### --- 測試test網頁是否執行正常:

[root@serve12 ~]# rm -rf /usr/local/nginx/html/test.html刪除測試頁面          // 告警出現,嚴重警告
[root@serve12 ~]# echo "this is HA-server12:10.10.10.12 web-test " >>/usr/local/nginx/html/test.html
[root@serve12 ~]# curl localhost/test.html                                  // 重新新增頁面。恢復正常
this is HA-server12:10.10.10.12 web-test        
3、測試方案一:
### --- 測試方案一:

[root@serve12 ~]# echo "this is HA-server12:10.10.10.12 web-test " >>/usr/local/nginx/html/test.html
[root@serve12 ~]# curl localhost/test.html
this is HA-server12:10.10.10.12 web-test
五、通過Chrome訪問:http://10.10.10.12/test.html
### --- ——>zabbix聚合圖形,繪製圖形;放置公司比較重要的監控資訊<——

### --- 檢測中——>聚合圖形——>建立聚合圖形——>名稱:重要資訊——>新增
### --- ——>重要資訊——>編輯聚合圖形——>更改——>圖形:選擇:CPU load——>新增:時間——>END








===============================END===============================


Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart                                                                                                                                                    ——W.S.Landor



來自為知筆記(Wiz)