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 ...
随机推荐
- iPhone/iPad调整事件递交
UIKit 为应用程序提供了编程手段来简化事件处理或者完全关闭事件流.下面的列表总结了这些方法: 关闭触摸事件的递交. 缺省情况下,视图接收触摸事件,但是你可以设置它的userInteractionE ...
- Leetcode题目31.下一个排列(中等)
题目描述: 实现获取下一个排列的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列. 如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排列). 必须原地修改,只允许使用额外 ...
- 8 Linux 文件类型
Linux 系统中的文件是没有扩展名的. 1.通过 ls -l 文件名,看第一个字符判断文件类型: - 普通文件(文本文件.二进制文件.压缩文件.电影.图片等) d 目录文件 b 设备文件(块设 ...
- HearthBuddy卡牌无法识别
界面上无法识别,提示是 [Unidentified card ID :DAL_010][Unidentified card ID :DAL_415] Unidentified card ID :HER ...
- hadoop学习笔记以及遇到的坑整理(长期更新)
1.要看官方文档 http://hadoop.apache.org/docs/current/ 2.start-dfs.sh时提示rcmd: socket: Permission denied 解决方 ...
- koa 基础(二十六)数据库 与 art-template 模板 联动 --- 编辑数据、删除数据
1.通过 ObjectID 获取 _id 根目录/module/db.js /** * DB库 */ var MongoDB = require('mongodb'); var MongoClient ...
- 执行docker run命令时报错Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
一.解决办法: 修改host 二.步骤如下 2.1 安装dig工具 sudo apt-get install dnsutils -y (ubuntu下的安装方法) 2.2 找到registry-1. ...
- javascript字符串转数字
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- [java][转]安装ADT的时候,提示“Cannot complete the install because one or more required items could not be
今天在安装ADT的时候,提示“Cannot complete the install because one or more required items could not be found. S ...
- 【转】HBase shell命令与 scan 过滤器
Hbase 常用shell命令 https://www.cnblogs.com/i80386/p/4105423.html HBase基础之常用过滤器hbase shell操作 https://www ...