Archive for 1月 2019

Zabbix 4.0.2试用(九):在Linux主机中安装zabbix agent并添加该主机(RPM安装,适用于内网无互联网环境)

之前介绍的是用yum源方式安装,前提是主机需要与互联网相通,但有些需监控的客户机可能没有互联网,只有内网环境,就需要使用RPM安装方法,操作如下:

1、关闭防火墙和SELINUX

使用root用户登陆系统:

首先查看防火墙状态

[root@zabbix ~]# firewall-cmd –state
running
[root@zabbix ~]#

关闭firewall,并禁止防火墙开机启动,命令如下:

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

再次查看,防火墙已不在运行:

[root@zabbix ~]# firewall-cmd –state

安装之前还需将SELINUX关闭,运行如下命令编辑SELINUX配置文件:

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

并将SELINUX=enforcing改成SELINUX=disable,如下:

# 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 two values:
#     targeted – Targeted processes are protected,
#     minimum – Modification of targeted policy. Only selected processes are protected.
#     mls – Multi Level Security protection.
SELINUXTYPE=targeted

修改完成后,重启机器,运行如下命令查看是否 SELINUX已关闭:

[root@zabbix ~]# getenforce

退回disable即为已关闭。

2、安装Zabbix Agent

由于此centos客户端没有互联网环境,故不能使用YUM等方式安装,将采用RPM安装包进行安装。

首先进入http://repo.zabbix.com,下载http://repo.zabbix.com/zabbix-official-repo.keyhttp://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.1-1.el7.x86_64.rpm两个文件,然后开始安装:

首先导入repo:

[root@zabbixclient tmp]# rpm –import zabbix-official-repo.key

agentnew001

完成后,开始安装zabbix agent:

[root@zabbixclient tmp]# rpm -ivh zabbix-agent-4.0.1-1.el7.x86_64.rpm
warning: zabbix-agent-4.0.1-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing…                          ################################# [100%]
Updating / installing…
   1:zabbix-agent-4.0.1-1.el7         ################################# [100%]
[root@zabbixclient tmp]#

agentnew002

3、配置Zabbix Agent配置文件zabbix_agentd.conf

使用vi编辑器编辑配置文件,进入/etc/zabbix/目录,使用vi编辑器打开zabbix_agentd.conf

[root@zabbixclient tmp]# cd /etc/zabbix/
[root@zabbixclient zabbix]# ls
zabbix_agentd.conf  zabbix_agentd.d
[root@zabbixclient zabbix]# vi zabbix_agentd.conf

主要完成以下几项的修改:

EnableRemoteCommands=1       //来至zabbix服务器的远程命令是否允许被执行
Server=192.168.10.208             //zabbix server地址,用于被动模式,数据获取
ServerActive=192.168.10.208    //主动发送的zabbix server地址主动发送的zabbix server地址,用于主动模式,数据提交
Hostname=zabbix                     //和创建主机时的hostname一致
UnsafeUserParameters=1           //启用自定义key,zabbix监控mysql、tomcat等数据时需要自定义key

完成后保存退出。

3、启动Zabbix Agent服务

配置文件修改完成后,开始启动Agent程序,service zabbix-agent status用来查看启动状态,service zabbix-agent start用来启动服务,具体如下:

[root@zabbixclient zabbix]# service zabbix-agent status
Redirecting to /bin/systemctl status zabbix-agent.service
鈼zabbix-agent.service – Zabbix Agent
   Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@zabbixclient zabbix]# service zabbix-agent start
Redirecting to /bin/systemctl start zabbix-agent.service
[root@zabbixclient zabbix]# service zabbix-agent status
Redirecting to /bin/systemctl status zabbix-agent.service
鈼[0m zabbix-agent.service – Zabbix Agent
   Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-03-24 19:58:25 CST; 6s ago
  Process: 20179 ExecStart=/usr/sbin/zabbix_agentd -c $CONFFILE (code=exited, status=0/SUCCESS)
  Main PID: 20182 (zabbix_agentd)
    Tasks: 6
   CGroup: /system.slice/zabbix-agent.service
            鈹溾攢20182 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
           鈹溾攢20184 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
           鈹溾攢20185 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
           鈹溾攢20186 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
            鈹溾攢20187 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
           鈹斺攢20188 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]

Mar 24 19:58:25 zabbixclient systemd[1]: Starting Zabbix Agent…
Mar 24 19:58:25 zabbixclient systemd[1]: Started Zabbix Agent.
[root@zabbixclient zabbix]#

agentnew003

4、开机自启动Zabbix Agent服务

通过chkconfig zabbix-agent on命令来实现开机自动启动:

[root@zabbixclient zabbix]# chkconfig zabbix-agent on
Note: Forwarding request to ‘systemctl enable zabbix-agent.service’.
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@zabbixclient zabbix]#

5、将主机添加至zabbix server平台

打开zabbix server主界面,选择“配置‘->”主机“,点击右上角的”创建“按扭,创建一台主机,如下图

agentinstall06

输入主机名称,群组选择系统默认的Server hardware,agent代理接口IP设置刚才安装agent的主机192.168.10.209,端口默认10050,如下图:

agentinstall07

再选择”模板“选项栏,链接指示器里选择”Template OS Linux“,点击添加,最后点击蓝底添加按扭,完成添加。

agentinstall08

完成后可以看到列表中已经有刚才不回的主机,过几分钟后,可用性一栏中的ZBX变绿即表示监控正常。

agentinstall09