Zabbix实现故障自愈功能
当zabbix服务监控到指定的监控项异常时,可以通过指定的操作使故障自动恢复
案例:以nginx服务为例,当nginx服务停止时,自动重启服务,实现故障自愈功能
#Zabbix Agent 开启远程命令功能
在agent配置中添加AllowKey=system.run[*]、UnsafeUserParameters=1参数
在proxy配置中,将enableremotecommands参数设置为1
[root@ubuntu2204 ~]#grep UnsafeUserParameters /etc/zabbix/zabbix_agent2.conf
### Option: UnsafeUserParameters
# UnsafeUserParameters=0
UnsafeUserParameters=1
[root@ubuntu2204 ~]#grep AllowKey /etc/zabbix/zabbix_agent2.conf
### Option: AllowKey
# If no AllowKey or DenyKey rules defined, all keys are allowed.
AllowKey=system.run[*]
# Multiple keys matching rules may be defined in combination with AllowKey.
# If no AllowKey or DenyKey rules defined, all keys are allowed.
#Zabbix Agent 对 Zabbix 用户授权管理权限
[root@ubuntu2204 ~]#grep zabbix /etc/sudoers
zabbix ALL=(ALL) NOPASSWD:ALL
[root@ubuntu2204 ~]#visudo -c
/etc/sudoers:解析正确
/etc/sudoers.d/README:解析正确
[root@ubuntu2204 ~]# getent passwd|grep zabbix
zabbix:x:111:116::/var/lib/zabbix/:/usr/sbin/nologin
#测试是否成功
[root@ubuntu2204 ~]#su -s /bin/bash zabbix -c "sudo systemctl restart nginx"
创建内置的模板及相关触发器
添加脚本
#测试
[root@ubuntu2204 ~]#systemctl stop nginx
[root@ubuntu2204 ~]#systemctl status nginx
○ nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Tue 2022-12-27 14:55:18 CST; 13s ago
Docs: man:nginx(8)
Process: 6338 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 6339 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 6955 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 6340 (code=exited, status=0/SUCCESS)
CPU: 181ms
12月 27 14:22:04 ubuntu2204.wang.org systemd[1]: Starting A high performance web server and a reverse proxy server...
12月 27 14:22:04 ubuntu2204.wang.org systemd[1]: Started A high performance web server and a reverse proxy server.
12月 27 14:55:18 ubuntu2204.wang.org systemd[1]: Stopping A high performance web server and a reverse proxy server...
12月 27 14:55:18 ubuntu2204.wang.org systemd[1]: nginx.service: Deactivated successfully.
12月 27 14:55:18 ubuntu2204.wang.org systemd[1]: Stopped A high performance web server and a reverse proxy server.
等一会会发现服务重启,问题被解决
Zabbix 的主动和被动模式工作原理
*主动模式和被动模式都是相对 zabbix agent而言的
- 被动模式:Zabbix默认是被动模式,如果有100个监控项,被动模式需要 Zabbix Server找 Zabbix Agent要100次
- 主动模式:主动模式是Zabbix Server给 Zabbix Agent发送一个包括100个监控项的任务清单,Zabbix Agent根据任务清单,采集好100个监控项的值,主动汇报给 Zabbix Server这100个监控项,Zabbix Agent主动模式只需要发送一次数据,大大提高了传输效率。
注意: 两种模式可以在Zabbix Server上同时存在,可以将一部分监控项设为主动,其它设为被动模式
通信过程
#被动监测通信过程如下:
Server打开一个TCP连接
Server发送请求agent.ping
Agent接收到请求并且响应<HEADER><DATALEN>
Server处理接收到的数据
关闭TCP连接
被动模式每获取一个监控项都需要打开一个tcp连接,这样当监控项越来越多时,Zabbix Server会打开很多端口,就会出现server端性能瓶颈问题。
#主动模式监测通信过程如下:
zabbix agent 首先向ServerActive配置的IP请求获取active items,获取并提交active items数据值给server或者proxy。
zabbix多久获取一次active items?
它会根据agent的配置文件中的RefreshActiveChecks的频率进行,如果获取失败,那么将会在60秒之后重试。
主动模式的流程分两个部分:
- 获取ACTIVE ITEMS列表
Agent主动打开一个TCP连接(主动检测变成Agent打开)
Agent请求items检测列表
Server返回items列表
Agent 处理响应
关闭TCP连接
Agent开始收集数据
- 主动检测提交数据过程
Agent建立TCP连接
Agent批量提交items列表收集的所有监控项数据
Server处理数据,并返回响应状态
关闭TCP连接
注意:Zabbix agent主动模式对应的进程数量只有1个,不能调整 Zabbix agent被动模式对应的进程数量默认3个,可以调整
案例:被动模式下 Zabbix agent 进程和端口打开情况
#查看被动模式下 Zabbix agent 进程和端口打开情况
[root@ubuntu2204 ~]#grep StartAgents /etc/zabbix/zabbix_agentd.conf
# Mandatory: yes, if StartAgents is not explicitly set to 0
### Option: StartAgents
# StartAgents=3
[root@ubuntu2204 ~]#ps ax|grep zabbix
811 ? S 0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
812 ? S 0:01 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
813 ? S 0:07 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
814 ? S 0:06 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
815 ? S 0:06 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
816 ? S 0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
[root@ubuntu2204 ~]#ss -nta|grep 10050
LISTEN 0 4096 0.0.0.0:10050 0.0.0.0:*
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:49942
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:49700
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:37962
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:53422
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:49594
TIME-WAIT 0 0 127.0.0.1:32936 127.0.0.1:10050
TIME-WAIT 0 0 127.0.0.1:32986 127.0.0.1:10050
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:59854
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:53260
TIME-WAIT 0 0 127.0.0.1:32890 127.0.0.1:10050
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:53442
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:59906
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:49966
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:59960
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:38068
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:42376
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:49984
TIME-WAIT 0 0 127.0.0.1:10050 127.0.0.1:53372
.....
[root@ubuntu2204 ~]#tail /var/log/zabbix/zabbix_agentd.log
811:20221227:102802.958 using configuration file: /etc/zabbix/zabbix_agentd.conf
811:20221227:102802.959 agent #0 started [main process]
814:20221227:102802.962 agent #3 started [listener #2]
815:20221227:102802.962 agent #4 started [listener #3]
816:20221227:102802.965 agent #5 started [active checks #1]
813:20221227:102802.967 agent #2 started [listener #1]
816:20221227:102802.971 Unable to connect to [127.0.0.1]:10051 [cannot connect to [[127.0.0.1]:10051]: [111] Connection refused]
816:20221227:102802.971 Active check configuration update started to fail
812:20221227:102802.971 agent #1 started [collector]
816:20221227:103102.089 Active check configuration update from [127.0.0.1:10051] is working again
案例:Zabbix Agent 实现主动模式
- 在 Zabbix Agent 配置主机模式相关配置
- 在 Zabbix Server 创建配置有主动模式监控项的模板
- 关联主动模板至支持主动模式的 Agent 主机
- 注意: 基于原被动模板克隆生成的主动模式模板,不是所有监控项都能改为主动模式,比如agent.ping 监控项如果改为主动模式, ZBX 提示将无法变绿
#Zabbix Server 通过 trapper 进程实现主动模式
[root@ubuntu2204 ~]#grep StartTrappers /etc/zabbix/zabbix_server.conf
### Option: StartTrappers
# StartTrappers=5
[root@ubuntu2204 ~]#ps ax|grep trapper
978 ? S 0:00 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.002824 sec, waiting for connection]
979 ? S 0:00 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.002858 sec, waiting for connection]
980 ? S 0:00 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.006950 sec, waiting for connection]
981 ? S 0:00 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.002255 sec, waiting for connection]
982 ? S 0:00 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.005087 sec, waiting for connection]
4253 pts/0 S+ 0:00 grep --color=auto trapper
#Zabbix Agent2配置主动模式配置
Server=<Zabbix Server> #被动模式指向 Zabbix Server的IP或FQDN,默认模式
ServerActive=<Zabbix Server> #主动模式指向 Zabbix Server的IP或FQDN
Hostname=<当前主机IP> #当前主机的IP,此项必须和Zabbix Server中设置的主机名称相同
[root@ubuntu2204 ~]#grep '^[^#]' /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=10.0.0.200
ServerActive=10.0.0.200
Hostname=10.0.0.202
Timeout=30
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
Include=./zabbix_agent2.d/plugins.d/*.conf
[root@ubuntu2204 ~]#systemctl restart zabbix-agent2.service
[root@ubuntu2204 ~]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 127.0.0.1:6010 0.0.0.0:*
LISTEN 0 511 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 [::1]:6010 [::]:*
LISTEN 0 4096 *:10050 *:*
LISTEN 0 511 [::]:80 [::]:*
在Zabbix Frontend上添加主动模式的服务即可
额外提一点:主动模式下Zabbix录取监控数据是并行执行,被动模式下是串行
监控 JAVA 程序
Zabbix 不支持直接监控JAVA应用。如果要监控JAVA程序比如Tomcat等,需要使用 Java gateway 做为代理,才能从JAVA应用中获取数据
Zabbix Java gateway 能过监听10052/tcp 端口实现监控JAVA应用
案例:监控 Java 应用 Tomcat 服务
部署 tomcat 服务
TOMCAT_VERSION=9.0.70
JDK_VERSION=8u351
TOMCAT_FILE="apache-tomcat-${TOMCAT_VERSION}.tar.gz"
JDK_FILE="jdk-${JDK_VERSION}-linux-x64.tar.gz"
JDK_DIR="/usr/local"
TOMCAT_DIR="/usr/local"
DIR=`pwd`
color () {
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \E[0m"
echo -n "$2" && $MOVE_TO_COL
echo -n "["
if [ $1 = "success" -o $1 = "0" ] ;then
${SETCOLOR_SUCCESS}
echo -n $" OK "
elif [ $1 = "failure" -o $1 = "1" ] ;then
${SETCOLOR_FAILURE}
echo -n $"FAILED"
else
${SETCOLOR_WARNING}
echo -n $"WARNING"
fi
${SETCOLOR_NORMAL}
echo -n "]"
echo
}
install_jdk(){
if [ ! -f "$DIR/$JDK_FILE" ];then
color 1 "$JDK_FILE 文件不存在"
exit;
elif [ -d $JDK_DIR/jdk ];then
color 1 "JDK 已经安装"
exit
else
[ -d "$JDK_DIR" ] || mkdir -pv $JDK_DIR
fi
tar xvf $DIR/$JDK_FILE -C $JDK_DIR
cd $JDK_DIR && ln -s jdk* jdk
cat > /etc/profile.d/jdk.sh <<EOF
export JAVA_HOME=$JDK_DIR/jdk
export PATH=\$PATH:\$JAVA_HOME/bin
#export JRE_HOME=\$JAVA_HOME/jre
#export CLASSPATH=.:\$JAVA_HOME/lib/:\$JRE_HOME/lib/
EOF
. /etc/profile.d/jdk.sh
java -version && color 0 "JDK 安装完成" || { color 1 "JDK 安装失败" ; exit; }
}
install_tomcat(){
if ! [ -f "$DIR/$TOMCAT_FILE" ];then
color 1 "$TOMCAT_FILE 文件不存在"
exit;
elif [ -d $TOMCAT_DIR/tomcat ];then
color 1 "TOMCAT 已经安装"
exit
else
[ -d "$TOMCAT_DIR" ] || mkdir -pv $TOMCAT_DIR
fi
tar xf $DIR/$TOMCAT_FILE -C $TOMCAT_DIR
cd $TOMCAT_DIR && ln -s apache-tomcat-*/ tomcat
echo "PATH=$TOMCAT_DIR/tomcat/bin:"'$PATH' > /etc/profile.d/tomcat.sh
id tomcat &> /dev/null || useradd -r -s /sbin/nologin tomcat
cat > $TOMCAT_DIR/tomcat/conf/tomcat.conf <<EOF
JAVA_HOME=$JDK_DIR/jdk
EOF
chown -R tomcat.tomcat $TOMCAT_DIR/tomcat/
cat > /lib/systemd/system/tomcat.service <<EOF
[Unit]
Descriptinotallow=Tomcat
#After=syslog.target network.target remote-fs.target nss-lookup.target
After=syslog.target network.target
[Service]
Type=forking
Envirnotallow=$TOMCAT_DIR/tomcat/conf/tomcat.conf
ExecStart=$TOMCAT_DIR/tomcat/bin/startup.sh
ExecStop=$TOMCAT_DIR/tomcat/bin/shutdown.sh
RestartSec=3
PrivateTmp=true
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now tomcat.service &> /dev/null
systemctl is-active tomcat.service &> /dev/null && color 0 "TOMCAT 安装完成" || { color 1 "TOMCAT 安装失败" ; exit; }
}
install_jdk
install_tomcat
----------------------------------------------------------------------------------------
[root@ubuntu2204 ~]#systemctl status tomcat
● tomcat.service - Tomcat
Loaded: loaded (/lib/systemd/system/tomcat.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-12-27 16:13:18 CST; 51s ago
Process: 8621 ExecStart=/usr/local/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 8630 (java)
Tasks: 29 (limit: 9365)
Memory: 101.7M
CPU: 3.409s
CGroup: /system.slice/tomcat.service
└─8630 /usr/local/jdk/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.proto
col.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.b
ase=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
12月 27 16:13:18 ubuntu2204.wang.org systemd[1]: Starting Tomcat...
12月 27 16:13:18 ubuntu2204.wang.org startup.sh[8621]: Tomcat started.
12月 27 16:13:18 ubuntu2204.wang.org systemd[1]: Started Tomcat.
[root@ubuntu2204 ~]#ss -ntlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=649,fd=14))
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=760,fd=3))
LISTEN 0 128 127.0.0.1:6010 0.0.0.0:* users:(("sshd",pid=846,fd=7))
LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=7579,fd=6),("nginx",pid=7578,fd=6),("nginx",pid=7577,fd=6))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=760,fd=4))
LISTEN 0 128 [::1]:6010 [::]:* users:(("sshd",pid=846,fd=5))
LISTEN 0 4096 *:10050 *:* users:(("zabbix_agent2",pid=7212,fd=7))
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:* users:(("java",pid=8630,fd=66))
LISTEN 0 100 *:8080 *:* users:(("java",pid=8630,fd=58))
LISTEN 0 511 [::]:80 [::]:* users:(("nginx",pid=7579,fd=7),("nginx",pid=7578,fd=7),("nginx",pid=7577,fd=7))
Tomcat 开启 JMX 监控
- 通常使用JMX来监控系统的运行状态或管理系统的某些方面,比如清空缓存、重新加载配置文件等
[root@ubuntu2204 ~]#vim /usr/local/tomcat/bin/catalina.sh
...
# -----------------------------------------------------------------------------
CATALINA_OPTS="$CATALINA__OPTS
-Dcom.sun.management.jmxremote -- 启用远程监控JMX
-Dcom.sun.management.jmxremote.port=12345 -- 默认启动的JMX端口号
-Dcom.sun.management.jmxremote.authenticate=false -- 不使用用户名密码
-Dcom.sun.management.jmxremote.ssl=false -- 不使用ssl认证
-Djava.rmi.server.hostname=10.0.0.202" -- tomcat主机的IP地址
# OS specific support. $var _must_ be set to either true or false.
...
[root@ubuntu2204 ~]#systemctl start tomcat
[root@ubuntu2204 ~]#systemctl status tomcat
● tomcat.service - Tomcat
Loaded: loaded (/lib/systemd/system/tomcat.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-12-27 16:35:55 CST; 3s ago
Process: 9259 ExecStart=/usr/local/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 9267 (java)
Tasks: 32 (limit: 9365)
Memory: 102.9M
CPU: 2.917s
CGroup: /system.slice/tomcat.service
└─9267 /usr/local/jdk/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.proto
col.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=fals
e -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=10.0.0.202 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcata
lina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
12月 27 16:35:54 ubuntu2204.wang.org systemd[1]: Starting Tomcat...
12月 27 16:35:55 ubuntu2204.wang.org startup.sh[9259]: Tomcat started.
12月 27 16:35:55 ubuntu2204.wang.org systemd[1]: Started Tomcat.
#查看端口12345是否打开
[root@ubuntu2204 ~]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 127.0.0.1:6010 0.0.0.0:*
LISTEN 0 128 127.0.0.1:6011 0.0.0.0:*
LISTEN 0 511 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 50 *:12345 *:*
LISTEN 0 128 [::1]:6010 [::]:*
LISTEN 0 128 [::1]:6011 [::]:*
LISTEN 0 4096 *:10050 *:*
LISTEN 0 50 *:37155 *:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 511 [::]:80 [::]:*
LISTEN 0 50 *:46769 *:*
使用 java 客户端 cmdlinejmxclient 获取 JMX 信息
- cmdline-jmxclient-0.10.3.jar 是一个开源jar包,在zabbix 中常用于测试的一个工具,可以用来测试 jmx是否配置正确。在监控方面还可以对Tomcat各种属性进行监控。
下载:
https://github.com/qiueer/zabbix/blob/master/Tomcat/cmdline-jmxclient-0.10.3.jar
[root@ubuntu2204 ~]#ll cmdline-jmxclient-0.10.3.jar
-rw-r--r-- 1 root root 20124 12月 27 16:46 cmdline-jmxclient-0.10.3.jar
[root@ubuntu2204 ~]#apt install openjdk-8-jdk -y
#测试能否获取到java最大线程数:
[root@ubuntu2204 ~]#java -jar cmdline-jmxclient-0.10.3.jar - 10.0.0.202:12345 'Catalina:name="http-nio-8080",type=ThreadPool' currentThreadCount
12/27/2022 16:58:21 +0800 org.archive.jmx.Client currentThreadCount: 10
部署 Java gateway 服务器
- Java gateway 是一个独立于zabbix server和 zabbix agent的组件,默认使用端口10052/tcp, 所以javagateway可以是单独的一台服务器,但是也可以和zabbix server或者zabbix agent 共用一台服务器
[root@ubuntu2204 ~]#wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4%2Bubuntu22.04_all.deb
--2022-12-27 17:08:54-- https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4%2Bubuntu22.04_all.deb
正在解析主机 repo.zabbix.com (repo.zabbix.com)... 178.128.6.101, 2604:a880:2:d0::2062:d001
正在连接 repo.zabbix.com (repo.zabbix.com)|178.128.6.101|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 3676 (3.6K) [application/octet-stream]
正在保存至: ‘zabbix-release_6.0-4+ubuntu22.04_all.deb.1’
zabbix-release_6.0-4+ubuntu22.04_all.deb.1 100%[===================================================================================================================================>] 3.59K --.-KB/s 用时 0s
2022-12-27 17:08:55 (1.65 GB/s) - 已保存 ‘zabbix-release_6.0-4+ubuntu22.04_all.deb.1’ [3676/3676])
[root@ubuntu2204 ~]#dpkg -i zabbix-release_6.0-4+ubuntu22.04_all.deb
(正在读取数据库 ... 系统当前共安装有 88686 个文件和目录。)
准备解压 zabbix-release_6.0-4+ubuntu22.04_all.deb ...
正在解压 zabbix-release (1:6.0-4+ubuntu22.04) 并覆盖 (1:6.0-4+ubuntu22.04) ...
正在设置 zabbix-release (1:6.0-4+ubuntu22.04) ...
[root@ubuntu2204 ~]#apt update
命中:1 http://mirrors.ustc.edu.cn/ubuntu jammy InRelease
获取:2 http://mirrors.ustc.edu.cn//ubuntu jammy-security InRelease [110 kB]
获取:3 http://mirrors.ustc.edu.cn/ubuntu jammy-security InRelease [110 kB]
获取:4 http://mirrors.ustc.edu.cn/ubuntu jammy-updates InRelease [114 kB]
获取:5 http://mirrors.ustc.edu.cn/ubuntu jammy-proposed InRelease [270 kB]
获取:6 http://mirrors.ustc.edu.cn/ubuntu jammy-backports InRelease [99.8 kB]
命中:7 https://repo.zabbix.com/zabbix-agent2-plugins/1/ubuntu jammy InRelease
命中:8 https://repo.zabbix.com/zabbix/6.0/ubuntu jammy InRelease
已下载 705 kB,耗时 2秒 (385 kB/s)
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
有 69 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。
[root@ubuntu2204 ~]#apt install zabbix-java-gateway
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
将会同时安装下列软件:
default-jre-headless openjdk-11-jre-headless
建议安装:
default-jre libnss-mdns fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei fonts-indic
下列【新】软件包将被安装:
default-jre-headless openjdk-11-jre-headless zabbix-java-gateway
升级了 0 个软件包,新安装了 3 个软件包, 要卸载 0 个软件包,有 69 个软件包未被升级。
需要下载 42.2 MB 的归档。
解压缩后会消耗 172 MB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://mirrors.ustc.edu.cn//ubuntu jammy-security/main amd64 openjdk-11-jre-headless amd64 11.0.17+8-1ubuntu2~22.04 [41.5 MB]
获取:2 https://repo.zabbix.com/zabbix/6.0/ubuntu jammy/main amd64 zabbix-java-gateway all 1:6.0.12-1+ubuntu22.04 [694 kB]
获取:3 http://mirrors.ustc.edu.cn/ubuntu jammy/main amd64 default-jre-headless amd64 2:1.11-72build2 [3,042 B]
已下载 42.2 MB,耗时 3秒 (13.4 MB/s)
debconf: 因为并未安装 apt-utils,所以软件包的设定过程将被推迟
正在选中未选择的软件包 openjdk-11-jre-headless:amd64。
(正在读取数据库 ... 系统当前共安装有 88686 个文件和目录。)
准备解压 .../openjdk-11-jre-headless_11.0.17+8-1ubuntu2~22.04_amd64.deb ...
正在解压 openjdk-11-jre-headless:amd64 (11.0.17+8-1ubuntu2~22.04) ...
....
#可以开启自身的JMX功能实现自身的监控(可选)
[root@ubuntu2204 ~]#vim /etc/zabbix/zabbix_java_gateway.conf
# uncomment to enable remote monitoring of the standard JMX objects on the Zabbix
Java Gateway itself
JAVA_OPTIONS="$JAVA_OPTIONS -Dcom.sun.management.jmxremote -
Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false -
Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.registry.ssl=false"
[root@ubuntu2204 ~]#vim /etc/zabbix/zabbix_java_gateway.conf
[root@ubuntu2204 ~]#systemctl restart zabbix-java-gateway
[root@ubuntu2204 ~]#systemctl enable zabbix-java-gateway
Synchronizing state of zabbix-java-gateway.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-java-gateway
[root@ubuntu2204 ~]#systemctl status zabbix-java-gateway
● zabbix-java-gateway.service - Zabbix Java Gateway
Loaded: loaded (/lib/systemd/system/zabbix-java-gateway.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-12-27 17:21:23 CST; 12s ago
Main PID: 13793 (java)
Tasks: 19 (limit: 9365)
Memory: 31.7M
CPU: 745ms
CGroup: /system.slice/zabbix-java-gateway.service
└─13793 java -server -Dlogback.cnotallow=/etc/zabbix/zabbix_java_gateway_logback.xml -classpath lib:lib/android-json-4.3_r3.1.jar:lib/logback-classic-1.2.9.jar:lib/logback-core-1.2.9.jar:lib/slf4j-api-1.7.32.j
ar:bin/zabbix-java-gateway-6.0.12.jar -Dzabbix.pidFile=/var/run/zabbix/zabbix_java_gateway.pid -Dsun.rmi.transport.tcp.respnotallow=3000 com.zabbix.gateway.JavaGateway
12月 27 17:21:23 ubuntu2204.wang.org systemd[1]: Starting Zabbix Java Gateway...
12月 27 17:21:23 ubuntu2204.wang.org systemd[1]: Started Zabbix Java Gateway.
#Ubuntu安装后会自动启动服务并打开监听10052/tcp端口
[root@ubuntu2204 ~]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 127.0.0.1:6010 0.0.0.0:*
LISTEN 0 128 127.0.0.1:6011 0.0.0.0:*
LISTEN 0 511 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 50 *:12345 *:*
LISTEN 0 128 [::1]:6010 [::]:*
LISTEN 0 128 [::1]:6011 [::]:*
LISTEN 0 4096 *:10050 *:*
LISTEN 0 50 *:37155 *:*
LISTEN 0 50 *:10052 *:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 511 [::]:80 [::]:*
LISTEN 0 50 *:46769 *:*
配置 Zabbix Server 支持 Java gateway
[root@ubuntu2204 ~]#vim /etc/zabbix/zabbix_server.conf
...
### Option: JavaGateway
# IP address (or hostname) of Zabbix Java gateway.
# Only required if Java pollers are started.
#
# Mandatory: no
# Default:
JavaGateway=10.0.0.202 #指向JAVA gateway主机
### Option: JavaGatewayPort
# Port that Zabbix Java gateway listens on.
#
# Mandatory: no
# Range: 1024-32767
# Default:
# JavaGatewayPort=10052 #指定端口,此为默认值,可不修改
### Option: StartJavaPollers
# Number of pre-forked instances of Java pollers.
#
# Mandatory: no
# Range: 0-1000
# Default:
StartJavaPollers=10 #指定开启的进程数,默认为0,即不开启,所以必须修改此行 这里开10个进程做实验
[root@ubuntu2204 ~]#systemctl restart zabbix-server.service
[root@ubuntu2204 ~]#ps -ef|grep java
zabbix 15568 15543 0 17:31 ? 00:00:00 /usr/sbin/zabbix_server: java poller #1 [got 0 values in 0.000065 sec, idle 5 sec]
zabbix 15569 15543 0 17:31 ? 00:00:00 /usr/sbin/zabbix_server: java poller #2 [got 0 values in 0.000038 sec, idle 5 sec]
zabbix 15570 15543 0 17:31 ? 00:00:00 /usr/sbin/zabbix_server: java poller #3 [got 0 values in 0.000031 sec, idle 5 sec]
zabbix 15571 15543 0 17:31 ? 00:00:00 /usr/sbin/zabbix_server: java poller #4 [got 0 values in 0.000018 sec, idle 5 sec]
zabbix 15572 15543 0 17:31 ? 00:00:00 /usr/sbin/zabbix_server: java poller #5 [got 0 values in 0.000031 sec, idle 5 sec]
zabbix 15575 15543 0 17:31 ? 00:00:00 /usr/sbin/zabbix_server: java poller #6 [got 0 values in 0.000075 sec, idle 5 sec]
zabbix 15576 15543 0 17:31 ? 00:00:00 /usr/sbin/zabbix_server: java poller #7 [got 0 values in 0.000015 sec, idle 5 sec]
zabbix 15577 15543 0 17:31 ? 00:00:00 /usr/sbin/zabbix_server: java poller #8 [got 0 values in 0.000026 sec, idle 5 sec]
zabbix 15578 15543 0 17:31 ? 00:00:00 /usr/sbin/zabbix_server: java poller #9 [got 0 values in 0.000017 sec, idle 5 sec]
zabbix 15579 15543 0 17:31 ? 00:00:00 /usr/sbin/zabbix_server: java poller #10 [got 0 values in 0.000086 sec, idle 5 sec]
使用系统内置模板监控 tomcat 主机
我是moore,大家一起加油!一晃一天又过去了......