Centos6.5安装Zabbix-3.2.4

从网上看过N篇教程,编译安装不仅复杂费时又各种出错,无奈选择LNMP一键安装包,解决所有问题。用的是lnmp.org提供的lamp一体包,现已成功安装,做个笔记,记录过程以便学习和查看。

一、简述过程

我的系统是Centos6.5最小化安装的,selinux的安全机制有时会影响我们正常安装软件,首先我先将它关了然后在安装

1.禁用selinux
[root@cloud ~]# setenforce 0    #配置立即生效
[root@cloud ~]# sed -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config
2.安装LNMP
[root@cloud ~]# yum -y install screen wget    #安装screen(中断可运行 screen -r 重连)
[root@cloud ~]# screen -S lnmp                #建立一个lnmp作业
[root@cloud ~]# wget -c http://soft.vpser.NET/lnmp/lnmp1.3-full.tar.gz && tar zxf lnmp1.3-full.tar.gz && cd lnmp1.3-full && ./install.sh lnmp  

+------------------------------------------------------------------------+
|          LNMP V1.3 for CentOS Linux Server, Written by Licess          |
+------------------------------------------------------------------------+
|        A tool to auto-compile & install LNMP/LNMPA/LAMP on Linux       |
+------------------------------------------------------------------------+
|          For more information please visit http://www.lnmp.org         |
+------------------------------------------------------------------------+
Please setup root password of MySQL.(Default password: root)     #设置Mysql密码 
Please enter: 
Please enter: 123456
MySQL root password: 123456
===========================
Do you want to enable or disable the InnoDB Storage Engine?
Default enable,Enter your choice [Y/n]: y
You will enable the InnoDB Storage Engine
===========================
You have 5 options for your DataBase install.
1: Install MySQL 5.1.73
2: Install MySQL 5.5.48 (Default)
3: Install MySQL 5.6.29
4: Install MariaDB 5.5.48
5: Install MariaDB 10.0.23
6: Install MySQL 5.7.11
Enter your choice (1, 2, 3, 4, 5 or 6): 3
You will Install MySQL 5.6.29
===========================
You have 6 options for your PHP install.
1: Install PHP 5.2.17
2: Install PHP 5.3.29
3: Install PHP 5.4.45 (Default)
4: Install PHP 5.5.36
5: Install PHP 5.6.22
6: Install PHP 7.0.7
Enter your choice (1, 2, 3, 4, 5 or 6): 5
You will install PHP 5.6.22
===========================
You have 3 options for your Memory Allocator install.
1: Don't install Memory Allocator. (Default)
2: Install Jemalloc
3: Install TCMalloc
Enter your choice (1, 2 or 3): 1
You will install not install Memory Allocator.

Press any key to install...or Press Ctrl+c to cancel

到此按回车静静的等带LNMP安装好即可
完成安装后显示:Nginex:OK,Mysql:OK,PHP:OK

3.安装zabbix环境支持包
[root@cloud ~]# yum -y install mysql-devel net-snmp-devel curl curl-devel
4.创建zabbix运行所需要的用户权限
[root@cloud ~]# groupadd  -g 201  zabbix
[root@cloud ~]# useradd  -g zabbix  -u 201 -m zabbix
5.下载安装zabbix
[root@cloud ~]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.4/zabbix-3.2.4.tar.gz --no-check-certificate 
[root@cloud ~]# tar zxf zabbix-3.2.4.tar.gz
[root@cloud ~]# cd zabbix-3.2.4/
[root@cloud zabbix-3.2.4]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --enable-ipv6 --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2
...  ... 
***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

[root@cloud zabbix-3.2.4]# make && make install

[root@cloud zabbix-3.2.4]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/  #添加系统软链接
[root@cloud zabbix-3.2.4]# ln -s /usr/local/zabbix/bin/* /usr/local/bin/    #添加系统软链接
[root@cloud zabbix-3.2.4]# ln -s /usr/local/zabbix/etc/   /etc/zabbix

[root@cloud zabbix-3.2.4]# sed -i '$a\zabbix-agent    10050/tcp               # Zabbix Agent' /etc/services  
[root@cloud zabbix-3.2.4]# sed -i '$a\zabbix-agent    10050/udp               # Zabbix Agent' /etc/services
[root@cloud zabbix-3.2.4]# sed -i '$a\zabbix-trapper  10051/tcp               # Zabbix Trapper' /etc/services
[root@cloud zabbix-3.2.4]# sed -i '$a\zabbix-trapper  10051/udp               # Zabbix Trapper' /etc/services

[root@cloud zabbix-3.2.4]# tail -n 10 /etc/services             #查看确认下
blp5            48129/tcp               # Bloomberg locator
blp5            48129/udp               # Bloomberg locator
com-bardac-dw   48556/tcp               # com-bardac-dw
com-bardac-dw   48556/udp               # com-bardac-dw
iqobject        48619/tcp               # iqobject
iqobject        48619/udp               # iqobject
zabbix-agent    10050/tcp               # Zabbix Agent
zabbix-agent    10050/udp               # Zabbix Agent
zabbix-trapper  10051/tcp               # Zabbix Trapper
zabbix-trapper  10051/udp               # Zabbix Trapper
zabbix_server 服务端配置
[root@rbtnode1 zabbix-3.2.4]# cat /etc/zabbix/zabbix_server.conf|egrep -v '^#|^$'   
ListenPort=10051
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=100
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=192.168.86.89
DBName=zabbix
DBUser=zabbix
DBPassword=Pwd@123
DBSocket=/tmp/mysql.sock
DBPort=3306
StartPollers=80
StartPollersUnreachable=40
StartTrappers=32
StartPingers=30
StartDiscoverers=1
StartHTTPPollers=5
StartTimers=10
ListenIP=0.0.0.0
HousekeepingFrequency=12
MaxHousekeeperDelete=1000
CacheSize=512M
StartDBSyncers=8
HistoryCacheSize=64M
HistoryIndexCacheSize=32M
TrendCacheSize=64M
Timeout=30
TrapperTimeout=300
AlertScriptsPath=/usr/local/zabbix/alertscripts
FpingLocation=/usr/sbin/fping
Fping6Location=/usr/sbin/fping6
LogSlowQueries=3000
StartProxyPollers=5
ProxyConfigFrequency=600
ProxyDataFrequency=20
[root@rbtnode1 zabbix-3.2.4]# 
zabbix_agentd 客户端配置
[root@rbtnode1 zabbix-3.2.4]# cat /etc/zabbix/zabbix_agentd.conf|egrep -v '^#|^$'   
LogFile=/var/log/zabbix/zabbix_agentd.log
Server=192.168.86.89
ServerActive=192.168.86.89:10051
Hostname=Zabbix
BufferSize=1000
Timeout=30
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
UnsafeUserParameters=1
[root@rbtnode1 zabbix-3.2.4]# 
[root@rbtnode1 zabbix-3.2.4]# mkdir -p /var/log/zabbix  /var/run/zabbix
[root@rbtnode1 zabbix-3.2.4]# chown  -R zabbix:zabbix /var/log/zabbix
[root@rbtnode1 zabbix-3.2.4]# chown  -R zabbix:zabbix /var/run/zabbix

[root@cloud zabbix-3.2.4]# cp misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server       #添加服务端开机启动脚本
[root@cloud zabbix-3.2.4]# cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd       #添加客户端开机启动脚本
[root@cloud zabbix-3.2.4]# chmod +x /etc/rc.d/init.d/zabbix_server       #添加脚本执行权限 +x
[root@cloud zabbix-3.2.4]# chmod +x /etc/rc.d/init.d/zabbix_agentd       #添加脚本执行权限 +x

[root@cloud zabbix-3.2.4]# vim /etc/rc.d/init.d/zabbix_server        #编辑服务端配置文件  :设置zabbix安装目录
 BASEDIR=/usr/local/zabbix/
[root@cloud zabbix-3.2.4]# vim /etc/rc.d/init.d/zabbix_agentd        #编辑客户端配置文件  :设置zabbix安装目录
 BASEDIR=/usr/local/zabbix/       
6.导入数据库文件
[root@cloud zabbix-3.2.4]# mysql -u root -p123456
mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on zabbix.* to 'zabbix'@'localhost' identified by '123456' with grant option;
mysql> grant all on zabbix.* to 'zabbix'@'ip' identified by '123456' with grant option;
Query OK, 0 rows affected (0.03 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit

[root@cloud zabbix-3.2.4]# mysql -uzabbix -p123456 zabbix<./database/mysql/schema.sql
[root@cloud zabbix-3.2.4]# mysql -uzabbix -p123456 zabbix<./database/mysql/images.sql
[root@cloud zabbix-3.2.4]# mysql -uzabbix -p123456 zabbix<./database/mysql/data.sql

[root@cloud zabbix-3.2.4]# cd frontends/
[root@cloud frontends]# cp -rf php/ /home/wwwroot/zabbix        #配置WEB站点
[root@cloud frontends]# chown -R www.www /home/wwwroot/zabbix/

[root@cloud frontends]#
7.域名设置等
[root@cloud ~]# lnmp vhost add

================================================
Virtualhost infomation:
Your domain: 192.168.31.185
Home Directory: /home/wwwroot/zabbix/
Rewrite: none
Enable log: yes
Create database: no
Create ftp account: no
================================================
[root@cloud ~]# 

到此打开浏览器输入IP即可访问zabbix.setup界面
但还会有错误提示可根据该方法调整下参数:


- 1.max_input_time问题:

[root@cloud ~]# vim /usr/local/php/etc/php.ini
 max_input_time = 300 
[root@cloud ~]# service php-fpm reload

- 2.about always-populate-raw-post-data must be set -1 的问题:
[root@cloud ~]# vim /home/www/zabbix/include/classes/setup/CFrontendSetup.php     

大概在366行:
添加 $current = -1;

[root@cloud ~]# head -n 380  /home/www/zabbix/include/classes/setup/CFrontendSetup.php |tail -n 20
     *
     * See: http://php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data
     *
     * @return array
     */
    public function checkPhpAlwaysPopulateRawPostData() {
            $current = ini_get('always_populate_raw_post_data');
            $current = -1;      #就是这行
            return [
                    'name' => _s('PHP option "%1$s"', 'always_populate_raw_post_data'),
                    'current' => ($current != -1) ? _('on') : _('off'),
                    'required' => _('off'),
                    'result' => ($current != -1) ? self::CHECK_FATAL : self::CHECK_OK,
                    'error' => _s('PHP option "%1$s" must be set to "%2$s"', 'always_populate_raw_post_data', -1)
            ];
    }

    /**
     * Checks for PHP sockets extension.
     *
[root@cloud ~]# service php-fpm reload






默认账号是:admin 密码是:zabbix

可能会遇到Zabbix Server 起不来的情况 zabbix server is not running

查看日志 zabbix_server.log,看到有这个报错

connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'


试试将mysql.sock 做个软链接到 /var/lib/mysql/mysql.sock 再重启下zabbix_server看看 Over 解决了

zabbix-agent_install.sh

comments powered by Disqus