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,
官網:https://www.zabbix.com/download?zabbix=4.0&os_distribution=centos&os_version=6&db=mysql
開始安裝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 ResolutionDependencies Resolved
===================================================================================================
Package Arch Version Repository Size
===================================================================================================
Installing:
zabbix-agent x86_64 4.0.2-1.el7 zabbix 384 kTransaction Summary
===================================================================================================
Install 1 PackageTotal 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/1Installed:
zabbix-agent.x86_64 0:4.0.2-1.el7Complete!
[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
完成后保存退出。
這是比較全面的配置,可以把vi /etc/zabbix/zabbix_agentd.conf文件內清空
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log #錯誤日志
LogFileSize=0
ListenPort=10050 #啟動監聽端口
StartAgents=3 #被動模式下選擇,主動模式則為0
ListenIP=0.0.0.0 #監聽所有IP
Server=10.27.146.250 #被動模式下必填,將zabbix-server端的ip填入
#ServerActive=10.27.146.250 #主動模式下填寫
Hostname=Api1Bearead #本機的hostname,此值必須與zabbix的網頁上創建的主機名一致即可
Include=/etc/zabbix/zabbix_agentd.d/
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主界面,選擇“配置‘->”主機“,點擊右上角的”創建“按扭,創建一台主機,如下圖
輸入主機名稱,群組選擇系統默認的Server hardware,agent代理接口IP設置剛才安裝agent的主機192.168.10.209,端口默認10050,如下圖:
再選擇”模板“選項欄,鏈接指示器里選擇”Template OS Linux“,點擊添加,最后點擊藍底添加按扭,完成添加。
完成后可以看到列表中已經有剛才不回的主機,過幾分鍾后,可用性一欄中的ZBX變綠即表示監控正常。