一、zabbix使用nginx做web服务器
yum nginx装好,默认的default.conf文件直接backup掉,新建一个zabbx.conf文件,
如果有报错看下nginx_log 日志排错。
1、安装nginx
[root@server1 ~]# cd /etc/nginx/
[root@server1 nginx]# ls
conf.d koi-utf mime.types scgi_params win-utf
fastcgi_params koi-win nginx.conf uwsgi_params
[root@server1 nginx]# cd conf.d/
[root@server1 conf.d]# ls
default.conf example_ssl.conf
[root@server1 conf.d]# vim default.conf
location /status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
[root@server1 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@server1 conf.d]# nginx
[root@server1 conf.d]# nginx -s reload
2、网页访问:
3、shell测试:
4、配置 zabbix nginx 文件 。
[root@server1 nginx]# cd /etc/zabbix/
[root@server1 zabbix]# ls
zabbix_agentd.conf zabbix_agentd.d
[root@server1 zabbix]# cd zabbix_agentd.d/
[root@server1 zabbix_agentd.d]# ls
userparameter_mysql.conf
[root@server1 zabbix_agentd.d]# cp userparameter_mysql.conf userparameter_nginx.conf
[root@server1 zabbix_agentd.d]# vim userparameter_nginx.conf
[root@server1 zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent: [FAILED]
Starting Zabbix agent: [ OK ]
5、 zabbix 主机 开启服务 :
[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
[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 ~]# systemctl start zabbix-agent
[root@localhost ~]# systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@server1 zabbix_agentd.d]# curl -s http://127.0.0.1/status | awk NR==3 | awk ''
[root@server1 zabbix_agentd.d]# curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $3}'
33
[root@server1 zabbix_agentd.d]# curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $1}'
29
[root@server1 zabbix_agentd.d]# curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $2}'
30
[root@server1 zabbix_agentd.d]# ls
userparameter_mysql.conf userparameter_nginx.conf
[root@server1 zabbix_agentd.d]# vim userparameter_nginx.conf
UserParameter=nginx.active,curl -s http://127.0.0.1/status | grep Active | awk '{print $NF}'
UserParameter=nginx.accepts,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $1}'
UserParameter=nginx.handled,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $2}'
UserParameter=nginx.requests,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $3}'
~
7、添加zabbix 文件配置
[root@localhost ~]# ls
anaconda-ks.cfg zabbix-get-3.4.6-1.el7.x86_64.rpm
fping-3.10-1.el7.x86_64.rpm zabbix-java-gateway-3.4.6-1.el7.x86_64.rpm
iksemel-1.4-2.el7.centos.x86_64.rpm zabbix-proxy-mysql-3.4.6-1.el7.x86_64.rpm
php-bcmath-5.4.16-42.el7.x86_64.rpm zabbix-server-mysql-3.4.6-1.el7.x86_64.rpm
php-mbstring-5.4.16-42.el7.x86_64.rpm zabbix-web-3.4.6-1.el7.noarch.rpm
zabbix-agent-3.4.6-1.el7.x86_64.rpm zabbix-web-mysql-3.4.6-1.el7.noarch.rpm
[root@localhost ~]# rpm -ivh zabbix-get-3.4.6-1.el7.x86_64.rpm
warning: zabbix-get-3.4.6-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
package zabbix-get-3.4.6-1.el7.x86_64 is already installed
[root@localhost ~]# zabbix_get -s 172.25.50.1 -p 10050 -k 'nginx.active'
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.50.1 -p 10050 -k 'nginx.requests'
49
[root@localhost ~]# zabbix_get -s 172.25.50.1 -p 10050 -k 'nginx.handled'
45
[root@localhost ~]# zabbix_get -s 172.25.50.1 -p 10050 -k 'nginx.accepts'
47
8、网页操作:
分别加入:nginx.accepts nginx.requests
在 nginx _ status 分别加入 以上三个监控项
浏览图形:
二、配置mysql
1、安装
[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]# vim userparameter_percona_mysql.conf
[root@localhost zabbix_agentd.d]# systemctl restart zabbix-agent
[root@localhost zabbix_agentd.d]# 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]# cd /var/lib/zabbix/
[root@localhost zabbix]# ls
percona
[root@localhost zabbix]# cd
[root@localhost ~]# cd -
/var/lib/zabbix
[root@localhost zabbix]# cd percona/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]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
4
[root@localhost tmp]# cat localhost-mysql_cacti_stats.txt
[root@localhost tmp]# rm -fr localhost-mysql_cacti_stats.txt
2、测试:
zabbix_agentd 端口为 10050
[root@localhost zabbix]# zabbix_get -s 127.0.0.1 -p 10050 -k 'MySQL.Threads-cached'
0
[root@localhost ~]# vim ~zabbix/.my.cnf
[client]
user = root
password = westos
~
3、打开网页:
导入: zbx_percona_mysql_template.xml ,并对相应选项打钩
在 zabbix server 中,添加 mysql 模板 ,更新
我们可以清楚看到监控项已经到达 271 ,而且在模板部分,也可以看到我们所添加的模板
查看,在图形中选择mysql connections ,浏览图形
三、 Zabbix部署jmx监控tomcat
zabbix提供了一个java gateway的应用去监控jmx(Java Management Extensions,即Java管理扩展)是一个为应用程序、设备、系统等植入管理功能的框架。JMX可以跨越一系列异构操作系统平台、系统体系结构和网络传输协议,灵活的开发无缝集成的系统、网络和服务管理应用。
Zabbix 172.25.50.11
Java gateway 172.25.50.11
Tomcat 172.25.50.1
1、安装
[root@server1 ~]# cd /usr/local/
[root@server1 local]# ls
apache-tomcat-7.0.90 bin etc games include lib lib64 libexec sbin share src
[root@server1 local]# ln -s apache-tomcat-7.0.90/ tomcat
[root@server1 local]# cd tomcat/
[root@server1 tomcat]# ls
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work
[root@server1 tomcat]# cd bin/
[root@server1 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@server1 bin]# vim catalina.sh
文件内容:
CATALINA_OPTS='-Dcom.cun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8888
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false'
2、开启服务
[root@server1 bin]# vim catalina.sh
[root@server1 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@server1 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.
查看端口,可以看到 8888
3、网页访问 :http://tomcat.apache.org/
4、安装 zabbix-java-gateway
Java有了JMX,全称是Java Management Extensions,即Java管理扩展
[root@localhost ~]# yum install -y 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
tcp6 0 0 :::10052 :::* LISTEN 12023/java
[root@localhost zabbix]# vim zabbix_server.conf ##开启java接口
[root@localhost zabbix]# systemctl restart zabbix-server
5、网页添加JMX接口
添加JMX模板
添加成功
6、查看,稍等一会就会出现 JMX 变成 绿色
关机重启后会是红色,再次开启服务: agent 和 zabbix-java-geteway