安装zabbix-agent客户端


1. 虚拟机中安装Centos7系统

本次实验使用最小系统安装,安装完后可以先进行内核软件更新(yum -y update)时间比较久,快速配置可以忽略此步骤。

2.关闭Centos7的SELinux和防火墙配置

关闭SELinux

[root@zabbix-agent1 ~]# setenforce 0

[root@zabbix-agent1 ~]# vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

关闭防火墙配置

[root@zabbix-agent1 ~]# systemctl stop firewalld.service
[root@zabbix-agent1 ~]# systemctl disable firewalld.service

3.部署zabbix4.4客户端

[root@zabbix-agent1 ~]# rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm

[root@zabbix-agent1 ~]# yum clean all

[root@zabbix-agent1 ~]# yum makecache

[root@zabbix-agent1 ~]# yum install -y zabbix-agent

zabbix-agent客户端配置:

[root@zabbix-agent1 ~]# vim /etc/zabbix/zabbix_agentd.conf

PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=10.10.1.88
ServerActive=10.10.1.88
UnsafeUserParameters=1
Include=/etc/zabbix/zabbix_agentd.d/*.conf

zabbix-agent启动:

[root@zabbix-agent1 ~]# systemctl start zabbix-agent;systemctl enable zabbix-agent

jar服务端:

1、远程监控和管理

要从远程系统启用监视和管理,必须在启动Java VM时设置以下系统属性。

-Dcom.sun.management.jmxremote

-Dcom.sun.management.jmxremote.port=22345  #多实例端口加1

-Dcom.sun.management.jmxremote.local.only=false

-Dcom.sun.management.jmxremote.authenticate=false

-Dcom.sun.management.jmxremote.ssl=false

参考https://docs.oracle.com/javase/6/docs/technotes/guides/management/agent.html

[dev@zabbix-agent1 odms-8092]$ nohup java -server  -Dspring.profiles.active=test -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar mpm-odms-2.4.20-SHAPSHOT.jar >> /data/logs/odms-8092/odms.log 2>&1 &

2、测试是否可以获取数据

下载cmdline-jmxclient-0.10.3.jar工具

下载地址:https://pan.baidu.com/s/1MWi8MeAiYQ5ajac6XnqbAw    提取码:m0ty

在服务器端进行测试:有数据则表示成功

[root@zabbix-agent1 ~]# java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:12345 java.lang:type=Memory NonHeapMemoryUsage
04/24/2020 03:52:55 -0400 org.archive.jmx.Client NonHeapMemoryUsage: 
committed: 146931712
init: 2555904
max: -1
used: 141616280

Tomcat服务端

1、给tomcat启动脚本添加参数,开启JMX

vim tomcat/bin/catalina.sh

添加如下内容:

CATALINA_OPTS="${CATALINA_OPTS} -Djava.rmi.server.hostname=172.22.1.xx"  #----备注(172.22.1.xx是客户端ip地址)
CATALINA_OPTS="${CATALINA_OPTS} -Djavax.management.builder.initial="
CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote=true"
CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote.port=12345"   #多实例端口加1
CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote.ssl=false"
CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false"  

2、重启tomcat

./bin/shutdown.sh

./bin/startup.sh

3、测试是否可以获取数据

下载cmdline-jmxclient-0.10.3.jar工具

在服务器端进行测试

java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:12345 java.lang:type=Memory NonHeapMemoryUsage