zabbix—环境搭建:server&agent安装

Posted 龙叔运维

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix—环境搭建:server&agent安装相关的知识,希望对你有一定的参考价值。

这里讲解的是在centos下zabbix环境的源码安装(本文是zabbix-4.4.1)

我喜欢源码安装,因为更便于管理,这里也只讲安装,至于配置文件,和如何使用等等,我会慢慢写别的博客讲解

 

安装包下载地址:下载Zabbix

 

1·Server

1.1·安装

将安装包传到服务器上

然后进入到安装包目录中:cd zabbix-4.4.1/

1.1.1·环境准备

【1】在安装zabbix之前,你要把基础环境安装好,包括:httpd、phpmysql、编译环境等

【2】创建zabbix用户和组:

groupadd zabbix

useradd -g zabbix zabbix

【3】mysql数据库配置:

·账号密码的创建就不多讲了

·创建zabbix库:CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_general_ci;

·执行初始化脚本,mysql的脚本在zabbix安装目录如下路径(需要执行三个sql文件)

/root/zabbix/Zabbix4.4.1-install/zabbix-4.4.1/database/mysql

mysql -uroot -p123456 zabbix < schema.sql

mysql -uroot -p123456 zabbix < images.sql

mysql -uroot -p123456 zabbix < data.sql

1.1.2·编译安装

在zabbix安装目录下执行:

./configure  \\
        --prefix=/usr/local/zabbix  \\
        --enable-server  \\
        --enable-agent  \\
        --with-mysql=/usr/bin/mysql_config   \\
        --with-net-snmp  \\
        --with-libcurl  \\
        --with-libxml2  \\
        --enable-java  
 
make -j 2 && make install 
 

1.2·配置

【1】拷贝启动文件到/etc/init.d/下:

cp misc/init.d/fedora/core/* /etc/init.d/

【2】编辑启动模块:

sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#" /etc/init.d/zabbix_server
sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#" /etc/init.d/zabbix_agentd

【3】设置开机启动:

systemctl enable zabbix_agentd

 

1.3·启动

#启动zabbix服务

/etc/init.d/zabbix_server restart
/etc/init.d/zabbix_agentd restart
 #重启验证服务
systemctl restart zabbix_server 
systemctl restart zabbix_agentd

启动后 就可以看到zabbix进程了

[root@wxl-1 zabbix-4.4.1]# ps -ef |grep zabbix |grep -v grep
zabbix     1008      1  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd
zabbix     1033   1008  0 22:31 ?        00:00:01 /usr/local/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix     1034   1008  0 22:31 ?        00:00:01 /usr/local/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix     1035   1008  0 22:31 ?        00:00:01 /usr/local/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix     1036   1008  0 22:31 ?        00:00:01 /usr/local/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix     1037   1008  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
zabbix     1139      1  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server
zabbix     1356   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: configuration syncer [synced configuration in 0.042270 sec, idle 60 sec]
zabbix     1357   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: housekeeper [deleted 95 hist/trends, 0 items/triggers, 32 events, 0 sessions, 0 alarms, 0 audit items,
zabbix     1358   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: timer #1 [updated 0 hosts, suppressed 0 events in 0.000392 sec, idle 59 sec]
zabbix     1359   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: http poller #1 [got 0 values in 0.000428 sec, idle 5 sec]
zabbix     1360   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.000979 sec, idle 60 sec]
zabbix     1361   1139  0 22:31 ?        00:00:01 /usr/local/zabbix/sbin/zabbix_server: history syncer #1 [processed 0 values, 0 triggers in 0.000015 sec, idle 1 sec]
zabbix     1362   1139  0 22:31 ?        00:00:01 /usr/local/zabbix/sbin/zabbix_server: history syncer #2 [processed 2 values, 2 triggers in 0.001427 sec, idle 1 sec]
zabbix     1363   1139  0 22:31 ?        00:00:01 /usr/local/zabbix/sbin/zabbix_server: history syncer #3 [processed 0 values, 0 triggers in 0.000048 sec, idle 1 sec]
zabbix     1364   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #4 [processed 0 values, 0 triggers in 0.000024 sec, idle 1 sec]
zabbix     1365   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.001308 sec, idle 3 sec]
zabbix     1366   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000020 sec, idle 5 sec]
zabbix     1367   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: self-monitoring [processed data in 0.000019 sec, idle 1 sec]
zabbix     1368   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: task manager [processed 0 task(s) in 0.000205 sec, idle 5 sec]
zabbix     1369   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #1 [got 2 values in 0.000357 sec, idle 2 sec]
zabbix     1370   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #2 [got 0 values in 0.000027 sec, idle 2 sec]
zabbix     1371   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #3 [got 0 values in 0.000013 sec, idle 2 sec]
zabbix     1372   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #4 [got 0 values in 0.000033 sec, idle 2 sec]
zabbix     1373   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #5 [got 0 values in 0.000010 sec, idle 2 sec]
zabbix     1374   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000022 sec, idle 5 sec]
zabbix     1375   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection]
zabbix     1376   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection]
zabbix     1377   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection]
zabbix     1378   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #4 [processed data in 0.001599 sec, waiting for connection]
zabbix     1379   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection]
zabbix     1380   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000031 sec, idle 5 sec]
zabbix     1381   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: alert manager #1 [sent 0, failed 0 alerts, idle 5.010197 sec during 5.010352 sec]
zabbix     1382   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: alerter #1 started
zabbix     1383   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: alerter #2 started
zabbix     1384   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: alerter #3 started
zabbix     1385   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: preprocessing manager #1 [queued 0, processed 16 values, idle 5.005431 sec during 5.005692 sec]
zabbix     1386   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: preprocessing worker #1 started
zabbix     1387   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: preprocessing worker #2 started
zabbix     1388   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: preprocessing worker #3 started
zabbix     1389   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: lld manager #1 [processed 0 LLD rules during 5.006161 sec]
zabbix     1390   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: lld worker #1 [processed 1 LLD rules, idle 2065.603648 sec during 2065.631210 sec]
zabbix     1391   1139  0 22:31 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server: lld worker #2 [processed 1 LLD rules, idle 1536.026289 sec during 1536.053847 sec]
zabbix     1392   1139  0 22:31 ?        00:00:01 /usr/local/zabbix/sbin/zabbix_server: alert syncer [queued 0 alerts(s), flushed 0 result(s) in 0.000400 sec, idle 1 sec]
 

 

2·Agent

2.1·安装

将安装包传到服务器上

然后进入到安装包目录中:cd zabbix-4.4.1/

./configure   --prefix=/usr/local/zabbix --enable-agent  

报错1:configure: error: no acceptable C compiler found in $PATH
解决1:yum install gcc -y

 

报错2:configure: error: Unable to use libpcre (libpcre check failed)

解决2: yum -y install pcre*

编译成功如下:

 

然后

make -j 2 && make install 

 

2.2·配置

2.2.1·创建用户

useradd zabbix
passwd zabbix

不然启动会报错

2.2.2·开机自启动

拷贝启动文件到/etc/init.d/下:

cp misc/init.d/fedora/core/* /etc/init.d/

编辑启动模块:

sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#" /etc/init.d/zabbix_agentd

设置开机启动:

systemctl enable zabbix_agentd

 

2.2.3·启动

/etc/init.d/zabbix_agentd start

/etc/init.d/zabbix_agentd restart

就可以看到zabbix-agent的进程了

[root@wxl-2 zabbix]# ps -ef |grep zabbix |grep -v grep
zabbix    15144      1  0 00:05 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd
zabbix    15145  15144  0 00:05 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix    15146  15144  0 00:05 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix    15147  15144  0 00:05 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix    15148  15144  0 00:05 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix    15149  15144  0 00:05 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
 

 

推荐公众号,分享运维知识:龙叔18岁

 

 

 

以上是关于zabbix—环境搭建:server&agent安装的主要内容,如果未能解决你的问题,请参考以下文章

zabbix服务器搭建

Zabbix 监控 AlwaysOn

zabbix环境安装搭建

zabbix server

Zabbix监控搭建

zabbix-server搭建