zabbix运行的系统环境是LNMP平台,这里主要总结了一些自己在生产环境中安装zabbix_server的过程和方法,因为某些原因,这套过程在CentOS,Suse,Eulor系统均反复尝试过,都可以成功安装zabbix_server。我喜欢用源码包安装,这样可以掌握各种依赖软件包的安装路径,缺啥装啥,尤其是避免php安装过程中无法找到依赖包的麻烦。

一.Mysql的源码安装

1.相关安装包的下载

(1)mysql的下载
登陆https://downloads.mysql.com/archives/community/选择最新的稳定版本,进行下载。
(2)cmake的下载
登陆https://cmake.org/download/下载最新的版本。
(3)Boost的下载
登陆https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz下载。

2.Mysql的安装

(1)Yum安装依赖包
这里使用yum安装gcc,c++的编译环境。
#yum -y install gcc gcc-c++ ncurses ncurses-devel *curl* *libxml2*
(2)安装cmake

#tar -xvf cmake-3.10.1.tar.gz
#cd cmake-3.10.1/
#./bootstrap --prefix=/home/cmake
#make && make install

(3)准备boost
# tar -xvf boost_1_59_0.tar.gz -C /usr/local/
(4)创建用户和日志文件目录

# groupadd mysql
# useradd -s /sbin/nologin -g mysql mysql
# mkdir /var/log/mysql
# chown -R mysql.mysql /var/log/mysql/

(5)安装mysql

# tar -xvf mysql-5.7.18.tar.gz
# cd mysql-5.7.18/
#/home/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/node/mysql  -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost_1_59_0
#make && make install

3.配置mysql

(1)拷贝启动脚本

# cp /node/installfile/mysql/mysql-5.7.18/support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld

(2)将mysql数据库的动态链接库共享至系统链接库,以便被其他服务调用
# ln -sv /node/mysql/lib/libmysqlclient.so.20 /usr/lib/
(3)设置库文件及环境变量

# echo "/node/mysql/lib" >> /etc/ld.so.conf
# ldconfig
# echo "export PATH=$PATH:$HOME/bin:/node/mysql/bin/" >>  /etc/profile
# source /etc/profile

(4)设置开机自启

# chkconfig --add mysqld
# chkconfig mysqld on
# chkconfig --list mysqld

(5)配置文件
mysql的配置文件是/etc/my.cf,mysql对于zabbix的使用性能来说,是重要的影响因素,需要做一些优化,这部分内容在后面做一些总结。

4.初始化数据库

# mysqld --initialize-insecure --user=mysql --basedir=/node/mysql --datadir=/node/mysql/data

5.启动数据库

# chown -R mysql.mysql /node/mysql/
# /etc/init.d/mysqld restart
# netstat -anptu |grep "mysql"
tcp6       0      0 :::3306            :::*           LISTEN      3922/mysqld

二.Nginx的源码安装

1,准备依赖库

(1)Pcre
下载地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
# tar -xvf pcre-8.41.tar.gz
(2)Openssl
下载地址:https://www.openssl.org/source/
# tar -xvf openssl-1.1.0g.tar.gz
(3)Zlib
下载地址:http://www.zlib.net/
# tar -xvf zlib-1.2.11.tar.gz

2.添加用户

# groupadd nginx
# useradd -s /sbin/nologin -g nginx nginx

3.Nginx安装

# tar -xvf nginx-1.12.2.tar.gz
# cd nginx-1.12.2/
# ./configure --prefix=/node/nginx-1.12.2 --user=nginx --with-pcre=../pcre-8.41/ --with-zlib=../zlib-1.2.11/ --with-openssl=../openssl-1.1.0g/ --with-http_stub_status_module --with-http_ssl_module
#make && make install

4.Nginx配置

# echo 'export PATH=$PATH:/node/nginx-1.12.2/sbin/' >> /etc/profile
# source /etc/profile

5.启动nginx

# nginx`
#nginx -s stop #关闭nginx

6.nginx的启动脚本

#vim /etc/init.d/nginxd
#!/bin/bash
#chkconfig: - 80 90
pid=/node/nginx-1.12.2/logs/nginx.pid
mstart(){
        if [ -e $pid ];then
           echo -e "\033[32mnginx已启动\033[0m"
        else 
           nginx  &>/etc/null
           [ $? -eq 0 ]&&echo -e "\033[32mnginx启动成功\033[0m"||echo -e "\033[31mnginx启动失败\033[0m"
        fi            
}
mstop(){
      if [ -e $pid ];then
         nginx -s stop  &>/etc/null
         [ $? -eq 0 ]&&echo -e "\033[32mnginx关闭成功\033[0m"||echo -e "\033[31mnginx关闭失败\033[0m"
      else 
        echo -e "\033[32mnginx已关闭\033[0m"
      fi  
}
mstatus(){
      if [ -e $pid ];then
         echo -e "\033[32mnginx已启动\033[0m"
      else 
         echo -e "\033[32mnginx已关闭\033[0m"           
      fi 
}
mrestart(){
        if [ -f $pid ];then
        kill `cat $pid`
        [ $? -eq 0 ]&&echo -e "\033[32mnginx已关闭\033[0m"||echo "nginx失败"
     else
        echo -e "\033[32mnginx已关闭\033[0m"
     fi
     echo -e "nginx重启中"
     sleep 2
     if [ -f $pid ];then
        echo -e "\033[32mnginx已启动\033[0m"
     else
     nginx  &> /dev/null
     [ $? -eq 0 ]&&echo -e "\033[32mnginx已启动\033[0m"||echo "nginx启动失
败" 
     fi

}

case $1 in 
start)
    mstart
    ;;
stop)
    mstop
    ;;
status)
    mstatus
    ;;
restart)
    mrestart
    ;;
reload)
    nginx -s reload
    ;;
*)
    echo "Usage: $0 [start|stop|restart|status|reload]"
esac

三.安装PHP

1.安装依赖库

# yum install libXpm-devel
(1)安装mhash

# tar -xvf mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9/
# ./configure 
#make && make install

(2)安装libiconv

# tar -xvf libiconv-1.15.tar.gz
# cd libiconv-1.15/
# ./configure
#make && make install

(3)安装libmcrypt

# tar -xvf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8/
# ./configure
#make && make install

(4)安装libxml2

#tar -xvf libxml2-2.7.8.tar.gx
#cd libxml2-2.7.8/
#./configure
#make && make install

(5)建立软连接

# ln -sv /usr/local/lib/libmcrypt* /usr/lib/
# ln -sv /usr/local/lib/libmhash* /usr/lib/
# ln -sv /usr/local/lib/libiconv* /usr/lib/

2.安装GD

(1)安装zlib

# tar -xvf zlib-1.2.11.tar.gz
# cd zlib-1.2.11/
# ./configure --prefix=/usr/local/zlib --shared --enable-shared
#make && make install

(2)安装libpng

# tar -xvf libpng-1.6.34.tar.gz
# cd libpng-1.6.34/
# ./configure --prefix=/usr/local/libpng
#make && make install

(3)安装freetype

# tar -xvf freetype-2.3.11.tar.gz
# cd freetype-2.3.11/
# ./configure --prefix=/usr/local/freetype
#make && make install

(4)安装jpeg

# tar -xvf jpegsrc.v9b.tar.gz
# cd jpeg-9b/
# ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
#make && make install

(5)安装libwebp

# tar -xvf libwebp-0.6.1.tar.gz
# cd libwebp-0.6.1/
# ./configure --prefix=/usr/local/libwebp --enable-libwebpmux --enable-libwebpdemux --enable-libwebpdecoder --enable-libwebpextras --enable-swap-16bit-csp --disable-static
#make && make install

(6)安装gd

# tar -xvf libgd-2.2.5.tar.gz
# cd libgd-2.2.5/
# ./configure --prefix=/usr/local/libgd --with-zlib=/usr/local/zlib/ --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype/ --with-jpeg=/usr/local/jpeg/
#make && make install

3.安装php

#tar -xvf php-7.2.0.tar.gz
#cd php-7.2.0/
#./configure --prefix=/node/php7 --with-mysql=/node/mysql --enable-fpm --enable-mbstring --with-mcrypt --with-mhash --with-curl --with-config-file-path=/node/php7/etc --with-mysqli=/node/mysql/bin/mysql_config --enable-gd-native-ttf --enable-sockets --enable-bcmath --with-zlib-dir=/usr/local/zlib/ --with-jpeg-dir=/usr/local/jpeg/ --with-freetype-dir=/usr/local/freetype/ --with-png-dir=/usr/local/libpng/ --with-webp-dir=/usr/local/libwebp/ --with-xpm-dir=/usr/ --with-iconv=/usr/ --with-gd
#make
#make install

四.构建LNMP平台

1.构建php-fpm

(1)拷贝并修改php-fpm配置文件

# cd /node/php7/etc/
# cp php-fpm.conf.default php-fpm.conf
#vim php-fpm.conf
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = error
daemonize = yes
# cd php-fpm.d/
# cp www.conf.default www.conf
#vim www.conf
user = www
group = www
pm = dynamic
pm.max_children = 32
pm.start_servers = 15
pm.min_spare_servers = 5
pm.max_spare_servers = 32

(2)拷贝php-fpm启动文件

# cp /node/installfile/php/php-7.2.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# groupadd www
# useradd -s /sbin/nologin -g www www

(3)设置开机启动

# chkconfig --add php-fpm
# chkconfig php-fpm on

(4)启动php-fpm

# /etc/init.d/php-fpm start
Starting php-fpm  done
# ps aux |grep  php

2.修改nginx配置文件支持php

# vim /node/nginx-1.12.2/conf/nginx.conf
   location / {
            root   html;
            index  index.php index.html index.htm;
        }
    location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

# nginx -s reload //重新加载nginx

3. 修改php配置文件,支持zabbix

# cp /node/installfile/php/php-7.2.0/php.ini-development /node/php7/etc/php.ini

# vim /node/php7/etc/php.ini 
date.timezone = Asia/Shanghai
max_execution_time = 300
max_input_time = 300
post_max_size = 64M
memory_limit = 128M
mbstring.func_overload = 0

五.安装zabbix_server

1.安装依赖

# yum -y install OpenIPMI OpenIPMI-devel ipmitool freeipmi net-snmp* libcurl* libevent*

2.安装zabbix

# tar -xvf zabbix-3.4.3.tar.gz
# cd zabbix-3.4.3/
# ./configure --prefix=/node/zabbix-3.4.3 --enable-server --enable-agent --with-mysql=/node/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-openipmi
#make && make install

3.创建数据库并导入数据

# mysql -uroot -p
mysql> set password for 'root'@'localhost'=password('123456');
mysql> create database zabbix character set utf8;
mysql> grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';

4.导入数据

# cd /node/installfile/zabbix/zabbix-3.4.3/database/mysql/
# mysql -uzabbix -pzabbix zabbix < schema.sql 
# mysql -uzabbix -pzabbix zabbix < images.sql 
# mysql -uzabbix -pzabbix zabbix < data.sql 

5.创建启动环境

(1)创建用户

# groupadd zabbix
# useradd -s /sbin/nologin -g zabbix zabbix

(2)创建日志文件目录

# mkdir /var/log/zabbix
# chown -R zabbix.zabbix /var/log/zabbix/

(3)创建软链接

# ln -sv /node/zabbix-3.4.3/etc /etc/zabbix
# ln -sv /node/zabbix-3.4.3/bin/* /usr/bin/
# ln -sv /node/zabbix-3.4.3/sbin/* /usr/sbin/

(4)拷贝启动脚本
# cp /node/installfile/zabbix/zabbix-3.4.3/misc/init.d/fedora/core/zabbix_* /etc/init.d/
修改启动脚本中的安装路径

# vim /etc/zabbix/zabbix_server.conf
BASEDIR=/node/zabbix-3.4.3

(5)添加端口信息

# vim /etc/services
zabbix-agent    10050/tcp               #zabbix agent
zabbix-agent    10050/udp               #zabbix agent
zabbix-server   10051/tcp               #zabbix server
zabbix-server   10051/udp               #zabbix server

(6)修改zabbix-server配置文件

# vim /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

(7)拷贝web页面

# cp -r /node/installfile/zabbix/zabbix-3.4.3/frontends/php  /node/nginx-1.12.2/html/zabbix
# chown -R nginx.nginx /node/nginx-1.12.2/

6.启动zabbix-server

# chkconfig --add zabbix_server
# chkconfig zabbix_server on
# /etc/init.d/zabbix_server start

7.Web页面安装zabbix

http://ip/zabbix
可能会显示php少模块,再编译安装进去即可
#yum -y install autoconf m4
(1)安装ldap
# yum -y install openldap
#yum install openldap-devel

# cp /usr/lib64/libldap* /usr/lib/
# cd /node/installfile/php/php-7.2.0/ext/ldap/
# /node/php7/bin/phpize 
# ./configure --with-ldap --with-php-config=/node/php7/bin/php-config
#make && make install

(2)安装gettext

#cd /node/installfile/php/php-7.2.0/ext/gettext
# /node/php7/bin/phpize 
# ./configure  --with-php-config=/node/php7/bin/php-config
#make && make install

(3)在php.ini配置文件中增加模块

# vim /node/php7/etc/php.ini
extension=gettext.so
extension=ldap.so

(4)重启php-fpm
# /etc/init.d/php-fpm restart

六.Zabbix安装完成

通过web页面进行配置后,进入登陆页面:
http://ip/zabbix/index.php
用户名:admin
密码:zabbix
Zabbix的企业级监控架构搭建—zabbix_server的安装_第1张图片