Zabbix 4.0.2试用(七):在Linux主机中安装zabbix agent并添加该主机(yum源安装)

之前介绍的是下载源安装包,编译安装的方式来安装agent,本次将采用yum源方式安装,前提是主机需要与互联网相通,操作如下:

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

首先需添加对应的yum repository:

进入zabbix官网文档,选择产品手册->安装->从二进制包安装->1 Red Hat Enterprise,

zabbixinstallx21

zabbixagentyum01

开始安装agent:

[root@localhost ~]# yum install zabbix-agent
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
  * base: centos.ustc.edu.cn
  * extras: centos.ustc.edu.cn
  * updates: mirrors.shu.edu.cn
base                                                                        | 3.6 kB  00:00:00    
extras                                                                      | 3.4 kB  00:00:00    
updates                                                                     | 3.4 kB  00:00:00    
zabbix                                                                      | 2.9 kB  00:00:00    
zabbix-non-supported                                                        |  951 B  00:00:00    
updates/7/x86_64/primary_db    FAILED                                         
http://mirrors.shu.edu.cn/centos/7.6.1810/updates/x86_64/repodata/384ed51dad1c96d9f80866dedacb6fd008516393c597a3da83afd33281356e1b-primary.sqlite.bz2: [Errno 14] curl#7 – “Failed connect to mirrors.shu.edu.cn:80; Connection refused”
Trying other mirror.
(1/5): extras/7/x86_64/primary_db                                           | 156 kB  00:00:00    
(2/5): base/7/x86_64/group_gz                                               | 166 kB  00:00:00    
(3/5): zabbix/x86_64/primary_db                                             |  26 kB  00:00:00    
(4/5): updates/7/x86_64/primary_db                                          | 1.3 MB  00:00:04    
(5/5): base/7/x86_64/primary_db                                             | 6.0 MB  00:00:10    
zabbix-non-supported/x86_64/primary                                         | 1.6 kB  00:00:00    
zabbix-non-supported                                                                           4/4
Resolving Dependencies
–> Running transaction check
—> Package zabbix-agent.x86_64 0:4.0.2-1.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================
  Package                   Arch                Version                   Repository           Size
===================================================================================================
Installing:
  zabbix-agent              x86_64              4.0.2-1.el7               zabbix              384 k

Transaction Summary
===================================================================================================
Install  1 Package

Total download size: 384 k
Installed size: 1.5 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/zabbix/packages/zabbix-agent-4.0.2-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Public key for zabbix-agent-4.0.2-1.el7.x86_64.rpm is not installed
zabbix-agent-4.0.2-1.el7.x86_64.rpm                                         | 384 kB  00:00:01    
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
Importing GPG key 0xA14FE591:
  Userid     : “Zabbix LLC <packager@zabbix.com>”
  Fingerprint: a184 8f53 52d0 22b9 471d 83d0 082a b56b a14f e591
  Package    : zabbix-release-4.0-1.el7.noarch (installed)
  From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : zabbix-agent-4.0.2-1.el7.x86_64                                                 1/1
  Verifying  : zabbix-agent-4.0.2-1.el7.x86_64                                                 1/1

Installed:
  zabbix-agent.x86_64 0:4.0.2-1.el7                                                              

Complete!
[root@localhost ~]#

3、配置Zabbix Agent

完成安装后,开始配置zabbix_agentd.conf配置文件:

[root@localhost ~]# vi /etc/zabbix/zabbix_agentd.conf

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

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

完成后保存退出。

4、启动Zabbix Agent

配置文件修改后,开始启动服务:

启动服务:

[root@localhost ~]# systemctl start zabbix-agent.service

添加开机启动功能:

[root@localhost ~]# 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.

查看agent服务是否已启动:

[root@localhost ~]# ps -ef | grep zabbix
zabbix    2842     1  0 06:37 ?        00:00:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix    2843  2842  0 06:37 ?        00:00:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix    2844  2842  0 06:37 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix    2845  2842  0 06:37 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix    2846  2842  0 06:37 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix    2847  2842  0 06:37 ?        00:00:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root      2896  2435  0 06:38 pts/1    00:00:00 grep –color=auto zabbix
[root@localhost ~]#
[root@localhost ~]# ss -tnl | grep 10050
LISTEN     0      128          *:10050                    *:*                 
LISTEN     0      128         :::10050                   :::*                

如上,已发现agentd进程运行,并且10050端口已启动。

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

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

agentinstall06

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

agentinstall07

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

agentinstall08

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

agentinstall09

Leave a Reply