最新公司需要上一套监控系统,一番调研下来,决定使用zabbix,下班时间搭了一套出来,过程如下

环境如下

OS CentOS6.5
zabbix 4.0 4.0.2
apche 1.3.12或以上
mysql 5.0.3或以上 5.1.73
php 5.4.0或以上 5.6

建议先搭建lamp环境,环境搭建好之后再安装zabbix
因为整个zabbix安装下来依赖包很多,所以环境的搭建采取yum方式


lamp坏境搭建

1.appche安装

yum install -y httpd httpd-devel

2.mysql安装

yum install mysql* -y
service mysqld start                                                     #启动mysql
mysqladmin  -u root password 2018                           #设置mysql root 密码
mysql -uroot -p2018                                              #登录mysql
mysql>create database zabbix character set utf8 collate utf8_bin;   #创建数据库zabbix
mysql>grant all privileges on zabbix.* to zabbix@localhost identified by '2018';       #新增账号zabbix,密码为2018并授权访问数据库zabbix
mysql>flush privileges;      
mysql>SHOW DATABASES;                            #show 查看数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
| zabbix             |
+--------------------+
4 rows in set (0.02 sec)

service mysqld restart                             #重启mysql服务

3.php安装

rpm -qa | greo php                      #查看已安装php版本,如果低于最低要求则删除
yum  remove php*                                                               #删除自带php
yum list  php*      #查看yum源上是否有自己需要的版本,没有就添加第三方yum源
rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpmyum -y install  php56w php56w-gd php56w-mysqlnd php56w-bcmath php56w-mbstring php56w-xml php56w-ldap    
vim /etc/php.ini                                                                        #编辑配置文件
post_max_size = 16M                                                       #zabbix必填参数
max_execution_time = 300                                                    #zabbix必填参数
max_input_time = 300
date.timezone = Asia/Shanghai                                               #zabbix必填参数
always_populate_raw_post_data = -1                                       #zabbix参数

以上就是lamp 环境的前期准备工作

zabbix的编译安装

./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --enable-java --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --with-ssh2 --with-openipmi --with-openssl --prefix=/usr/local/zabbix    #根据实际需求,安装先关组件

部分报错及解决方案
(1)configure: error: LIBXML2 library not found
yum install libxml2-devel -y
(2)configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
yum install net-snmp* -y
(3)configure: error: SSH2 library not found
 yum install libssh2-devel  -y
(4)configure: error: Invalid OPENIPMI directory - unable to find ipmiif.h
 yum install OpenIPMI  OpenIPMI-devel -y
(5)configure: error: Unable to use libevent (libevent check failed)
 yum install libevent-devel -y 
(6)configure: error: Unable to find "javac" executable in path
 yum install java* -y 
(7)configure: error: Curl library not found
 yum install curl-devel -y  
(8)configure: error: Unable to use libpcre (libpcre check failed)
 yum -y install pcre*
 (9)checking for cc... no
checking for c99... no
checking for gcc... no
 yum -y install gcc libc

出现以下界面,表示配置成功 
 ***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*                                  *
***********************************************************

make            #可以直接make install 
make[3]: *** [libzbxdbhigh_a-odbc.o] Error 1
make[3]: Leaving directory `/home/zabbix-3.4.15/src/libs/zbxdbhigh'
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory `/home/zabbix-3.4.15/src/libs'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/home/zabbix-3.4.15/src'
make: *** [install-recursive] Error 1

yum install unixODBC-devel  -y  

make  install                                      #没有报错表示安装成功

下面进行配置

mysql:

cd  /home/zabbix-3.4.15/database/mysql                #将zabbix的数据库表导入mysql
mysql -uroot -p2018 zabbix < schema.sql
mysql -uroot -p2018 zabbix < images.sql
mysql -uroot -p2018 zabbix < data.sql

mysql -uroot -p2018
>use zabbix;
>show tables;                                                            #可查看到添加的一系列表格
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |

zabbix配置:

mkdir /var/log/zabbix  -p                                          #创建log目录
chown zabbix  zabbix                                            #修改log目录权限
vim /usr/local/zabbix/etc/zabbix_server.conf         #修改zabix_server配置文件
LogFile=/var/log/zabbix/zabbix_server.log         #log文件存放文职(可选参数)
DBName=zabbix                                                            #数据库名称(必填参数)
DBUser=zabbix                                                            #用户(必填参数)
DBPassword=2018                                                #数据库密码(必填参数)                           

mkdir /var/www/html/zabbix   
cp frontends/php/ /var/www/html/zabbix/  -a   #将zabbix的php文件放到httpd默认发布目录下
chown -R apache:apache /var/www/html/zabbix      #设置apache的执行和所有者
chmod +x /var/www/html/zabbix/php/conf/ -R                 #赋予可执行权限

vim /etc/httpd/conf/httpd.conf    
DocumentRoot "/var/www/html/zabbixphp"

ServerName 127.0.0.1
DirectoryIndex index.html index.html.var index.php

vim /etc/services
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper

service iptables stop    #关闭防火墙或者开放相应端口10050 10051 80 3006
setenforce 0                                                           #临时关闭selinux

service mysqld restart
service httpd restart
./usr/local/zabbix/etc/zabbix_server

访问网页 http://172.16.9.1
默认账号:Admin zabbix
更改zabbix默认语言为中文,替换监控图像上系统默认中文字体

大概过程以上,后期空了再来修复