一、Zabbix:API管理主机
1、获得令牌(zabbix主机:172.25.120.11)
[root@server7 ~]# vim zabbix-api
[root@server7 ~]# chmod +x zabbix-api
[root@server7 ~]# cat zabbix-api
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin", ##用户、密码
"password": "zabbix"
},
"id": 1,
"auth": null
}' http:
[root@server7 ~]# ./zabbix-api ##执行脚本,获取令牌
{
"id": 1,
"jsonrpc": "2.0",
"result": "e0ecfc8234c5176d36d9222f2208e540" ##令牌
}
2、删除监控主机(注意:停用自动发现和自动注册
[root@server7 ~]# vim zabbix-deleteapi
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.delete", ##执行的命令
"params": [
"10258" ##监控主机的hostid
],
"id": 1,
"auth": "85b6908b50b6919800987457cd234fdc" ##指定令牌
}' http:
[root@server7 ~]# chmod +x zabbix-deleteapi
[root@server7 ~]# ./zabbix-deleteapi ##执行脚本,删除主机
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"hostids": [
"10258"
]
}
}
3、获取监控主机信息
[root@server7 ~]# vim zabbix-getapi
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output":["host"] ##输出主机信息
},
"id": 1,
"auth": "85b6908b50b6919800987457cd234fdc" ##指定令牌
}' http:
[root@server7 ~]# chmod +x zabbix-getapi
[root@server7 ~]# ./zabbix-getapi ##执行脚本get信息
{
"id": 1,
"jsonrpc": "2.0",
"result": [
{
"host": "Zabbix server", ##get的host信息
"hostid": "10084"
}
]
}
4、创建新的监控主机
- groupid可以通过点击group,查看网址得到
[root@server7 ~]# vim zabbix-createapi
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "server2", ##新增的主机名
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "172.25.120.2", ##监控主机的IP
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "2" ##指定的groupid(Linux Server)
}
],
"templates": [
{
"templateid": "10001" ##指定的templateid(Template OS Linux)
}
],
"inventory_mode": 0,
"inventory": {
"macaddress_a": "01234",
"macaddress_b": "56768"
}
},
"id": 1,
"auth": "85b6908b50b6919800987457cd234fdc" ##指定令牌
}' http:
[root@server7 ~]# chmod +x zabbix-createapi
[root@server7-1 ~]# ./zabbix-createapi ##执行脚步,新增监控主机
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"hostids": [
"10259" ##新增的hostid:10259
]
}
}
二、监控tomcat
1、客户端(被监控主机)
[root@server2 ~]
[root@server2 ~]
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
2、配置tomcat
[root@server2 ~]
[root@server2 ~]
[root@server2 local]
[root@server2 local]
[root@server2 bin]
100 CATALINA_OPTS='-Dcom.sun.management.jmxremote
101 -Dcom.sun.management.jmxremote.port=8888
102 -Dcom.sun.management.jmxremote.ssl=false
103 -Dcom.sun.management.jmxremote.authenticate=false'
[root@server2 bin]
[root@server2 bin]
tcp 0 0 :::8888 :::* LISTEN 0 21874 3553/java
3、server端(zabbix主机)
[root@server7 ~]
[root@server7 zabbix]
262 JavaGateway=172.25.120.11
270 JavaGatewayPort=10052
278 StartJavaPollers=5
[root@server7 ~]
[root@server7 ~]
tcp6 0 0 :::10052 :::* LISTEN 997 109538 9230/java
[root@server7 ~]
三、报警(邮箱设置)
1、配置虚拟机上网
[root@server7 ~]
[root@server7 ~]
nameserver 114.114.114.11
[root@foundation120 ~]
[root@server7 ~]
PING baidu.com (220.181.57.216) 56(84) bytes of data.
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=1 ttl=48 time=79.1 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=2 ttl=48 time=102 ms
2、配置QQ邮箱
[root@foundation120 ~]# dig -t mx qq.com ##选取SMTP一个作为服务器
qq.com. 5698 IN MX 20 mx2.qq.com.
qq.com. 5698 IN MX 30 mx1.qq.com.
qq.com. 5698 IN MX 10 mx3.qq.com.
[root@server7 ~]# mail root
[root@server7 ~]# mail
Delivered-To: root@server7.localdomain
- zabbix管理平台:
- 配置 –> 动作 –> 触发器 –> 修改
- 管理 –> 报警媒介 –> Email(指定服务器)
- QQ邮箱配置:设置白名单
3、云告警 ##需要注册云告警,设置
[root@server3 zabbix]
/etc/zabbix
[root@server3 zabbix]
509 ExternalScripts=/usr/lib/zabbix/externalscripts
[root@server7 ~]
[root@server7 ~]
[root@server7 alertscripts]
[root@server7 alertscripts]
[root@server7 bin]
alert.sh install.sh log.sh update.sh
[root@server7 bin]
Zabbix管理地址: http://172.25.120.11/zabbix
Zabbix管理员账号: Admin
Zabbix管理员密码: ******
create action success!
安装成功.
4、进入onea!irt,激活邮箱,绑定微信,设置通知策略
5、进入zabbix启动,客户端关闭zabbix-agent
四、zabbix-proxy
1、zabbix-proxy主机(server3)
[root@server3 ~]
[root@server3 ~]
[root@server3 zabbix]
24 Server=172.25.120.11
43 Hostname=server3
167 DBName=zabbix_proxy
182 DBUser=zabbix
190 DBPassword=westos
198 DBSocket=/var/lib/mysql/mysql.sock
323 JavaGateway=172.25.120.11
331 JavaGatewayPort=10052
339 StartJavaPollers=5
[root@server3 zabbix]
[root@server3 zabbix]
[root@server3 zabbix]
[root@server3 zabbix]
[root@server3 zabbix]
mysql> create database zabbix_proxy character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix_proxy.* to zabbix@localhost identified by 'westos';
[root@server3 zabbix]
[root@server3 zabbix-proxy-mysql-3.4.6]
AUTHORS ChangeLog COPYING NEWS README schema.sql.gz
[root@server3 zabbix-proxy-mysql-3.4.6]
Enter password:
[root@server3 zabbix]
[root@server3 zabbix]
[root@server3 zabbix]
- 出现以下错误,查看服务状态,proxy和mysql,保证服务、端口ok即可
1061:20180714:153423.217 [Z3001] connection to database 'zabbix_proxy' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES)
1061:20180714:153423.217 database is down: reconnecting in 10 seconds
1061:20180714:153433.256 database connection re-established
1061:20180714:153433.256 [Z3005] query failed: [1146] Table 'zabbix_proxy.users' doesn't exist [select userid from users limit 1]
1061:20180714:153433.256 cannot use database "zabbix_proxy": database is not a Zabbix database
##出现以下信息才ok
1444:20180714:154811.567 received configuration data from server at "172.25.120.11", datalen 21387
2、zabbix主机(server7)
- 进入zabbix管理界面配置proxy
- 管理 –> agent代理程序 –> 新增代理服务器server3(代理server2,主动式)
[root@server7 zabbix]
3、配置agent主机(server2)
- 查看zabbix监控界面,ZBX和JMX正常即可
- 常见错误:JMX报错,注意proxy主机 Java 的相关配置即可
[root@server2 ~]
[root@server2 zabbix]
97 Server=172.25.120.3
138 ServerActive=172.25.120.3
[root@server2 zabbix]