源码安装Zabbix

解压缩zabbix安装包

# tar -xvf zabbix-2.4.6.tar.gz 

安装zabbix需要依赖库

# yum -y install net-snmp-devel curl-devel
# yum -y install libxml2 libxml2-devel 

新建zabbix管理用户

# useradd -M -s /sbin/nologin zabbix

创建zabbix数据库

shell> mysql -uroot -p

#新建zabbix数据库
mysql> create database zabbix character set utf8 collate utf8_bin;  

#授权zabbxi使用zabbix这个数据库
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
mysql> quit;

#zabbix的数据库表结构
shell> mysql -uzabbix -p zabbix < database/mysql/schema.sql
# stop here if you are creating database for Zabbix proxy
shell> mysql -uzabbix -p zabbix < database/mysql/images.sql

#zabbix的数据库数据,将zabbix源码包中的数据导入到新建的zabbix数据库,这一步是zabbix2.0.13与旧版不同的地方,在版本2.0.13里数据库的结构和名字都变了,而且导入也要严格按照顺序来。
shell> mysql -uzabbix -p zabbix < database/mysql/data.sql

编译安装zabbix
configure the sources for a Zabbix server and agent

# ./configure --prefix=/zabbix --enable-server --enable-proxy --enable-agent --with-mysql --with-net-snmp  --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
# make && make install

--prefix指定zabbix安装目录,
--enable-server 支持zabbix服务器,
--enable-agent支持zabbix代理,
--enable-proxy 支持zabbix代理服务器,
--with-mysql 使用MySQL客户端库可以选择指定路径mysql_config,
--with-net-snmp 使用net - snmp软件包,择性地指定路径NET - SNMP配置, 
--with-libcurl 使用curl包。

若./configure 出现hecking for mysql_config... configure: error: MySQL library not found,可以使用find / -name "mysql_config"来查看mysql_config位置,用--with-mysql指定;
若./configure出现错误configure: error: Invalid NET-SNMP directory - unable to find net-snmp-config,可以通过yum install net-snmp-devel来解决。
若已安装net-snmp-devel却报error while loading shared libraries: libnetsnmp.so.30" 错误的原因和解决办法,可以通过find / -name libnetsnmp.so.30,查看libnetsnmp.so.30位置,将libnetsnmp.so.30位置添加到/etc/ld.so.conf,/sbin/ldconfig后,再编译即可

为zabbix server添加端口

# cat >> /etc/services <<eof
zabbix-agent    10050/tcp
zabbix-agent    10050/udp
zabbix-trapper  10051/tcp
zabbix-trapper  10051/udp

server端的配置

# vim /zabbix/etc/zabbix_server.conf   
#修改以下内容
LogFile=/var/log/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock   //如果配置不正确,zabbix会一直报connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'。即使mysql账号、权限是正确的,/var/lib/mysql/mysql.sock存在也是一样会报错。
DBPort=3306
# touch /var/log/zabbix_server.log
# chmod 777 /var/log/zabbix_*

client端的配置

# vim /zabbix/etc/zabbix_agentd.conf   
#修改以下内容
LogFile=/var/log/zabbix_agentd.log
Server=10.10.12.192
UnsafeUserParameters=1

# touch /var/log/zabbix_agentd.log
# chmod 777 /var/log/zabbix_*

启动服务配置
进入zabbix的解压目录

# cd misc/init.d/tru64
# cp zabbix_server /etc/init.d/
# cp zabbix_agentd /etc/init.d/
# chmod +x /etc/init.d/zabbix_*

# vi /etc/init.d/zabbix_server 
BASEDIR=/zabbix/  #实际zabbix的安装位置
# vi /etc/init.d/zabbix_agentd 
BASEDIR=/zabbix/  #实际zabbix的安装位置

设置开启自启动

# chkconfig --add zabbix_server
# chkconfig --add zabbix_agentd
# chkconfig zabbix_server on
# chkconfig zabbix_agentd on

安装zabbix的web接口
zabbix前台是php实现的,所以需要web服务器支持php解析

# yum install httpd
# yum install php
# vim /etc/php.ini  //修改以下地方
date.timezone = Asia/Shanghai
post_max_size = 32M
max_execution_time = 300
max_input_time = 300

# mkdir /var/www/html/zabbix
进入zabbix解压目录
[root@zabbix zabbix]# cd frontends/php/
[root@zabbix php]# cp -a . /var/www/html/zabbix/

通常建议将zabbix的web前端放到HTML根目录下的子目录中。

登录URL http://<server_ip_or_name>/zabbix进行安装

原文地址:https://www.cnblogs.com/abclife/p/4760460.html