2321221 发表于 2017-10-10 10:09:43

CentOS7.2 LNMP安装部署zabbix3.2

一、安装说明
系统环境CentOS7.2_x64yum安装数据库:mariadb 5.5yum安装 zabbix 3.2.8
编译安装nginx 1.2.1(最新稳定版)   编译安装 php 5.6.31最新稳定版

关闭selinux
防火墙添加好规则,tcp/10051(进出)tcp/10050(出)或为了便于测试直接关闭

二、安装nginx
1、编译安装nginx

1
2
#yum install vim gcc wgetunzip pcre-devel openssl-devel gcc-c++ pcre-devzlib-devel -y
wget http://101.96.10.63/nginx.org/download/nginx-1.12.1.tar.gz   (不要问我这个链接怎么是ip,官方就是这样的)




##添加系统nginx用户

1
2
#groupadd -g 108 -r nginx
#useradd -u 108 -r -g 108 nginx





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#tar xvfnginx-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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/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管理

1
2
3
#chkconfig --add nginx
#chkconfig nginx on
#systemctl daemon-reload





4、配置及启动nginx
cd /etc/nginx
cp nginx.conf nginxconf_def
cat nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
usernginx;
worker_processes2;
error_log/data1/log/nginx/error.log warn;
pid      /var/run/nginx.pid;
events {
    worker_connections1024;
}
http {
    include       /etc/nginx/mime.types;
    default_typeapplication/octet-stream;
    log_formatmain'$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.logmain;
    server_tokens off;
    sendfile      on;
    tcp_nopush   on;
    client_max_body_size    5m;
    keepalive_timeout60;
    gzipon;
    include /etc/nginx/conf.d/*.conf;
}




#cat conf.d/test.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 -ygcc 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源码及编译安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#! /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

1
2
3
4
5
6
7
8
9
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库

1
#rpm -ivh




2、安装zabbix server agent及mysql插件
#yum install zabbix-get zabbix-sender zabbix-server-mysqlzabbix-web zabbix-agent
3、配置zabbix_server.conf
egrep -v '(^$|^#)' /etc/zabbix/zabbix_server.conf


1
2
3
4
5
6
7
8
9
10
11
12
13
14
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目录权限

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




注:此目录没有权限,后面web安装配置zabbix时提示没有权限类似如下信息:

1
2
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服务并启动

1
2
3
4
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
通常需要修改如下项:

1
2
3
4
5
6
7
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 . Exiting ...
2597:20171009:103201.762 connection to database 'zabbix' failed: received invalid response to SSL negotiation: R
手动连接数据库是正常的,最后发现安装的包不对
如下:

正常的两个基于mysql(mariadb)的如下:

1
2
3
4
5
6
7
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端口。
页: [1]
查看完整版本: CentOS7.2 LNMP安装部署zabbix3.2