zabbix监控(四)监控全网服务器
监控全网服务器5.1 需求说明
实际需求:
公司已经有了100台服务器,现在需要使用zabbix全部监控起来。
5.2 规划方案
常规监控:cpu,内存,磁盘,网卡问题:怎样快速添加100台机器
方法1:使用克隆的方式
方法2:自动注册和自动发现
方法3:调用zabbix api接口curl 、python
开发自己的运维平台兼容zabbix的通道
服务监控,url监控等特殊监控:自定义监控
5.2.1 api接口使用(curl)
curl -i -X POST -H 'Content-Type:application/json' -d'{"jsonrpc": "2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"auth": null,"id":0}' "http://10.0.0.61/zabbix/api_jsonrpc.php"
curl -i -X POST -H 'Content-Type:application/json' -d'
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"hostid",
"host"
],
"selectInterfaces": [
"interfaceid",
"ip"
]
},
"id": 2,
"auth": "6a450a8fc3dce71fd310cfe338746578"
}' "http://10.0.0.61/zabbix/api_jsonrpc.php"
5.3 具体实施规划
5.3.1 硬件、系统、网络监控
所有集群节点(所有虚拟机)都监控上
交换机,路由器监控(简单方法:换成端口对应服务器网卡流量监控;标准方法:监控交换机的网卡)
snmp监控
5.3.2 应用服务监控
1. 监控备份服务器,简单方法是监控rsync端口,如果有其他更佳方案可以说明;
方法1:监控873端口net.tcp.port[,873]
方法2:模拟推送拉取文件
方法3:监控进程数
2. 监控NFS服务器,使用监控NFS进程来判断NFS服务器正常,如果有其他更佳方案可以说明;
方法1:端口(通过111的rpc端口获取nfs端口) net.tcp.port[,111]
方法2:showmount -e ip|wc -l
3. 监控MySQL服务器,简单方法监控mysql的3306端口,或者使用zabbix提供的Mysql模板,如果有其他更佳方案可以说明;
方法1:端口(通过3306的mysql端口) net.tcp.port[,3306]
方法2:mysql远程登录
方法3:使用zabbix agent自带的模板及key
4. 监控2台web服务器,简单方法监控80端口,如果有其他更佳方案可以说明;
方法1:端口(通过80的web端口) net.tcp.port[,80]
方法2:看网页状态码、返回内容==zabbix 自带WEB检测
5. 监控URL地址来更精确的监控我们的网站运行正常;
使用zabbix自带的监控Web监测 进行监控
6. 监控反向代理服务器,PPTP服务器等你在期中架构部署的服务。
nginx,pptp
ntp 端口udp 123
7. 监控Nginx的7种连接状态。
自定义监控
5.3.3 监控服务通用方法
1. 监控端口 netstat ss lsof==》 wc -l
2. 监控进程 ps -ef|grep 进程|wc -l试运行一下
3. 模拟客户端的使用方式监控服务端
web==》 curl
mysql ==》 select insert
memcache ==》 set再get
5.4 实施全网监控
安装客户端脚本,for centos6
#!/bin/bash
#设置解析
# echo '10.0.0.1 mirrors.aliyuncs.commirrors.aliyun.comrepo.zabbix.com' >> /etc/hosts
#安装zabbix源、aliyu nYUM源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
yum clean all
yum clean all
#安装zabbix客户端
yum install zabbix-agent -y
sed -i.ori 's#Server=127.0.0.1#Server=172.16.1.61#' /etc/zabbix/zabbix_agentd.conf
/etc/init.d/zabbix-agent start
#写入开机自启动
chmod +x /etc/rc.d/rc.local
cat >>/etc/rc.d/rc.local /application/nginx/html/www/check.html
测试监控面页
# for ip in 7 8 9 ;do curl 10.0.0.$ip/check.html ;doneok
ok
ok
创建web监测模板
创建应用集
http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif
http://s1.运维网.com/images/20180320/1521558687276175.png
创建Web场景
http://s1.运维网.com/images/20180320/1521558689110899.png
创建图形 http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif
http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gifhttp://s1.运维网.com/images/20180320/1521558696997292.png
将模板关联到主机
http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif
http://s1.运维网.com/images/20180320/1521558707998885.png
监测结果
http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gifhttp://s1.运维网.com/images/20180320/1521558714544404.png
5.4.7 监控反向代理服务器
创建自定义key
# cat /etc/zabbix/zabbix_agentd.d/userparameter_nk.conf
UserParameter=keep-ip,ip a |grep 10.0.0.3|wc -l
在服务端测试
# zabbix_get -s 172.16.1.5 -p 10050 -k "keep-ip"
1
~]# zabbix_get -s 172.16.1.6 -p 10050 -k "keep-ip"
0
在web界面添加模板
http://s1.运维网.com/images/20180320/1521558795629259.png http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif
将模板关联到主机
http://s1.运维网.com/images/20180320/1521558801890061.png
5.4.8 监控Nginx的7种连接状态 http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif
nginx服务器显示status
……
location /status {
stub_status on;
access_log off;
}
……
# for ip in 7 8;do curl 172.16.1.$ip/status ;done
Active connections: 1
server accepts handled requests
73 73 69
Reading: 0 Writing: 1 Waiting: 0
Active connections: 1
server accepts handled requests
134 134 127
Reading: 0 Writing: 1 Waiting: 0
在nginx服务器上添加key
cat >/etc/zabbix/zabbix_agentd.d/userparameter_nginx_status.conf自动发现 >> Local network
使用自带的自动发现规则(进行修改)即可
http://s1.运维网.com/images/20180320/1521558932732334.png
在ip范围内输入ip,注意格式; http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif
延迟在实际的生产环境中要大一些(1h-2h),实验环境可以小一些60s
http://s1.运维网.com/images/20180320/1521558943852714.png
http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif
创建发现动作
配置 >> 动作 >> Auto discovery. Linux servers.
http://s1.运维网.com/images/20180320/1521558995977353.png
http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif
①配置动作
http://s1.运维网.com/images/20180320/1521559022506467.png
② 在条件中添加条件,让添加更准确(条件保持不变,D不需要添加) http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif
http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif
http://s1.运维网.com/images/20180320/1521559033607794.png
③在操作中添加
a)添加主机与启用主机
http://blog.运维网.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif
http://s1.运维网.com/images/20180320/1521559047526844.png
然后等待者客户端自动上门就好
小伙伴们可以关注我的微信公众号:linux运维菜鸟之旅
http://image.135editor.com/files/users/342/3423179/201802/UNTxFr9s_b7qF.jpg
关注“中国电信天津网厅”公众号,首次绑定可免费领2G流量,为你的学习提供流量!
http://image.135editor.com/files/users/342/3423179/201802/kd4HfE4U_EIDs.jpg
页:
[1]