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 ...
随机推荐
- MySQL_(Java)使用JDBC创建用户名和密码校验查询方法
MySQL_(Java)使用JDBC向数据库发起查询请求 传送门 MySQL数据库中的数据,数据库名garysql,表名garytb,数据库中存在的用户表 通过JDBC对MySQL中的数据用户名和密码 ...
- [JZOJ5400]:Repulsed(贪心+树形DP)
题目描述 小$w$心里的火焰就要被熄灭了. 简便起见,假设小$w$的内心是一棵$n-1$条边,$n$个节点的树. 现在你要在每个节点里放一些个灭火器,每个节点可以放任意多个. 接下来每个节点都要被分配 ...
- String.format保留小数位数
java保留小数--四舍五入--想保留几位就几位 String.format("%.nf",d);----表示保留N位!!!format("%.nf",doub ...
- Python中的OS对路径的操作以及应用
目录处理 OS目录处理目录-->路径,文件夹 文件:html 1. 新建和删除一个目录import os #引入os目录from xx import xxos.mkdir("D:\\P ...
- 【Java笔试】OYO校招Java工程师|牛客平台,算法:字符串翻转。附选择题解析
文章目录 1.Java笔试算法题:字符串翻转 2.单选题: 2.1.同一进程下的多个线程可以共享哪一种资源:data section 2.2.一个树形的叶结点在前序遍历和后序遍历下,可以相同的相对位置 ...
- leetcode-hard-array-454 4sum II-NO
mycode 过不了...我也不知道为什么... class Solution(object): def fourSumCount(self, A, B, C, D): ""& ...
- LC 711. Number of Distinct Islands II
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...
- Mysql密码忘记,修改密码方法
1.set password for ‘root’@’localhost’ = password(‘czllss’); -- czllss为新密码
- 五十一:数据库之Flask-Migrate详解
在实际开发中,经常会发生数据库修改行为,一般数据库修改不是直接手动修改,而是去修改ORM模型,然后再把模型映射到数据库中,这些操作可以通过flask-migrate实现,flask-migrate是基 ...
- 使用 QQ 邮箱发送邮件报错:java.net.SocketTimeoutException: Read timed out. Failed messages: javax.mail.MessagingException: Exception reading response
使用 QQ 邮箱发送邮件报错:java.net.SocketTimeoutException: Read timed out. Failed messages: javax.mail.Messagin ...