利用zabbix搭建分布式监控(nginx,percona,apache-tomcat)

**由于不想博客篇幅太长,本实验是在zabbix已经安装配置好的基础上开始做的:
基础实验配置请参考:https://mp.csdn.net/mdeditor/81736380**
关于企业6和企业7虚拟机的封装可以参考:https://blog.csdn.net/aaaaaab_/article/details/81712766**
结合nginx搭建zabbix监控:

实验环境:server3:  172.25.38.3  agent端  企业6
     loaclhost: 172.25.38.11      企业7
     server2:   172.25.38.2  proxy端  企业6
     最后的代理实验就是agent-->proxy-->localhost

在企业6版本的server3,:
关于企业6企业7版本虚拟机的封装可以查看https://blog.csdn.net/aaaaaab_/article/details/81712766

[root@server3 ~]# ls
mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz
zabbix-agent-3.4.6-1.el6.x86_64.rpm
[root@server3 ~]# ls
mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz
nginx-1.8.0-1.el6.ngx.x86_64.rpm
zabbix-agent-3.4.6-1.el6.x86_64.rpm
[root@server3 ~]# rpm -ivh nginx-1.8.0-1.el6.ngx.x86_64.rpm   安装nginx
warning: nginx-1.8.0-1.el6.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing...                ########################################### [100%]
   1:nginx                  ########################################### [100%]
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

----------------------------------------------------------------------

这里写图片描述

[root@server3 ~]# pwd
/root
[root@server3 ~]# ls
mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz
nginx-1.8.0-1.el6.ngx.x86_64.rpm
zabbix-agent-3.4.6-1.el6.x86_64.rpm
[root@server3 ~]# cd /etc/nginx/
[root@server3 nginx]# ls
conf.d          koi-utf  mime.types  scgi_params   win-utf
fastcgi_params  koi-win  nginx.conf  uwsgi_params
[root@server3 nginx]# cd conf.d/
[root@server3 conf.d]# ls
default.conf  example_ssl.conf
[root@server3 conf.d]# cd ..
[root@server3 nginx]# cd -
/etc/nginx/conf.d
[root@server3 conf.d]# ls
default.conf  example_ssl.conf
[root@server3 conf.d]# vim default.conf   加入一个location

这里写图片描述
这里写图片描述

[root@server3 conf.d]# nginx -t  检测nginx语法
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@server3 conf.d]# nginx 启动nginx
[root@server3 conf.d]# nginx -s reload 重载服务

这里写图片描述
在网页测试可以查看到状态:
这里写图片描述
添加访问黑白名单,为了安全性:

[root@server3 conf.d]# vim default.conf   加入允许访问的主机,拒绝所有,即只有127.0.0.1可以访问
[root@server3 conf.d]# nginx -s reload   重载服务生效

这里写图片描述
用其他主机(企业7版本的localhost主机)测试无法访问:

[root@localhost ~]# curl -s http://172.25.38.3/status
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.8.0</center>
</body>
</html>
[root@localhost ~]# 

这里写图片描述
用server3访问测试黑白名单:

[root@server3 conf.d]# curl -s http://127.0.0.1/status  127.0.0.1可以访问
Active connections: 1 
server accepts handled requests
 327 327 338 
Reading: 0 Writing: 1 Waiting: 0 
[root@server3 conf.d]# curl -s http://172.25.38.3/status   本机IP都无法调用访问
<html> 
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.8.0</center>
</body>
</html>

这里写图片描述
利用正则表达式取出各个状态值:

[root@server3 conf.d]# curl -s http://127.0.0.1/status | grep Active | awk '{print $3}' 过滤active行打印第三列
1
[root@server3 conf.d]# curl -s http://127.0.0.1/status | grep Active | awk '{print $NF}'  NF也代表最后一列效果相同
1
[root@server3 conf.d]# cd /etc/zabbix/
[root@server3 zabbix]# ls
zabbix_agentd.conf  zabbix_agentd.d
[root@server3 zabbix]# cd zabbix_agentd.d/
[root@server3 zabbix_agentd.d]# ls
userparameter_mysql.conf
[root@server3 zabbix_agentd.d]# cp userparameter_mysql.conf userparameter_nginx.conf 
[root@server3 zabbix_agentd.d]# vim userparameter_nginx.conf 
[root@server3 zabbix_agentd.d]# cat userparameter_nginx.conf 
UserParameter=nginx.active,curl -s http://127.0.0.1/status | grep Active | awk '{print $3}'
[root@server3 zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent:                                [FAILED]
Starting Zabbix agent:                                     [  OK  ]
[root@server3 zabbix_agentd.d]# /etc/init.d/zabbix-agent restart   重启服务
Shutting down Zabbix agent:                                [  OK  ]
Starting Zabbix agent:                                     [  OK  ]

这里写图片描述
同理取出其他状态值进行绘制监控图形:

[root@server3 zabbix_agentd.d]# curl -s http://127.0.0.1/status |awk NR==3 | awk '{print $2}'
24    取出NR=3代表第三行,$2代表第二列
[root@server3 zabbix_agentd.d]# curl -s http://127.0.0.1/status |awk NR==3 | awk '{print $3}'
35
[root@server3 zabbix_agentd.d]# curl -s http://127.0.0.1/status |awk NR==3 | awk '{print $1}'
26
[root@server3 zabbix_agentd.d]# ls
userparameter_mysql.conf  userparameter_nginx.conf
[root@server3 zabbix_agentd.d]# vim userparameter_nginx.conf 
[root@server3 zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent:                                [  OK  ]
Starting Zabbix agent:                                     [  OK  ]
[root@server3 zabbix_agentd.d]# cat userparameter_nginx.conf    添加到配置文件,nginx.active这个是键值,得与监控图形中一一对应
UserParameter=nginx.active,curl -s http://127.0.0.1/status | grep Active | awk '{print $3}'
UserParameter=nginx1.active,curl -s http://127.0.0.1/status |awk NR==3 | awk '{print $1}'
UserParameter=nginx2.active,curl -s http://127.0.0.1/status |awk NR==3 | awk '{print $2}'
UserParameter=nginx3.active,curl -s http://127.0.0.1/status |awk NR==3 | awk '{print $3}'

这里写图片描述
在企业7版本虚拟机开启服务:

[root@localhost ~]# systemctl start mariadb   开启数据库
[root@localhost ~]# systemctl enable mariadb   开机自动启动可以防止我们掉电启动之后出现服务忘记开启的情况
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# systemctl start zabbix-server  开启zabbix-server
\[root@localhost ~]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@localhost ~]# zabbix_get -s 172.25.38.3 -p 10050 -k 'nginx.active'  可以获取到servr3的状态值
1
[root@localhost ~]# systemctl start httpd  开启阿帕其
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# zabbix_get -s 172.25.38.3 -p 10050 -k 'nginx1.active'
72
[root@localhost ~]# zabbix_get -s 172.25.38.3 -p 10050 -k 'nginx2.active'
73
[root@localhost ~]# zabbix_get -s 172.25.38.3 -p 10050 -k 'nginx3.active'
84

这里写图片描述
在网页添加监控项添加图形:
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
结合percona进行zabbix的监控:

Percona Server为 MySQL 数据库服务器进行了改进,在功能和性能上较 MySQL 有着很显著的提升。
该版本提升了在高负载情况下的 InnoDB 的性能、为 DBA 提供一些非常有用的性能诊断工具;另外有
更多的参数和命令来控制服务器行为。

实验部署:

[root@localhost ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm  安装percona-zabbix安装包
[root@localhost ~]# cd /var/lib/zabbix/percona/templates/
[root@localhost templates]# ls
userparameter_percona_mysql.conf
zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml
[root@localhost templates]# cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
[root@localhost templates]# cd /etc/zabbix/zabbix_agentd.d/
[root@localhost zabbix_agentd.d]# ls
userparameter_mysql.conf  userparameter_percona_mysql.conf
[root@localhost zabbix_agentd.d]# systemctl restart zabbix-agent
[root@localhost zabbix_agentd.d]# ls
userparameter_mysql.conf  userparameter_percona_mysql.conf

这里写图片描述

[root@localhost zabbix_agentd.d]# cd -
/var/lib/zabbix/percona/templates
[root@localhost templates]# cd /var/lib/zabbix/
[root@localhost zabbix]# ls
percona
[root@localhost zabbix]# cd 
[root@localhost ~]# cd -
/var/lib/zabbix
[root@localhost zabbix]# cd percona/
[root@localhost percona]# ls
scripts  templates
[root@localhost percona]# cd scripts/
[root@localhost scripts]# ls
get_mysql_stats_wrapper.sh  ss_get_mysql_stats.php
[root@localhost scripts]# vim ss_get_mysql_stats.php 
[root@localhost scripts]# ls
get_mysql_stats_wrapper.sh  ss_get_mysql_stats.php
[root@localhost scripts]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf
[root@localhost scripts]# cat /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf
<?
$mysql_user = 'root';
$mysql_pass = 'westos'

这里写图片描述

[root@localhost scripts]# mysql -p  可以正常登陆数据库
MariaDB [(none)]> quit
Bye
[root@localhost scripts]# ls
get_mysql_stats_wrapper.sh  ss_get_mysql_stats.php  ss_get_mysql_stats.php.cnf
[root@localhost scripts]# cd /tmp/
[root@localhost tmp]# ls

这里写图片描述

[root@localhost ~]# vim ~zabbix/.my.cnf
[root@localhost ~]# cat ~zabbix/.my.cnf
[client]
user=root
password=westos
[root@localhost ~]# zabbix_get -s 127.0.0.1 -p 10050 -k 'MySQL.Threads-cached'

[root@localhost ~]# systemctl restart zabbix-agent  重启服务
[root@localhost ~]# netstat -antlp

这里写图片描述
在网页进行部署:
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
结合apache-tomcat部署zabbix监控:

[root@server3 ~]# ls
apache-tomcat-7.0.90.tar.gz                   nginx-1.8.0-1.el6.ngx.x86_64.rpm
jdk-8u121-linux-x64.rpm                       zabbix-agent-3.4.6-1.el6.x86_64.rpm
mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz
[root@server3 ~]# rpm -ivh jdk-8u121-linux-x64.rpm 先安装jdk
[root@server3 ~]# tar zxf apache-tomcat-7.0.90.tar.gz -C /usr/local/ 
[root@server3 ~]# cd /usr/local/

这里写图片描述

[root@server3 local]# ls
apache-tomcat-7.0.90  etc    include  lib64    mysql-proxy  share
bin                   games  lib      libexec  sbin         src
[root@server3 local]# ln -s apache-tomcat-7.0.90/ tomcat  制作软链接
[root@server3 local]# cd
[root@server3 ~]# cd /usr/local/tomcat/
[root@server3 tomcat]# ls
bin           conf             lib      logs    README.md      RUNNING.txt  webapps
BUILDING.txt  CONTRIBUTING.md  LICENSE  NOTICE  RELEASE-NOTES  temp         work
[root@server3 tomcat]# bin/startup.sh   开启服务
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@server3 bin]# netstat -antlp |grep :8080  过滤8080端口
tcp        0      0 :::8080                     :::*                        LISTEN      11101/java          
tcp        0      0 ::ffff:127.0.0.1:8080       ::ffff:127.0.0.1:53405      TIME_WAIT   -   

这里写图片描述

[root@server3 tomcat]# cd bin/
[root@server3 bin]# ls
bootstrap.jar                 configtest.bat    setclasspath.sh  tomcat-native.tar.gz
catalina.bat                  configtest.sh     shutdown.bat     tool-wrapper.bat
catalina.sh                   daemon.sh         shutdown.sh      tool-wrapper.sh
catalina-tasks.xml            digest.bat        startup.bat      version.bat
commons-daemon.jar            digest.sh         startup.sh       version.sh
commons-daemon-native.tar.gz  setclasspath.bat  tomcat-juli.jar
[root@server3 bin]# vim catalina.sh 写入端口

这里写图片描述

[root@server3 bin]# vim catalina.sh 
[root@server3 bin]# ./shutdown.sh   先关闭服务
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@server3 bin]# ./startup.sh   打开服务
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@server3 bin]# netstat -antlp |grep :8888 可以看到8888
tcp        0      0 :::8888                     :::*                        LISTEN      12243/java          

这里写图片描述
在企业7的虚拟机进行配置:

[root@localhost ~]# ls
apache-tomcat-7.0.90.tar.gz                  zabbix-agent-3.4.6-1.el7.x86_64.rpm
fping-3.10-1.el7.x86_64.rpm                  zabbix-get-3.4.6-1.el7.x86_64.rpm
iksemel-1.4-2.el7.centos.x86_64.rpm          zabbix-java-gateway-3.4.6-1.el7.x86_64.rpm
jdk-8u121-linux-x64.rpm                      zabbix-proxy-mysql-3.4.6-1.el7.x86_64.rpm
percona-zabbix-templates-1.1.8-1.noarch.rpm  zabbix-server-mysql-3.4.6-1.el7.x86_64.rpm
php-bcmath-5.4.16-42.el7.x86_64.rpm          zabbix-web-3.4.6-1.el7.noarch.rpm
php-mbstring-5.4.16-42.el7.x86_64.rpm        zabbix-web-mysql-3.4.6-1.el7.noarch.rpm
[root@localhost ~]# rpm -ivh zabbix-java-gateway-3.4.6-1.el7.x86_64.rpm 
[root@localhost ~]# cd /etc/zabbix/
[root@localhost zabbix]# ls
web                 zabbix_java_gateway.conf         zabbix_server.conf
zabbix_agentd.conf  zabbix_java_gateway_logback.xml
zabbix_agentd.d     zabbix_proxy.conf
[root@localhost zabbix]# vim zabbix_java_gateway.conf 

这里写图片描述

[root@localhost zabbix]# systemctl start zabbix-java-gateway
[root@localhost zabbix]# netstat -antlp| grep :10052  可以看到10052端口
tcp6       0      0 :::10052                :::*                    LISTEN      6999/java           
[root@localhost zabbix]# ls
web                 zabbix_java_gateway.conf         zabbix_server.conf
zabbix_agentd.conf  zabbix_java_gateway_logback.xml
zabbix_agentd.d     zabbix_proxy.conf
[root@localhost zabbix]# vim zabbix_server.conf 
[root@localhost zabbix]# systemctl restart zabbix-server  重启服务

这里写图片描述
在网页进行部署:
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值