首页 Linux正文

编译安装zabbix 3.4

王昊 Linux 2019-07-31 277 0

实验环境:CentOS 7.2、Apache 2.4.38MySQL 5.7.25PHP 7.3.7

建立zabbix数据库

mysql> CREATE DATABASE zabbix;

授权

mysql> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'abc123';

mysql> GRANT all ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'abc123';

刷新权限

mysql> flush privileges;

重启mysql服务

systemctl restart mysqld

vim /usr/local/apache/htdocs/index.php

<?php
$link=mysqli_connect('localhost','zabbix','abc123');
if($link) echo "<h1>Success</h1>";
else echo "Fail!!";
?>

systemctl restart httpd

访问测试:

只显示 Success 不显示 php 代码表示测试成功

安装相关依赖

cd /usr/local

yum -y install net-snmp-devel libxml2-devel libcurl-devel libevent libevent-devel

wget http://prdownloads.sourceforge.net/zabbix/zabbix-3.4.5.tar.gz

tar xf zabbix-3.4.5.tar.gz

cd zabbix-3.4.5

./configure \
-prefix=/usr/local/zabbix \
-enable-server \
-enable-agent \
-with-mysql \
-enable-ipv6 \
-with-net-snmp \
-with-libcurl \
-with-libxml2

make && make install

创建zabbix用户和用户组:

groupadd zabbix

useradd -g zabbix zabbix

chown -R zabbix:zabbix /usr/local/zabbix/

导入表结构

注意:导入的顺序不能更改

mysql> use zabbix;
mysql> source /usr/local/zabbix-3.4.5/database/mysql/schema.sql;
mysql> source /usr/local/zabbix-3.4.5/database/mysql/images.sql;
mysql> source /usr/local/zabbix-3.4.5/database/mysql/data.sql;

创建日志目录

cd /usr/local/zabbix/

mkdir log

chown -R zabbix:zabbix logs

修改配置文件

vim ./etc/zabbix_server.conf

在配置文件中,查找并按实际情况修改以下参数的内容

LogFile=/usr/local/zabbix/logs/zabbix_server.log 
PidFile=/tmp/zabbix_server.pid 
DBHost=localhost 
DBName=zabbix 
DBUser=zabbix 
DBPassword=abc123 
DBSocket=/usr/local/mysql/mysql.sock 
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf

vim ./etc/zabbix_agentd.conf

在配置文件中,查找并按实际情况修改以下参数的内容

PidFile=/tmp/zabbix_agentd.pid 
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log 
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf

启动 zabbix_server 服务

/usr/local/zabbix/sbin/zabbix_server

错误提示:

/usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

解决方法:

[root@localhost zabbix]# find / -name libmysqlclient.so.20
/usr/local/mysql-5.7.25/libmysql/libmysqlclient.so.20
/usr/local/mysql/lib/libmysqlclient.so.20
[root@localhost zabbix]# echo "/usr/local/mysql/lib" >> /etc/ld.so.conf
[root@localhost zabbix]# ldconfig

再次启动,问题解决

/usr/local/zabbix/sbin/zabbix_server

启动 zabiix_agent 服务

/usr/local/zabbix/sbin/zabbix_agentd

把zabbix添加到系统服务里

cp /usr/local/zabbix-3.4.5/misc/init.d/fedora/core/zabbix_* /etc/init.d/

vim /etc/init.d/zabbix_server

按实际安装位置来修改,例如

BASEDIR=/usr/local/zabbix

vim /etc/init.d/zabbix_agentd

同上

BASEDIR=/usr/local/zabbix

拷贝WEB应用程序

mv /usr/local/zabbix-3.4.5/frontends/php/* /usr/local/apache/htdocs/

浏览器访问:

http://服务器IP/setup.php

web界面的配置我们在下一篇博客中会有详细介绍:zabbix3.4 web界面的配置

版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论