Zabbix 监控常见服务
监控Apache性能
1.客户端编译安装Apache服务,并在编译选项中开启监控页面功能.
[root@localhost ~]# yum install -y gcc openssl openssl-devel zlib zlib-devel pcre pcre-devel expat-devel libxml2-devel
2.安装Apr-1.6.3,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库.
[root@localhost ~]# wget http://www-eu.apache.org/dist//apr/apr-1.6.3.tar.gz
[root@localhost ~]# tar -xzvf apr-1.6.3.tar.gz
[root@localhost ~]# cd apr-1.6.3/
[root@localhost ~]# CC="gcc -m64" ./configure --prefix=/usr/local/apr
[root@localhost ~]# ./configure --prefix=/usr/local/apr
[root@localhost ~]# make && make install
3.安装Apr-util-1.6.1,是包含了一些常用的开发组件,这些组件与apache的关系更加密切一些,比如存储段和存储段组,加密等.
[root@localhost ~]# wget http://www-eu.apache.org/dist//apr/apr-util-1.6.1.tar.gz
[root@localhost ~]# tar -xzvf apr-util-1.6.1.tar.gz
[root@localhost ~]# cd apr-util-1.6.1/
[root@localhost ~]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost ~]# make && make install
4.安装Apache-2.4.33
[root@localhost ~]# wget http://www-eu.apache.org/dist//httpd/httpd-2.4.33.tar.gz
[root@localhost ~]# tar -xzvf httpd-2.4.33.tar.gz
[root@localhost ~]# cd httpd-2.4.33/
[root@localhost ~]# ./configure --prefix=/usr/local/apache2 \
--enable-rewrite \
--enable-so \
--enable-headers \
--enable-expires \
--with-mpm=worker \
--enable-modules=most \
--enable-deflate \
--enable-ssl \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-pcre=/usr/local/pcre
[root@localhost ~]# make && make install
5.编辑apache配置文件开启状态页面功能.
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
140 LoadModule status_module modules/mod_status.so
473 # Real-time info on requests and configuration
474 Include conf/extra/httpd-info.conf
[root@localhost ~]# vim /usr/local/apache2/conf/extra/httpd-info.conf
12 # Change the ".example.com" to match your domain to enable.
13
14 <Location /server-status>
15 SetHandler server-status
16 Order deny,allow
17 Allow from all
18 </Location>
6.重启Apache,并测试相应页面是否启动了.
[root@localhost ~]# /usr/local/apache2/bin/httpd -k restart
[root@localhost ~]# curl http://localhost/server-status
7.下载zpache模板并解压,设置相应的权限,放入监控目录里即可.
[root@localhost ~]# wget https://github.com/lorf/zapache/archive/master.zip
[root@localhost ~]# unzip master.zip
[root@localhost ~]# cd zapache-master/
[root@localhost ~]# cp -a zapache /etc/zapache.sh
[root@localhost ~]# chmod 777 -R /etc/zapache.sh
8.修改客户端的配置文件,写入一个监控字段.修改下路径指定一下脚本保存位置.
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
UserParameter=zapache[*],/etc/zapache.sh \$1
[root@localhost ~]# systemctl restart zabbix-agent
9.Zabbix服务端配置
模板 -> 导入 -> 选取文件 -> 导入,然后添加一个模板主机,即可实现监控了.
## 监控Nginx性能
1.配置Yum仓库,安装Nginx所依赖的包文件,以及编译器.
[root@localhost ~]# yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
2.编译安装Nginx,在编译过程中制定开启状态页--with-http_stub_status_module
.
[root@localhost ~]# useradd -s /sbin/nologin -M nginx
[root@localhost ~]# wget http://nginx.org/download/nginx-1.13.12.tar.gz
[root@localhost ~]# tar -xzvf nginx-1.13.12.tar.gz
[root@localhost ~]# cd nginx-1.13.12/
[root@localhost ~]# ./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_stub_status_module
[root@localhost ~]# make && make install
3.检查Nginx配置文件正确性,启动关闭与重启Nginx配置.
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t #检测配置文件正确性
[root@localhost ~]# /usr/local/nginx/sbin/nginx #启动Nginx
4.编译时开启Nginx的状态统计,并在Nginx主配置文件中加入以下内容.
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
19 location / {
20 root html;
21 index index.html index.htm;
22 }
#===============================================
24 location /lyshark { #添加以下字段,开启统计页面.
25
26 stub_status on;
27 access_log off;
28 allow 127.0.0.1;
29 }
#===============================================
31 error_page 500 502 503 504 /50x.html;
32 location = /50x.html {
33 root html;
34 }
5.在客户机上创建监控脚本,并配置好相应的权限.
[root@localhost ~]# vim /etc/nginx_status.sh
#!/bin/bash
HOST="127.0.0.1"
PORT="80"
WEB="lyshark"
function ping {
/sbin/pidof nginx | wc -l
}
function active {
/usr/bin/curl "http://$HOST:$PORT/$WEB/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
/usr/bin/curl "http://$HOST:$PORT/$WEB/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
/usr/bin/curl "http://$HOST:$PORT/$WEB/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
/usr/bin/curl "http://$HOST:$PORT/$WEB/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
function accepts {
/usr/bin/curl "http://$HOST:$PORT/$WEB/" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled {
/usr/bin/curl "http://$HOST:$PORT/$WEB/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
/usr/bin/curl "http://$HOST:$PORT/$WEB/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
case $1 in
"ping") ping ;;
"active") active ;;
"reading") reading ;;
"writing") writing ;;
"waiting") waiting ;;
"accepts") accepts ;;
"handled") handled ;;
"requests") requests ;;
*)
echo "Usage: $0 { ping |active | accepts | handled | requests | reading | writing | waiting }" ;;
esac
[root@localhost ~]# chmod 755 -R /etc/nginx_status.sh
6.将自定义的UserParameter加入配置文件,然后重启agentd.
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=nginx.status[*],/etc/nginx_status.sh \$1
[root@localhost ~]# systemctl restart zabbix-agent
7.服务端使用zabbix_get获取数据,并在web页面导入模板即可.
[root@localhost ~]# yum install -y zabbix-get
[root@localhost ~]# zabbix_get -s 192.168.1.10 -k "nginx.status[ping]"
模板下载:http://www.ttlsa.com/wp-content/uploads/2015/10/zabbix_monitor_nginx_template_ttlsa_com.zip
配置 -> 模板 -> 导入 -> 导入模板 -> 选择Nginx模板文件 -> 导入
配置 -> 主机 -> 模板 -> 链接模板 -> 选择 -> Template App NGINX ->添加 -> 更新
## Zabbix监控MariaDB
1.首先在被控主机上,通过Yum方式安装一个MariaDB数据库.
[root@localhost ~]# yum install -y mariadb mariadb-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package 1:mariadb-5.5.60-1.el7_5.x86_64 already installed and latest version
Package 1:mariadb-server-5.5.60-1.el7_5.x86_64 already installed and latest version
Nothing to do
2.配置数据库的一个guest的用户,用来监控状态.
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# systemctl enable mariadb
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
MariaDB [(none)]> grant select on *.* to guest@localhost identified by "guest";
Query OK, 0 rows affected (0.00 sec)
3.配置一个MariaDB脚本文件用来获取用户信息.
[root@localhost ~]# vim /etc/mysql_status.sh
#!/bin/bash
MYSQL_USER="guest"
MYSQL_PWD="guest"
MYSQL_HOST="localhost"
MYSQL_PORT="3306"
# 数据连接
MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
# 参数是否正确
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_queries)
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_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)"
;;
esac
4.将自定义的UserParameter加入配置文件,然后重启agentd
[root@localhost ~]# chmod 755 -R /etc/mysql_status.sh
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=mysql.status[*],/etc/mysql_status.sh \$1
[root@localhost ~]# rm -fr /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
[root@localhost ~]# systemctl restart zabbix-agent
5.服务端使用zabbix_get获取数据,并在Web主机配置好模板.
[root@localhost ~]# yum install -y zabbix-get
[root@localhost ~]# zabbix_get -s 192.168.1.10 -k "mysql.status[Uptime]"
配置 -> 主机 -> 模板 -> 链接模板 -> 选择 -> Template DB MySQL ->添加 -> 更新
Zabbix 监控常见服务的更多相关文章
- zabbix监控memcached服务
zabbix监控memcached服务 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装并配置memcached服务 1>.使用yum方式安装memcached [ro ...
- Zabbix监控虚拟机服务-告警与自动恢复-模板化
上一篇文章测试了服务的告警与自动恢复:Zabbix监控虚拟机服务-告警与自动恢复 但是我是直接为某一个主机增加的监控项和触发器, 如果要让某一个自定义的监控项和触发器被很多机器共用,则需要创建模板 1 ...
- 使用Zabbix监控ZooKeeper服务的健康状态
一 应用场景描述 在目前公司的业务中,没有太多使用ZooKeeper作为协同服务的场景.但是我们将使用Codis作为Redis的集群部署方案,Codis依赖ZooKeeper来存储配置信息.所以做好Z ...
- 【zabbix告警监控】配置zabbix监控nginx服务
zabbix监控nginx,nginx需要添加--with-http_stub_status模块 使用zabbix监控nginx,首先nginx需要配置开启ngx_status.但是我这边nginx安 ...
- 使用Zabbix监控Nginx服务实战案例
使用Zabbix监控Nginx服务实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.编译安装nginx步骤详解并开启状态页 博主推荐阅读: https://www.cn ...
- Zabbix监控虚拟机服务-告警与自动恢复
今天稍微空闲,使用下zabbix的5.0版本,目前生产环境是4.x版本 今天就只实现一个目的:监控任意一个服务(示例中监控的是docker.service),如果服务挂了,自动给恢复,先看一个动图 搭 ...
- 使用Zabbix监控rabbitmq服务
添加rabbitmq脚本 [root@controller rabbitmq]# cd /etc/zabbix/script/rabbitmq [root@controller rabbitmq]# ...
- 【zabbix监控】zabbix监控tomcat服务
服务器配置(zabbix_server) 1. 安装jdk 版本需要1.7以上,我这边安装的是1.8的,可以参考我jdk安装的文章 # 上传到zabbix_server服务端.安装(jdk-8u171 ...
- zabbix监控常见系统报错
CPU触发器:1)Processor load is too high on {HOST.NAME} {HOST.NAME}上处理器负载太高触发器表达式:{Zabbix server:system.c ...
随机推荐
- 邻居子系统 之 邻居项查找neigh_lookup、___neigh_lookup_noref
概述 邻居项查找是通过neigh_lookup相关函数来进行的: ___neigh_lookup_noref,该函数根据输出设备和主键值(IPv4为下一跳ip地址)在邻居项hash表中查找,找到则返回 ...
- Java 实现 2的次幂表示
问题描述 任何一个正整数都可以用2进制表示,例如:137的2进制表示为10001001. 将这种2进制表示写成2的次幂的和的形式,令次幂高的排在前面,可得到如下表达式:137=2^7+2^3+2^0 ...
- springboot拦截异常信息发送邮件提醒
-- private JavaMailSender sender; 可能会出现注入错误,请注意yam配置文件中格式是否一致:否则会找不到注入的bean 一 发送邮件 在Springboot中发送邮件非 ...
- legend3---lavarel多对多模型操作实例
legend3---lavarel多对多模型操作实例 一.总结 一句话总结: 在多对多模型中,增加关系表的数据 需要 弄一个和关系表一对多的模型关系 1.在lavarel关系模型中,课程和标签表是多对 ...
- While 循环 kotlin(11)
While 循环while 和 do .. while 照常使用 while (x > 0) { x--} do { val y = retrieveData()} while (y != nu ...
- Runtime 源码阅读
Runtime 属性说明 /** * 每一个 Java 应用程序都有一个关联的运行时对象 * * @author unascribed * @see java.lang.Runtime#getRunt ...
- Proxmox
vmware: vmware 12 pro proxmox 下载地址 往下会比较麻烦一点,这里就不做展示了(仅供参考)
- XML字符串和 java对象项目转换
这是之前写,仅供参考(如果缺少jar包可以私信我,CSDN现在下载的东西太费了,动不动就要积分,开源精神所剩无几了,也没办法都需要吃饭,可以理解) import javax.xml.bind.JAXB ...
- SOA简介
1.你可以把SOA理解为一种概念,总的来说就是面向服务的设计. 这个概念简单来理解就是把之前所谓的模块划分做成服务. 比如之前的日志模块,需要引用你的dll,调用你的写日志方法来写日志.这样当有多个系 ...
- golang(09) golang 接口内部实现
原文链接 http://www.limerence2017.com/2019/09/24/golang14/#more 前文介绍过golang interface用法,本文详细剖析interface内 ...