1..zabbix分布式监控,模拟多机房实现监控?
1.有多机房时,需要用到proxy
1.网络不通
2.网络延迟
2.当监控的主机较多时,也可以用proxy来缓解压力
1.安装proxy
[root@web01 ~]# rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
2.安装proxy 数据库
yum install zabbix-proxy-mysql mariadb-server -y
systemctl start mariadb
MariaDB [(none)]> create database zabbix_proxy character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on zabbix_proxy.* to zabbix_proxy@localhost identified by 'zabbix_proxy';
zcat /usr/share/doc/zabbix-proxy-mysql-4.0.14/schema.sql.gz | mysql -uzabbix_proxy -pzabbix_proxy zabbix_proxy
3.配置zabbix-proxy
[root@web02 ~]# grep "^[a-Z]" /etc/zabbix/zabbix_proxy.conf
....
Server=10.0.0.71
Hostname=sh_proxy
DBHost=localhost
DBName=zabbix_proxy
DBUser=zabbix_proxy
DBPassword=zabbix_proxy
....
4.启动proxy
systemctl enable zabbix-proxy.service
systemctl start zabbix-proxy
5.配置zabbix-agent 不通区域的agent指向不同的proxy
10.0.0.71 <--- 10.0.0.7 <---172.16.1.51
10.0.0.71 <--- 10.0.0.8 <---172.16.1.41
[root@db01 ~]# grep '^[a-Z]' /etc/zabbix/zabbix_agentd.conf
.....
Server=172.16.1.7
ServerActive=172.16.1.7
Hostname=db01
.....
systemctl restart zabbix-agent
[root@node1 ~]# grep '^[a-Z]' /etc/zabbix/zabbix_agentd.conf
.....
Server=172.16.1.8
ServerActive=172.16.1.8
Hostname=node1
.....
systemctl restart zabbix-agent
6.登录zabbix-web
1.管理-->agent代理程序
注意:
zabbix-server 与 zabbix-proxy 需要版本一致
ProxyLocalBuffer Proxy将在本地保留数据N小时,即使数据已与server同步。(默认不保留立即发送)
ProxyOfflineBuffer 如果无法连接Zabbix server,proxy将默认保留数据1小时.
zabbix监控jvm? tomcat
2.zabbix ---> jmx ---> java(zabbix-agent)
1.Zabbix-Server找Zabbix-Java-Gateway获取Java数据
2.Zabbix-Java-Gateway找Java程序获取数据
3.Java程序返回数据给Zabbix-Java-Gateway
4.Zabbix-Java-Gateway返回数据给Zabbix-Server
5.Zabbix-Server进行数据展示
配置JMX监控的步骤:
1.安装Zabbix-Java-Gateway。
2.配置zabbix_java_gateway.conf参数。
3.配置zabbix-server.conf参数。-->连接java-gateway
4.Tomcat应用开启JMX协议。
5.ZabbixWeb配置JMX监控的Java应用。
环境:
zabbix-server 10.0.0.71 172.16.1.71
zabbix-gateway 172.16.1.7
tomcat 172.16.1.8
1.安装Zabbix-Java-Gateway
[root@web01 ~]# yum install zabbix-java-gateway -y
2.启动Zabbix-Java-Gateway
[root@web01 ~]# systemctl restart zabbix-java-gateway
[root@web01 ~]# systemctl enable zabbix-java-gateway.service
3.配置zabbix-server指向zabbix-java-gateway
[root@zabbix-server ~]# vim /etc/zabbix/zabbix_server.conf
JavaGateway=172.16.1.7
JavaGatewayPort=10052
StartJavaPollers=5
[root@zabbix-server ~]# systemctl restart zabbix-server
4.启动tomcat程序,开启jmx协议
[root@web02 soft]# vim /soft/tomcat/bin/catalina.sh #头部添加即可
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=172.16.1.8"
5.启动tomcat
pkill java
/soft/tomcat/bin/startup.sh*
6.登录zabbix-web添加一台jmx的主机
3.zabbix Api ( 开发 )
1.在使用zabbix-api之前,先获取一个token
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "oldxu.com"
},
"id": 1
}' http://zabbix.oldxu.com/zabbix/api_jsonrpc.php
2.返回的token值:
{"jsonrpc":"2.0","result":"4c831e081ff77510f9662bb9de0f9144","id":1}
3.检索主机
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"hostid",
"host"
],
"selectInterfaces": [
"interfaceid",
"ip"
]
},
"id": 2,
"auth": "4c831e081ff77510f9662bb9de0f9144"
}' http://zabbix.oldxu.com/zabbix/api_jsonrpc.php
4.使用token验证身份, 并禁用某一台主机
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.update",
"params": {
"hostid": "10283",
"status": 1
},
"auth": "4c831e081ff77510f9662bb9de0f9144",
"id": 1
}' http://zabbix.oldxu.com/zabbix/api_jsonrpc.php
5.使用API创建主机
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "10.0.0.1",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "10.0.0.1",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "20"
}
],
"templates": [
{
"templateid": "10001"
}
]
},
"auth": "4c831e081ff77510f9662bb9de0f9144",
"id": 1
}' http://zabbix.oldxu.com/zabbix/api_jsonrpc.php
4.zabbix优化
(1) Zabbix属于写多读少的业务, 所以需要针对zabbix的MySQL进行拆分.
1.LAMP -->拆分成LAP + MySQL
2.MySQL尽量使用SSD固态盘
(2) 将Zabbix-Agent被动监控模式, 调整为主动监控模式.
(3) 使用zabbix-proxy分布式监控, 在大规模监控时用于缓解Zabbix-Server压力
(4) 去掉无用监控项, 增加监控项的取值间隔, 减少历史数据保存周期(由housekeeper进程定时清理)
(5)针对于Zabbix-server进程调优, 谁忙就加大谁的进程数量, 具体取决实际情况, 不是越大越好
(6)针对于Zabbix-server缓存调优, 谁使用的缓存多,就加大它的缓存值(zabbix cache usage图表)
(7) 关注管理->队列, 是否有被延迟执行的监控项