Zabbix监控 -----云告警,监控tomcat,电脑远程控制服务器,主被动切换,zabbix-proxy

一:云告警

1:进入云告警官网注册用户

2:实现虚拟机钥匙虚拟机能够上网

主机;
[root@foundation36 Desktop]#  iptables -t nat -I POSTROUTING -s 172.25.36.0/24 -j MASQUERADE        ##使虚拟机上网

3:检测:ping百度看是否能够ping通

[root@server1 ~]# ping baidu.com   ##检测
PING baidu.com (123.125.115.110) 56(84) bytes of data.
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=1 ttl=49 time=61.3 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=2 ttl=49 time=74.5 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=3 ttl=49 time=40.8 ms
^C
--- baidu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 40.866/58.932/74.573/13.870 ms

4:安装插件(获取脚本目录)

[root@server1 ~]# cd /usr/lib/zabbix/alertscripts/
[root@server1 alertscripts]# pwd
/usr/lib/zabbix/alertscripts
[root@server1 alertscripts]# ls
oneitsm_zabbix_release-1.2.0.tar.gz
[root@server1 alertscripts]# tar axf oneitsm_zabbix_release-1.2.0.tar.gz   ##解压压缩包
[root@server1 alertscripts]# ls
oneitsm  oneitsm_zabbix_release-1.2.0.tar.gz

5:执行脚本,需要获取应用的key值(在云告警服务平台的应用里可以获取),安装

[root@server1 alertscripts]# cd oneitsm
[root@server1 oneitsm]# ls
bin  logs  release  update
[root@server1 bin]# ./install.sh fd32785a-2491-a8d3-15e2-eebe7bb0a0   ##云报警,zabbix应用key值
start to create config file...
Zabbix管理地址: http://172.25.36.1/zabbix
Zabbix管理员账号: Admin
Zabbix管理员密码: (zabbix)
start to auth by zabbix admin user and password...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:100   195  100    70  100   125   1237   2209 --:--:-- --:--:-- --:--:--  2232
auth success!
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:100   109  100    41  100    68   1077   1787 --:--:-- --:--:-- --:--:--  1837
start to create mediatype...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:100   356  100    56  100   300   1067   5717 --:--:-- --:--:-- --:--:--  5769
create media type success!
start to create user group...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:100   214  100    54  100   160    965   2859 --:--:-- --:--:-- --:--:--  2909
create user group success!
start to create user in zabbix...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:100   623  100    51  100   572    812   9115 --:--:-- --:--:-- --:--:--  9225
create user success!
start to create action...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:100  2013  100    51  100  1962    517  19927 --:--:-- --:--:-- --:100  2013  100    51  100  1962    517  19916 --:--:-- --:--:-- --:--:-- 19818
create action success!
安装成功.

4:zabbix web界面配置服务

5:云告警服务平台配置

微信关注公众号,当服务出现问题后,微信公众号也会受到消息

(1)添加zabbix应用:

(2)添加通知策略:

绑定微信公众号:

6:云告警平台搭建完成 测试:

关闭server3的zabbix-agent服务(此时显示红色表示服务关闭成功)

在仪表盘处可以查看到具体的处理的进度:

此时云告警平台已经收到邮件,并且微信公众号也收到了消息:

然后认领,将问题解决了,就显示已关闭而不是待处理状态

开启server3上zabbix-agent服务:

二:zabbix监控tomcat

server2安装tomcat

1:安装插件

[root@server2 ~]# rpm -ivh jdk-8u121-linux-x64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk1.8.0_121-2000:1.8.0_121-fcs  ################################# [100%]
Unpacking JAR files...
	tools.jar...
	plugin.jar...
	javaws.jar...
	deploy.jar...
	rt.jar...
	jsse.jar...
	charsets.jar...
	localedata.jar...

2:解压tomcat包到/usr/local目录下

[root@server2 ~]# tar zxf apache-tomcat-8.5.24.tar.gz -C /usr/local/
[root@server2 ~]# cd /usr/local/
[root@server2 local]# ls
apache-tomcat-8.5.24  etc    include  lib64    sbin   src
bin                   games  lib      libexec  share

3:做软连接方便开启服务

[root@server2 local]# ln -s apache-tomcat-8.5.24/ tomcat

4:修改配置文件,指定端口为8888

[root@server2 tomcat]# cd bin/
[root@server2 bin]# vim catalina.sh 

CATALINA_OPTS='-Dcom.sun.management.jmxremote
  -Dcom.sun.management.jmxremote.port=8888
  -Dcom.sun.management.jmxremote.ssl=false
  -Dcom.sun.management.jmxremote.authenticate=false'

5:开启服务,查看端口:

[root@server2 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@server2 bin]# netstat -antlp
tcp6       0      0 :::8888                 :::*                    LISTEN      4318/java   

6:server1上安装java网关:

[root@server1 4.0]# yum install -y zabbix-java-gateway-4.0.5-1.el7.x86_64.rpm 

7:开启服务,查看端口:

[root@server1 4.0]# cd /etc/zabbix/
[root@server1 zabbix]# ls
web                 zabbix_agentd.d           zabbix_java_gateway_logback.xml
zabbix_agentd.conf  zabbix_java_gateway.conf  zabbix_server.conf
[root@server1 zabbix]# systemctl start zabbix-java-gateway
[root@server1 zabbix]# netstat -antlp | grep :10052
tcp6       0      0 :::10052                :::*                    LISTEN      20001/java          

8:修改配置文件(指定java网关(设定的就是本机),端口,java线程数)

[root@server1 zabbix]# vim zabbix_server.conf 
JavaGateway=172.25.36.1
JavaGatewayPort=10052
StartJavaPollers=5

9:重新登录:

[root@server1 zabbix]# zabbix_server -R config_cache_reload
zabbix_server [20303]: command sent successfully

然后在zabbix server端进行检测(配置模版等)

10:zabbix web界面设置

重新开启服务(也可以之前的那一步就直接重新开启服务而不是重新登录)

此时就实现了zabbix监控tomcat

三:电脑远程控制服务器

四:主被动切换

这样是为了减轻server端的压力,让agent来主动找server端。

(1)配置模板(serever2):

下面选择更新

修改配置文件:


被动模式(默认)

#Server=172.25.36.1
#StartAgents=5


主动模式(server上模版设置了被动)
Server=172.25.36.1
StartAgents=5

改为全被动的模式,此时查看端口:

一会之后端口没有了:

此时发现zabbix端的server2服务出问题了


注意:

因为server2上有些模板就不能设置成被动的,此时再修改server2上的配置文件,

设置成主动的,将注释去除,词汇严格意义上来说,此时是一种主动被动都存在的

情况,server端能被动的走被动,必须主动的走主动,此时也能够降低server端的压力

修改配置文件:

server=172.25.36.1

重新开启服务,查看端口:

删除之前的模块,换上那个克隆来的设置成客户端主动的模块

此时刷新一下,对server2的监控正常

五:zabbix-proxy

设置代理服务器,用于监控不同网段的主机

server主机能和proxy主机通信,proxy主机能和agent主机通信

1:删除之前的server3主机,让server3充当proxy
2:修改server3的主机名为proxy,关闭之前的zabbix-proxy服务
[root@server3 ~]# hostnamectl set-hostname proxy
[root@server3 ~]# hostname
proxy
[root@server3 ~]# systemctl stop zabbix-agent
3:server1 server2 server3 真机 添加本地解析
4:在server1 zabbix中添加agent代理
5:传给proxy安装包
[root@server1 4.0]# scp zabbix-proxy-mysql-4.0.5-1.el7.x86_64.rpm proxy:
The authenticity of host 'proxy (172.25.36.3)' can't be established.
ECDSA key fingerprint is 06:c5:2c:34:02:a6:58:e9:54:c2:92:40:d9:14:50:85.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'proxy' (ECDSA) to the list of known hosts.
root@proxy's password: 
zabbix-proxy-mysql-4.0.5-1.el7.x86_64.rpm          100%  737KB 737.4KB/s   00:00    
[root@server1 4.0]# scp fping-3.10-1.el7.x86_64.rpm proxy:
root@proxy's password: 
fping-3.10-1.el7.x86_64.rpm                        100%   40KB  40.3KB/s   00:00  

6:proxy(server3)安装软件
[root@server3 ~]# yum install zabbix-proxy-mysql-4.0.5-1.el7.x86_64.rpm fping-3.10-1.el7.x86_64.rpm -y

7:安装数据库
[root@server3 ~]# yum install -y mariadb-server -y
8:开启数据库,建库,给权限
[root@server3 ~]# systemctl start mariadb
[root@server3 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> create database zabbix_proxy character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on zabbix_proxy.* to zabbix@localhost identified by 'westos';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> Bye

9:给数据库导入数据:
[root@server3 ~]# cd /usr/share/doc/
[root@server3 doc]# cd zabbix-proxy-mysql-4.0.5/
[root@server3 zabbix-proxy-mysql-4.0.5]# ls

AUTHORS  ChangeLog  COPYING  NEWS  README  schema.sql.gz
[root@server3 zabbix-proxy-mysql-4.0.5]# zcat schema.sql.gz | mysql zabbix_proxy
10:进入数据库,查看
[root@server3 zabbix-proxy-mysql-4.0.5]# mysql -u zabbix -p zabbix_pro
xy
Enter password: 
MariaDB [zabbix_proxy]> show tables;
11:修改配置文件:
[root@server3 zabbix-proxy-mysql-4.0.5]# cd /etc/zabbix/
[root@server3 zabbix]# vim zabbix_proxy.conf 
===================
Server=172.25.36.1
ServerPort=10051
Hostname=proxy
DBName=zabbix_proxy
DBUser=zabbix
DBPassword=westos
JavaGateway=172.25.36.1
JavaGatewayPort=10052
StartJavaPollers=5

===================
12:开启服务
[root@server3 zabbix]# systemctl start zabbix-proxy
[root@server3 zabbix]# netstat -antlp | grep :10051
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      9200/zabbix_proxy   
tcp        0      0 172.25.36.3:52224       172.25.36.1:10051       TIME_WAIT   -                   
tcp6       0      0 :::10051                :::*                    LISTEN      9200/zabbix_proxy   
13:server1上,查看日志
[root@server1 4.0]# cat /var/log/zabbix/zabbix_server.log
 6427:20190310:030935.356 sending configuration data to proxy "proxy" at "172.25.36.3", datalen 3511
14:proxy上查看日志
[root@server3 zabbix]# cat /var/log/zabbix/zabbix_proxy.log 
15:修改server2的配置文件
[root@server2 bin]# vim /etc/zabbix/zabbix_agentd.conf 
将server2上的server指定为proxy
=============================
ServerActive=172.25.36.3
Server=172.25.36.3

=============================

16:浏览器上,选中server2下面的proxy,此时会发现zbx和jmx变绿了  ##server2位proxy
17:重启server1 server2 proxy(server3)上的服务,并查看日志,直到没有报错就可以
[root@server1 4.0]# zabbix_server -R config_cache_reload
zabbix_server [9338]: command sent successfully
[root@server1 4.0]# cat /var/log/zabbix/zabbix_server.log

[root@server2 bin]# systemctl restart zabbix-agent

[root@server3 zabbix]# systemctl restart zabbix-proxy


猜你喜欢

转载自blog.csdn.net/yinzhen_boke_0321/article/details/88550937