|NO.Z.00042|——————————|^^ 构建 ^^|——|Zabbix3.2构建.V3|——|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

 
 
 
 
 
 
 
 
 

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

 

 

posted on   yanqi_vip  阅读(6)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示