实时警报通知:微信告警通知的重要性解析
702
2023-03-15
nginx 负载均衡搭建
环境说明
192.168.1.208 Nginx负载服务器192.168.1.210 webA服务器 PHP memcache xcache mysql192.168.1.211 webB服务器 PHP memcache xcache
192.168.1.208 Nginx负载服务器192.168.1.210 webA服务器 PHP memcache xcache mysql192.168.1.211 webB服务器 PHP memcache xcache
webA/webB 服务器PHP环境配置
# 注意:freetype在生成验证码图片需要用,所以必须要安装的[root@iZ23g4snm6gZ soft]# yum install openssl-devel libxml2 libxml2-devel curl-devel libevent[root@iZ23g4snm6gZ soft]# yum install libpng libpng-devel libjpeg libjpeg-devel freetype-devel gd gd-devel mysql-devel# 源码包安装libiconvtar zxvf libiconv-1.14.tar.gzcd libiconv-1.14/./configure --prefix=/usr/local/libiconvmakemake install# 源码包安装libiconvtar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configure --prefix=/usr/local/libmcrypt/makemake install# 开始编译PHPtar -zxvf php-5.6.3.tar.gzcd php-5.6.3./configure --prefix=/usr/local/php/ \--with-config-file-path=/usr/local/php/etc/ \--enable-fpm \--with-fpm-user=nginx \--with-fpm-group=nginx \--with-zlib \--with-libxml-dir \--enable-sockets \--with-curl \--with-jpeg-dir \--with-png-dir \--with-gd \--with-iconv-dir=/usr/local/libiconv \--with-freetype-dir= \--enable-gd-native-ttf \--with-xmlrpc \--with-openssl \--with-mhash \ --with-mcrypt=/usr/local/libmcrypt/ \--with-pear \--enable-mbstring \--enable-sysvshm \--enable-zip \--with-mysql \--with-mysqli \--with-mysql-sock \--with-pdo-mysql \--disable-fileinfo \# 安装配置makemake install
# 注意:freetype在生成验证码图片需要用,所以必须要安装的[root@iZ23g4snm6gZ soft]# yum install openssl-devel libxml2 libxml2-devel curl-devel libevent[root@iZ23g4snm6gZ soft]# yum install libpng libpng-devel libjpeg libjpeg-devel freetype-devel gd gd-devel mysql-devel# 源码包安装libiconvtar zxvf libiconv-1.14.tar.gzcd libiconv-1.14/./configure --prefix=/usr/local/libiconvmakemake install# 源码包安装libiconvtar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configure --prefix=/usr/local/libmcrypt/makemake install# 开始编译PHPtar -zxvf php-5.6.3.tar.gzcd php-5.6.3./configure --prefix=/usr/local/php/ \--with-config-file-path=/usr/local/php/etc/ \--enable-fpm \--with-fpm-user=nginx \--with-fpm-group=nginx \--with-zlib \--with-libxml-dir \--enable-sockets \--with-curl \--with-jpeg-dir \--with-png-dir \--with-gd \--with-iconv-dir=/usr/local/libiconv \--with-freetype-dir= \--enable-gd-native-ttf \--with-xmlrpc \--with-openssl \--with-mhash \ --with-mcrypt=/usr/local/libmcrypt/ \--with-pear \--enable-mbstring \--enable-sysvshm \--enable-zip \--with-mysql \--with-mysqli \--with-mysql-sock \--with-pdo-mysql \--disable-fileinfo \# 安装配置makemake install
配置php-fpm.conf文件
php-fpm开机自启动配置
#! /bin/sh ### BEGIN INIT INFO# Provides: php-fpm# Required-Start: $remote_fs $network# Required-Stop: $remote_fs $network# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts php-fpm# Description: starts the PHP FastCGI Process Manager daemon### END INIT INFO prefix=/usr/local/phpexec_prefix=${prefix} php_fpm_BIN=${exec_prefix}/sbin/php-fpmphp_fpm_CONF=${prefix}/etc/php-fpm.confphp_fpm_PID=${prefix}/var/run/php-fpm.pid php_opts="--fpm-config $php_fpm_CONF" 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 $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 ;; 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}" exit 1 ;; esac# 开机自启动配置mv php-fpm /etc/init.d/ // 移动php-fpm脚本到init.d目录下chmod a+x /etc/init.d/php-fpm // 添加执行权限chkconfig --add php-fpm // 添加开机启动配置chkconfig --level 2345 php-fpm on // 配置开机启动权限级别
#! /bin/sh ### BEGIN INIT INFO# Provides: php-fpm# Required-Start: $remote_fs $network# Required-Stop: $remote_fs $network# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts php-fpm# Description: starts the PHP FastCGI Process Manager daemon### END INIT INFO prefix=/usr/local/phpexec_prefix=${prefix} php_fpm_BIN=${exec_prefix}/sbin/php-fpmphp_fpm_CONF=${prefix}/etc/php-fpm.confphp_fpm_PID=${prefix}/var/run/php-fpm.pid php_opts="--fpm-config $php_fpm_CONF" 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 $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 ;; 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}" exit 1 ;; esac# 开机自启动配置mv php-fpm /etc/init.d/ // 移动php-fpm脚本到init.d目录下chmod a+x /etc/init.d/php-fpm // 添加执行权限chkconfig --add php-fpm // 添加开机启动配置chkconfig --level 2345 php-fpm on // 配置开机启动权限级别
Nginx 服务器配置安装
配置nginx支持php
Vhost目录下的虚拟机配置文件
Nginx 开机启动配置
#!/bin/bash# nginx This shell script takes care of starting and stopping# nginx## chkconfig: - 13 68# description: nginx is a web server### BEGIN INIT INFO# Provides: $named# Short-Description: start|stop|status|restart|configtest ### END INIT INFO#variablesNGINX_BIN="/usr/local/nginx/sbin/nginx"NGINX_CONF="/usr/local/nginx/conf/nginx.conf"NGINX_PID="/usr/local/nginx/logs/nginx.pid"NETSTAT="/bin/netstat"alter=$1prog=nginx#load system function. /etc/rc.d/init.d/functions#function:echo ok or errorfunction if_no {if [ $2 == 0 ]; thenecho -n $"$1 ${prog}:" && success && echoelseecho -n $"$1 ${prog}:" && failure && echofi}#start nginxfunction start {rm -f ${NGINX_PID} 2>/dev/nullif [ -s ${NGINX_PID} ]; thenecho "nginx already running" elseif [ `${NETSTAT} -tnpl | grep nginx | wc -l` -eq 0 ]; thenrm -f ${NGINX_PID} 2>/dev/null${NGINX_BIN} -c ${NGINX_CONF} if_no start $? else${NETSTAT} -tnpl | grep nginx | awk '{ print $7}' | cut -d '/' -f 1 > ${NGINX_PID}if_no start $?fifi}#stp nginxfunction stop {if [ -s ${NGINX_PID} ]; thencat ${NGINX_PID} | xargs kill -QUITif_no stop $?else if [ `${NETSTAT} -tnpl | grep nginx | wc -l` -eq 0 ]; thenrm -f ${NGINX_PID} 2>/dev/nullif_no stop 0elserm -f ${NGINX_PID} 2>/dev/nullkill `${NETSTAT} -tnpl | grep nginx | awk '{ print $7}' | cut -d '/' -f 1`if_no stop $?fifi}function restart {if [ -s ${NGINX_PID} ]; thencat ${NGINX_PID} | xargs kill -HUPif_no restart $?elsestopsleep 1startfi}function status {${NETSTAT} -tnpl | grep nginx | grep LISTEN[ $? == 0 ] && echo "nginx is running" || echo "nginx is not running"}function configtest {${NGINX_BIN} -t}case $alter instart)start;;stop)stop;;restart)restart;;status)status;;configtest)configtest;;*)echo "use:${NGINX} {start|stop|restart|status|configtest}";;esac# 配置Nginx自启动脚本chmod +x /etc/init.d/nginx/etc/init.d/nginx start 或 service nginx start // 启动nginx/etc/init.d/nginx stop 或 service nginx stop // 关闭nginx/etc/init.d/nginx restart 或 service nginx restart // 重启nginxchkconfig --add nginxchkconfig --level 2345 nginx on# 重启服务器/etc/init.d/nginx stop # 停止nginx 服务/etc/init.d/nginx start # 启动nginx 服务
#!/bin/bash# nginx This shell script takes care of starting and stopping# nginx## chkconfig: - 13 68# description: nginx is a web server### BEGIN INIT INFO# Provides: $named# Short-Description: start|stop|status|restart|configtest ### END INIT INFO#variablesNGINX_BIN="/usr/local/nginx/sbin/nginx"NGINX_CONF="/usr/local/nginx/conf/nginx.conf"NGINX_PID="/usr/local/nginx/logs/nginx.pid"NETSTAT="/bin/netstat"alter=$1prog=nginx#load system function. /etc/rc.d/init.d/functions#function:echo ok or errorfunction if_no {if [ $2 == 0 ]; thenecho -n $"$1 ${prog}:" && success && echoelseecho -n $"$1 ${prog}:" && failure && echofi}#start nginxfunction start {rm -f ${NGINX_PID} 2>/dev/nullif [ -s ${NGINX_PID} ]; thenecho "nginx already running" elseif [ `${NETSTAT} -tnpl | grep nginx | wc -l` -eq 0 ]; thenrm -f ${NGINX_PID} 2>/dev/null${NGINX_BIN} -c ${NGINX_CONF} if_no start $? else${NETSTAT} -tnpl | grep nginx | awk '{ print $7}' | cut -d '/' -f 1 > ${NGINX_PID}if_no start $?fifi}#stp nginxfunction stop {if [ -s ${NGINX_PID} ]; thencat ${NGINX_PID} | xargs kill -QUITif_no stop $?else if [ `${NETSTAT} -tnpl | grep nginx | wc -l` -eq 0 ]; thenrm -f ${NGINX_PID} 2>/dev/nullif_no stop 0elserm -f ${NGINX_PID} 2>/dev/nullkill `${NETSTAT} -tnpl | grep nginx | awk '{ print $7}' | cut -d '/' -f 1`if_no stop $?fifi}function restart {if [ -s ${NGINX_PID} ]; thencat ${NGINX_PID} | xargs kill -HUPif_no restart $?elsestopsleep 1startfi}function status {${NETSTAT} -tnpl | grep nginx | grep LISTEN[ $? == 0 ] && echo "nginx is running" || echo "nginx is not running"}function configtest {${NGINX_BIN} -t}case $alter instart)start;;stop)stop;;restart)restart;;status)status;;configtest)configtest;;*)echo "use:${NGINX} {start|stop|restart|status|configtest}";;esac# 配置Nginx自启动脚本chmod +x /etc/init.d/nginx/etc/init.d/nginx start 或 service nginx start // 启动nginx/etc/init.d/nginx stop 或 service nginx stop // 关闭nginx/etc/init.d/nginx restart 或 service nginx restart // 重启nginxchkconfig --add nginxchkconfig --level 2345 nginx on# 重启服务器/etc/init.d/nginx stop # 停止nginx 服务/etc/init.d/nginx start # 启动nginx 服务
以下扩展配置自行安装使用
AB测试与centos系统优化
配置Memcache缓存
Memcache配置地址
配置Xcache代码缓存
xcache缓存配置地址
发表评论
暂时没有评论,来抢沙发吧~