Ubuntu操作系统部署zabbix agent服务
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.下载zabbix软件包
博主推荐阅读: https://www.cnblogs.com/yinzhengjie2020/p/12305427.html
二.编译安装agent
1>.将下载的软件包上传到服务器上
[root@mysql202.yinzhengjie.org.cn ~]# cd /usr/local/src/ [root@mysql202.yinzhengjie.org.cn /usr/local/src]# [root@mysql202.yinzhengjie.org.cn /usr/local/src]# ll total 8 drwxr-xr-x 2 root root 4096 Aug 5 2019 ./ drwxr-xr-x 10 root root 4096 Aug 5 2019 ../ [root@mysql202.yinzhengjie.org.cn /usr/local/src]# [root@mysql202.yinzhengjie.org.cn /usr/local/src]# rz [root@mysql202.yinzhengjie.org.cn /usr/local/src]# [root@mysql202.yinzhengjie.org.cn /usr/local/src]# ll total 16800 drwxr-xr-x 2 root root 4096 Feb 14 12:52 ./ drwxr-xr-x 10 root root 4096 Aug 5 2019 ../ -rw-r--r-- 1 root root 17191889 Feb 14 01:20 zabbix-4.0.17.tar.gz [root@mysql202.yinzhengjie.org.cn /usr/local/src]#
2>.解压软件包

[root@mysql202.yinzhengjie.org.cn /usr/local/src]# ll total 16800 drwxr-xr-x 2 root root 4096 Feb 14 12:52 ./ drwxr-xr-x 10 root root 4096 Aug 5 2019 ../ -rw-r--r-- 1 root root 17191889 Feb 14 01:20 zabbix-4.0.17.tar.gz [root@mysql202.yinzhengjie.org.cn /usr/local/src]# [root@mysql202.yinzhengjie.org.cn /usr/local/src]# tar zxf zabbix-4.0.17.tar.gz [root@mysql202.yinzhengjie.org.cn /usr/local/src]# [root@mysql202.yinzhengjie.org.cn /usr/local/src]# ll total 16804 drwxr-xr-x 3 root root 4096 Feb 14 12:56 ./ drwxr-xr-x 10 root root 4096 Aug 5 2019 ../ drwxr-xr-x 13 1001 1001 4096 Jan 28 14:36 zabbix-4.0.17/ -rw-r--r-- 1 root root 17191889 Feb 14 01:20 zabbix-4.0.17.tar.gz [root@mysql202.yinzhengjie.org.cn /usr/local/src]# [root@mysql202.yinzhengjie.org.cn /usr/local/src]#
3>.安装依赖环境
[root@mysql202.yinzhengjie.org.cn ~]# apt-get -y install libpcre3 libpcre3-dev gcc make
4>.配置zabbix agent的安装参数

[root@mysql202.yinzhengjie.org.cn /usr/local/src]# ll total 16804 drwxr-xr-x 3 root root 4096 Feb 14 12:56 ./ drwxr-xr-x 10 root root 4096 Aug 5 2019 ../ drwxr-xr-x 13 1001 1001 4096 Jan 28 14:36 zabbix-4.0.17/ -rw-r--r-- 1 root root 17191889 Feb 14 01:20 zabbix-4.0.17.tar.gz [root@mysql202.yinzhengjie.org.cn /usr/local/src]# [root@mysql202.yinzhengjie.org.cn /usr/local/src]# cd zabbix-4.0.17/ [root@mysql202.yinzhengjie.org.cn /usr/local/src/zabbix-4.0.17]# [root@mysql202.yinzhengjie.org.cn /usr/local/src/zabbix-4.0.17]# ll total 1748 drwxr-xr-x 13 1001 1001 4096 Jan 28 14:36 ./ drwxr-xr-x 3 root root 4096 Feb 14 12:56 ../ -rw-r--r-- 1 1001 1001 54052 Jan 28 14:36 aclocal.m4 -rw-r--r-- 1 1001 1001 98 Jan 28 14:36 AUTHORS drwxr-xr-x 4 1001 1001 4096 Jan 28 14:36 bin/ drwxr-xr-x 4 1001 1001 4096 Jan 28 14:36 build/ -rw-r--r-- 1 1001 1001 991575 Jan 28 14:36 ChangeLog -rwxr-xr-x 1 1001 1001 7333 Jan 25 2017 compile* drwxr-xr-x 3 1001 1001 4096 Jan 28 14:36 conf/ -rwxr-xr-x 1 1001 1001 43940 Nov 12 2016 config.guess* -rwxr-xr-x 1 1001 1001 36339 Nov 12 2016 config.sub* -rwxr-xr-x 1 1001 1001 402710 Jan 28 14:36 configure* -rw-r--r-- 1 1001 1001 56757 Jan 28 14:36 configure.ac -rw-r--r-- 1 1001 1001 17990 Jan 28 14:36 COPYING drwxr-xr-x 8 1001 1001 4096 Jan 28 14:36 database/ -rwxr-xr-x 1 1001 1001 23566 Jan 25 2017 depcomp* drwxr-xr-x 3 1001 1001 4096 Jan 28 14:36 frontends/ drwxr-xr-x 2 1001 1001 4096 Jan 28 14:36 include/ -rw-r--r-- 1 1001 1001 82 Jan 28 14:36 INSTALL -rwxr-xr-x 1 1001 1001 15155 Jan 25 2017 install-sh* drwxr-xr-x 2 1001 1001 4096 Jan 28 14:36 m4/ -rw-r--r-- 1 1001 1001 6278 Jan 28 14:36 Makefile.am -rw-r--r-- 1 1001 1001 36024 Jan 28 14:36 Makefile.in drwxr-xr-x 2 1001 1001 4096 Jan 28 14:36 man/ drwxr-xr-x 5 1001 1001 4096 Jan 28 14:36 misc/ -rwxr-xr-x 1 1001 1001 6872 Jan 25 2017 missing* -rw-r--r-- 1 1001 1001 52 Jan 28 14:36 NEWS -rw-r--r-- 1 1001 1001 1317 Jan 28 14:36 README drwxr-xr-x 4 1001 1001 4096 Jan 28 14:36 sass/ drwxr-xr-x 10 1001 1001 4096 Jan 28 14:36 src/ [root@mysql202.yinzhengjie.org.cn /usr/local/src/zabbix-4.0.17]#
[root@mysql202.yinzhengjie.org.cn /usr/local/src/zabbix-4.0.17]# ./configure --prefix=/yinzhengjie/softwares/zabbix --enable-agent
5>.编译并安装
[root@mysql202.yinzhengjie.org.cn /usr/local/src/zabbix-4.0.17]# make -j 2 && make install
6>.编写zabbix agent的启动脚本
博主推荐阅读: https://www.cnblogs.com/yinzhengjie2020/p/12306215.html
三.手动启动zabbix agent程序
1>.修改zabbix agent的配置文件,指定zabbix server地址
[root@mysql202.yinzhengjie.org.cn ~]# cp /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf-`date +%F` #修改配置文件之前别忘记先备份文件

[root@mysql202.yinzhengjie.org.cn ~]# grep ^Server= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf Server=127.0.0.1 [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]# sed -r -i 's#(Server=)127.0.0.1#1172.200.5.203#' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]# grep ^Server= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf Server=172.200.5.203 [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]#

[root@mysql202.yinzhengjie.org.cn ~]# grep ^Hostname= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf Hostname=Zabbix server [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]# sed -r -i 's#(Hostname=)Zabbix server#1mysql202.yinzhengjie.org.cn#' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]# grep ^Hostname= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf Hostname=mysql202.yinzhengjie.org.cn [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]#
2>.修改zabbix的守护进程为root用户(默认是zabbix用户)

[root@mysql202.yinzhengjie.org.cn ~]# grep User= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf # User=zabbix [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]# sed -r -i 's@# (User=)zabbix@1root@' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]# grep User= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf User=root [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]#

[root@mysql202.yinzhengjie.org.cn ~]# grep AllowRoot= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf # AllowRoot=0 [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]# sed -r -i 's@# (AllowRoot=)0@11@' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]# grep AllowRoot= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf AllowRoot=1 [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]#
3>.启动zabbix agent服务

[root@mysql202.yinzhengjie.org.cn ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 80 172.200.5.202:3306 0.0.0.0:* LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 80 172.200.5.202:3306 0.0.0.0:* LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 0.0.0.0:10050 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* [root@mysql202.yinzhengjie.org.cn ~]# [root@mysql202.yinzhengjie.org.cn ~]#