CentOS7.2 LNMP安装部署zabbix3.2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7.2 LNMP安装部署zabbix3.2相关的知识,希望对你有一定的参考价值。
一、安装说明
系统环境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
如图:
注意:此时如果有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 如下图:
此此zabbix web安装配置完成
出现如下图:
默认的登录用户名密码: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的主要内容,如果未能解决你的问题,请参考以下文章