第二篇【Zabbix客户端的完整布署】

关于Zabbix服务端布署请查看

1、上传zabbix安装包(源码包默认(Server和Agent是一起的))

[root@sms-v2 ~]# ll /root/
-rw-r--r--  1 root root 20306084 11月 27 22:56 zabbix-4.4.3.tar.gz

2、安装依赖包

[root@sms-v2 ~]# yum install gcc gcc-c++ pcre-devel -y

3、创建运行用户

#创建组用户
[root@sms-v2 ~]# groupadd zabbix

#创建用户
[root@sms-v2 ~]# useradd -g zabbix -M -s /sbin/nologin zabbix

#检查是否创建成功
[root@sms-v2 ~]# id zabbix
uid=1002(zabbix) gid=1003(zabbix) 组=1003(zabbix)

 4、软件的安装

#解压软件
[root@sms-v2 ~]# tar xvf zabbix-4.4.3.tar.gz 

#进入软件安装目录
[root@sms-v2 ~]# cd zabbix-4.4.3/

#安装软件
[root@sms-v2 zabbix-4.4.3]# ./configure --prefix=/data/application/zabbix-4.4.3 --enable-agent

#编译安装
[root@sms-v2 zabbix-4.4.3]# make && make install

#安装完成的目录

[root@sms-v2 zabbix-4.4.3]# tree /data/application/zabbix-4.4.3/
/data/application/zabbix-4.4.3/
├── bin
│   ├── zabbix_get
│   └── zabbix_sender
├── etc
│   ├── zabbix_agentd.conf
│   └── zabbix_agentd.conf.d
├── lib
│   └── modules
├── sbin
│   └── zabbix_agentd
└── share
└── man
├── man1
│   ├── zabbix_get.1
│   └── zabbix_sender.1
└── man8
└── zabbix_agentd.8

 5、创建存放日志的目录

[root@sms-v2 zabbix-4.4.3]# mkdir /data/application/zabbix-4.4.3/log
[root@sms-v2 zabbix-4.4.3]# chown zabbix.zabbix /data/application/zabbix-4.4.3/log -R

 6、编译zabbix Agent配置文件

[root@sms-v2 zabbix-4.4.3]# vi /data/application/zabbix-4.4.3/etc/zabbix_agentd.conf
...
9 # Mandatory: no 10 # Default: 11 # PidFile=/tmp/zabbix_agentd.pid 12 PidFile=/data/application/zabbix-4.4.3/log/zabbix_agentd.pid 13 14 ### Option: LogType 15 # Specifies where log messages are written to: 16 # system - syslog 17 # file - file specified with LogFile parameter 18 # console - standard output ... 24 # Log file name for LogType 'file' parameter. 25 # 26 # Mandatory: yes, if LogType is set to file, otherwise no 27 # Default: 28 # LogFile= 29 30 LogFile=/data/application/zabbix-4.4.3/log/zabbix_agentd.log #日志文件位置 31 32 ### Option: LogFileSize 33 # Maximum size of log file in MB. 34 # 0 - disable automatic log rotation. 35 # 36 # Mandatory: no 37 # Range: 0-1024 38 # Default: 39 # LogFileSize=1 ... 83 ### Option: Server 84 # List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix servers and Zabbix proxies. 85 # Incoming connections will be accepted only from the hosts listed here. 86 # If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally 87 # and '::/0' will allow any IPv4 or IPv6 address. 88 # '0.0.0.0/0' can be used to allow any IPv4 address. 89 # Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com 90 # 91 # Mandatory: yes, if StartAgents is not explicitly set to 0 92 # Default: 93 # Server= 94 95 Server=127.0.0.1,,192.168.10.96 #Zabbix Server主动监控允许调用 96 97 ### Option: ListenPort 98 # Agent will listen on this port for connections from the server. 99 # ... 122 ##### Active checks related 123 124 ### Option: ServerActive 125 # List of comma delimited IP:port (or DNS name:port) pairs of Zabbix servers and Zabbix proxies for active checks. 126 # If port is not specified, default port is used. 127 # IPv6 addresses must be enclosed in square brackets if port for that host is specified. 128 # If port is not specified, square brackets for IPv6 addresses are optional. 129 # If this parameter is not specified, active checks are disabled. 130 # Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1] 131 # 132 # Mandatory: no 133 # Default: 134 # ServerActive= 135 136 ServerActive=192.168.10.96:10051 #Aget被动监控,即主机上传数据到Zabbix服务器 ... 138 ### Option: Hostname 139 # Unique, case sensitive hostname. 140 # Required for active checks and must match hostname as configured on the server. 141 # Value is acquired from HostnameItem if undefined. 142 # 143 # Mandatory: no 144 # Default: 145 # Hostname= 146 147 Hostname=192.168.10.95 #建议配置IP地址,主机名的话,怕解析延时 ... 271 ### Option: User 272 # Drop privileges to a specific, existing user on the system. 273 # Only has effect if run as 'root' and AllowRoot is disabled. 274 # 275 # Mandatory: no 276 # Default: 277 User=zabbix #运行Agent的用户 ... 279 ### Option: Include 280 # You may include individual files or all files in a directory in the configuration file. 281 # Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time. 282 # 283 # Mandatory: no 284 # Default: 285 # Include= 286 287 # Include=/usr/local/etc/zabbix_agentd.userparams.conf 288 # Include=/usr/local/etc/zabbix_agentd.conf.d/ 289 # Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf 290 Include=/data/application/zabbix-4.4.3/etc/zabbix_agentd.conf.d/*.conf #配置文件的位置 ...

  7、编写zabbix Agent启动服务

[root@sms-v2 init.d]# cat /etc/init.d/zabbix_agentd 
#!/bin/sh

##########################################################
###### Zabbix agent daemon init script
##########################################################

zabbix_agentd_sbin=/data/application/zabbix-4.4.3/sbin/zabbix_agentd
zabbix_etc=/data/application/zabbix-4.4.3/etc/zabbix_agentd.conf
PidFile=/data/application/zabbix-4.4.3/log/zabbix_agentd.pid

case $1 in

start)
        $zabbix_agentd_sbin -c $zabbix_etc ;;

stop)
        kill -TERM `cat $PidFile` ;;

restart)
        $0 stop
        sleep 10
        $0 start
        ;;

*)
        echo "Usage: $0 start|stop|restart"
        exit 1
esac
zabbix_agentd
#设置可执行权限
[root@sms-v2 ~]# chmod 755 /etc/init.d/zabbix_agentd

#zabbix agent开启、关闭、重启
[root@sms-v2 ~]# /etc/init.d/zabbix_agentd start
[root@sms-v2 ~]# /etc/init.d/zabbix_agentd stop
[root@sms-v2 ~]# /etc/init.d/zabbix_agentd restart

#这里需要开启zabbix agent服务

 8、查看zabbix agent日志

[root@sms-v2 ~]# tail -f /data/application/zabbix-4.4.3/log/zabbix_agentd.log 
 75987:20191224:101616.707 TLS support:            NO
 75987:20191224:101616.707 **************************
 75987:20191224:101616.707 using configuration file: /data/application/zabbix-4.4.3/etc/zabbix_agentd.conf
 75987:20191224:101616.707 agent #0 started [main process]
 75988:20191224:101616.708 agent #1 started [collector]
 75991:20191224:101616.709 agent #4 started [listener #3]
 75989:20191224:101616.710 agent #2 started [listener #1]
 75992:20191224:101616.710 agent #5 started [active checks #1]
 75990:20191224:101616.711 agent #3 started [listener #2]
 75992:20191224:101616.712 active check configuration update from [192.168.10.96:10051] started to fail (cannot connect to [[192.168.10.96]:10051]: [113] No route to host)
#这里的原因,因为zabbix服务端的端口没有在防火墙开放,导致agent连接不到服务端
#解决方法
#在zabbix服务端开放端口10051

[root@filestore-v2 ~]# firewall-cmd --permanent --add-port=10051/tcp
success
[root@filestore-v2 ~]# firewall-cmd --reload
success

再次查看日志

[root@sms-v2 ~]# tail -f /data/application/zabbix-4.4.3/log/zabbix_agentd.log
75987:20191224:101616.707 agent #0 started [main process]
75988:20191224:101616.708 agent #1 started [collector]
75991:20191224:101616.709 agent #4 started [listener #3]
75989:20191224:101616.710 agent #2 started [listener #1]
75992:20191224:101616.710 agent #5 started [active checks #1]
75990:20191224:101616.711 agent #3 started [listener #2]
75992:20191224:102216.927 active check configuration update from [192.168.10.96:10051] is working again  #问题是zabbix agent端连接到zabbix server端是正常
75992:20191224:102216.927 no active checks on server [192.168.10.96:10051]: host [192.168.10.95] not found #问题是zabbix server端连接到zabbix agent端不通,原因是agent端没有防火墙开放端口出来
#解决方法:在agent端的服务器操作如下

[root@sms-v2 ~]# firewall-cmd --permanent --add-port=10050/tcp
success
[root@sms-v2 ~]# firewall-cmd --reload
success

 9、在zabbix服务端利用自带的工具zabbix_get获取agent端的数据

#查看命令的使用方法
[root@filestore-v2 ~]# /data/application/zabbix-4.4.3/bin/zabbix_get --help
usage:
  zabbix_get -s host-name-or-IP [-p port-number] [-I IP-address] -k item-key
  zabbix_get -h
  zabbix_get -V
General options:
  -s --host host-name-or-IP  获取数据的IP地址
  -p --port port-number      获取数据的端口 (默认端口: 10050)
  -I --source-address IP-address   指定该数据往哪个网口出去,这里主要是涉及多网卡的时候使用
  -k --key item-key          指定监控项的key值
  -h --help                       查看帮忙文档
  -V --version                   显示当前agent版本

#获取主机CPU负载
[root@filestore-v2 ~]# /data/application/zabbix-4.4.3/bin/zabbix_get -s 192.168.10.95 -k "system.cpu.load[all,avg1]"
0.140000

#获取当前主机名
[root@filestore-v2 ~]# /data/application/zabbix-4.4.3/bin/zabbix_get -s 192.168.10.95 -k system.uname
Linux sms-v2 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64

猜你喜欢

转载自www.cnblogs.com/ygbh/p/12083944.html