1. 程式人生 > >CentOS7.2 LNMP安裝部署zabbix3.2

CentOS7.2 LNMP安裝部署zabbix3.2

centos7 zabbix3.2 lnmp

一、安裝說明

系統環境CentOS7.2_x64 yum安裝數據庫:mariadb 5.5 yum安裝 zabbix 3.2.8

編譯安裝nginx 1.2.1(最新穩定版) 編譯安裝 php 5.6.31最新穩定版


關閉selinux

防火墻添加好規則,tcp/10051(進出)tcp/10050(出)或為了便於測試直接關閉


二、安裝nginx

1、編譯安裝nginx

#yum install vim gcc wget  unzip pcre-devel openssl-devel gcc-c++ pcre-dev  zlib-devel -y
wget http://101.96.10.63/nginx.org/download/nginx-1.12.1.tar.gz   (不要問我這個鏈接怎麽是ip,官方就是這樣的)

##添加系統nginx用戶

#groupadd -g 108 -r nginx
#useradd -u 108 -r -g 108 nginx
#tar xvf  nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure   --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid   --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre \

2、添加系統服務(sysv)

cat /etc/init.d/nginx

#!/bin/sh  
# nginx - this script starts and stops the nginx daemon  
# chkconfig:   - 85 15  
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \  
#               proxy and IMAP/POP3 proxy server  
# processname: nginx  
# config:      /etc/nginx/nginx.conf  
# config:      /etc/sysconfig/nginx  
# pidfile:     /var/run/nginx.pid  
# Source function library.  
. /etc/rc.d/init.d/functions
# Source networking configuration.  
. /etc/sysconfig/network
# Check that networking is up.  
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
   # make required directories  
   user=`nginx -V 2>&1 | grep "configure arguments:" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -`
   options=`$nginx -V 2>&1 | grep ‘configure arguments:‘`
   for opt in $options; do
       if [ `echo $opt | grep ‘.*-temp-path‘` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
 mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: " 
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo 
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: " 
    killproc $prog -QUIT
    retval=$?
    echo 
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: " 
    killproc $nginx -HUP
    RETVAL=$?
    echo 
}
force_reload() {
    restart
}
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
        reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
            echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
        exit 2
esac

3、添加開機啟動及加載到 systemd管理

#chkconfig --add nginx
#chkconfig nginx on
#systemctl daemon-reload


4、配置及啟動nginx

cd /etc/nginx

cp nginx.conf nginxconf_def

cat nginx.conf

user  nginx;
worker_processes  2;
error_log  /data1/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;
    access_log  /data1/log/nginx/access.log  main;
    server_tokens off;
    sendfile        on;
    tcp_nopush     on;
    client_max_body_size    5m;
    keepalive_timeout  60;
    gzip  on;
    include /etc/nginx/conf.d/*.conf;
}

#cat conf.d/test.conf

server {
listen 80;
server_name _;
access_log /data1/log/nginx/test.access.log main;
index index.php index.html index.html;
root /data1/site/test;
  location /
 {
 try_files $uri $uri/ /index.php?$args;
 }
 
 location ~ .*\.(php)?$
 {
 expires -1s;
 try_files $uri =404;
 fastcgi_split_path_info ^(.+\.php)(/.+)$;
 include fastcgi_params;
 fastcgi_param PATH_INFO $fastcgi_path_info;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_pass 127.0.0.1:9000;
 
 }
}

#mkdir -pv /data1/log

#mkdir -pv /data1/site/

#chown nginx.nginx /data1/ -R

#systemctl start nginx


三、安裝maridb

yum -y install mariadb-server mariadb-devel

systemctl enable mariadb

systemctl start mariadb

添加zabbix數據庫及zabbix用戶名密碼
mysql -uroot -p
>grant all privileges on zabbix.* to ‘zabbix‘@‘localhost‘ identified by ‘123456‘;

mysqladmin -u root password "redhat" #設置數據的root密碼


四、編譯安裝php5.6.31

1、安裝依賴組件

yum install -y gcc gcc-c++ openssl openssl-devel libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel gd bzip2 bzip2-devel curl curl-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel

2、下載php源碼及編譯安裝

#wget http://cn2.php.net/distributions/php-5.6.31.tar.bz2
#tar xvf php-5.6.31.tar.gz
#cd php-5.6.31
#./configure --prefix=/usr/local/php5631 --with-config-file-path=/usr/local/php5631/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath

2、添加環境變量

cat /etc/profile.d/php.sh

export PATH=/usr/local/php5631/bin:$PATH


3、添加php-fpm系統服務

cat /etc/init.d/php-fpm

#! /bin/sh
# chkconfig:   - 85 25 
### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO

prefix=/usr/local/php5631
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid

php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
wait_for_pid () {
        try=0
        while test $try -lt 35 ; do
                case "$1" in
                        ‘created‘)
                        if [ -f "$2" ] ; then
                                try=‘‘
                                break
                        fi
                        ;;
                        ‘removed‘)
                        if [ ! -f "$2" ] ; then
                                try=‘‘
                                break
                        fi
                        ;;
                esac
                echo -n .
                try=`expr $try + 1`
                sleep 1
        done
}
case "$1" in
        start)
                echo -n "Starting php-fpm "
                $php_fpm_BIN --daemonize $php_opts
                if [ "$?" != 0 ] ; then
                        echo " failed"
                        exit 1
                fi
                wait_for_pid created $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;
stop)
                echo -n "Gracefully shutting down php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -QUIT `cat $php_fpm_PID`
                wait_for_pid removed $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed. Use force-quit"
                        exit 1
                else
                        echo " done"
                fi
        ;;
        status)
                if [ ! -r $php_fpm_PID ] ; then
                        echo "php-fpm is stopped"
                        exit 0
                fi
                PID=`cat $php_fpm_PID`
                if ps -p $PID | grep -q $PID; then
                        echo "php-fpm (pid $PID) is running..."
                fi
        ;;
force-quit)
                echo -n "Terminating php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -TERM `cat $php_fpm_PID`
                wait_for_pid removed $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;
        restart)
                $0 stop
                $0 start
        ;;
reload)
                echo -n "Reload service php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -USR2 `cat $php_fpm_PID`
                echo " done"
        ;;
        *)
                echo "Usage: $0 {start|stop|force-quit|restart|reload|status}"
                exit 1
        ;;
esac

#chkconfig --add php-fpm

#chkconfig php-fpm on

#systemctl daemon-reload

4、修改php-fpm.conf並啟動php-fpm

#cd /usr/local/php5631/etc

#cp php-fpm.conf.default php-fpm.conf

#egrep -v ‘(^$|^;)‘ php-fpm.conf

user = nginx 
group = nginx
listen = 127.0.0.1:9000
 
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

#systemctl start php-fpm


五、安裝zabbix 3.2

1、安裝zabbix官方yum庫

#rpm -ivh

2、安裝zabbix server agent及mysql插件

#yum install zabbix-get zabbix-sender zabbix-server-mysql zabbix-web zabbix-agent

3、配置zabbix_server.conf

egrep -v ‘(^$|^#)‘ /etc/zabbix/zabbix_server.conf

LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBSocket=/var/lib/mysql/mysql.sock
DBPort=3306
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000

修改/etc/zabbix/web目錄權限

#cd /etc/zabbix
#chown zabbix.nginx web -R
#chmod 775 web -R

註:此目錄沒有權限,後面web安裝配置zabbix時提示沒有權限類似如下信息:

Warning: require_once(/etc/zabbix/web/maintenance.inc.php): failed to open stream: Permission denied in /usr/local/nginx/html/zabbix/include/classes/core/ZBase.php on line 269
Fatal error: require_once(): Failed opening required ‘/etc/zabbix/web/maintenance.inc.php‘ (include_path=‘.:/usr/local/php/lib/php‘) in/usr/local/nginx/html/zabbix/include/classes/core/ZBase.php on line 269

4、配置zabbix-server,zabbix-agent服務並啟動

systemctl enable zabbix-server
systemctl start zabbix-server
systemctl enable zabbix-agent
systemctl start zabbix-agent

六、zabbix web nginx配置

1、創建zabbix web目錄並復制內容

#mkdir /data1/site/zabbix -pv

#chown nginx.nginx /data1/site/zabbix -R

#cp -rf /usr/share/zabbix/* /data1/site/zabbix


2、創建zabbix.conf配置文件

cd /etc/nginx/conf.d/

egrep -v ‘(^$|^#)‘ zabbix.conf

server {
listen 80;
server_name zabbix.pkey.cn;    #這個是測試域名在本地機器上添加 hosts文件,也可用ip
access_log /data1/log/nginx/zabbix.access.log main;
 
index index.php index.html index.html;
root /data1/site/zabbix;
 
 location /
 {
 try_files $uri $uri/ /index.php?$args;
 }
 
 location ~ .*\.(php)?$
 {
 expires -1s;
 try_files $uri =404;
 fastcgi_split_path_info ^(.+\.php)(/.+)$;
 include fastcgi_params;
 fastcgi_param PATH_INFO $fastcgi_path_info;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_pass 127.0.0.1:9000;
 
 }
}

3、重啟nginx

#systemctl restart nginx


七、web配置安裝zabbix

http://zabbix.pkey.cn

如圖:

技術分享 點 “next step” 如圖:

技術分享註意:此時如果有fail項請按上面的提示找到php.ini文件對應著修改,

獲取php.ini文件位置

#php -i |grep php.ini

通常需要修改如下項:

max_execution_time = 300
memory_limit =  128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
always_populate_raw_post_data = -1
date.timezone = Asia/Shanghai

直到如上所有的檢測項均ok時再點next setp

出現如下圖:


技術分享輸入zabbix數據庫的zabbix用戶密碼 ,如提示找不到文件夾之類的提示,Database host可以填寫127.0.0.1,netxt setp 如下圖:

技術分享next step

技術分享

此此zabbix web安裝配置完成

再次訪問http://zabbix.pkey.cn

出現如下圖:

技術分享

默認的登錄用戶名密碼:Admin/zabbix

登錄進去默認是英文如圖:

技術分享

修改為中文界面:

從windows 系統復制 c:/windows/fontes/simkai.ttf 字體上傳到

/data1/site/zabbix/fonts/中

並修改配置文件

#sed -i ‘s/graphfont/simkai/g‘ ../include/defines.inc.php

再在用戶設置中修改為中文字體如圖:

技術分享更新後,zabbixweb頁默認字體就是中文且不亂碼,如圖:

技術分享

至此一個基於CentOS7 LNMP環境 zabbix3.2.8 中文界面配置完成。


安裝zabbix-server後啟動過程中出現的一個錯誤提示:

癥狀:zabbix-server服務是啟動的,就是不偵聽端口,日誌顯示如下:

錯誤日誌/var/log/zabbix/zabbix_server.log描述:
2597:20171009:103156.940 database is down: reconnecting in 10 seconds
2597:20171009:103159.761 Got signal [signal:15(SIGTERM),sender_pid:2646,sender_uid:0,reason:0]. Exiting ...
2597:20171009:103201.762 [Z3001] connection to database ‘zabbix‘ failed: [0] received invalid response to SSL negotiation: R

手動連接數據庫是正常的,最後發現安裝的包不對

如下:

技術分享

正常的兩個基於mysql(mariadb)的如下:

zabbix-server-mysql-3.2.8-1.el7.x86_64
zabbix-release-3.2-1.el7.noarch
zabbix-web-pgsql-3.2.8-1.el7.noarch
zabbix-sender-3.2.8-1.el7.x86_64
zabbix-get-3.2.8-1.el7.x86_64
zabbix-web-3.2.8-1.el7.noarch
zabbix-agent-3.2.8-1.el7.x86_64

安裝了正常的包後故障排除,zabbix-server服務正常啟動偵聽10051端口。

本文出自 “學無止境,學以致用” 博客,請務必保留此出處http://dyc2005.blog.51cto.com/270872/1970986

CentOS7.2 LNMP安裝部署zabbix3.2