nginx-1.9.1平滑升级到nginx-1.9.7
操作系统CentOS>服务器ip192.168.1.129nginx版本1.9.1-->1.9.7pcre版本8.30openssl版本1.0.2azlib版本1.2.7源码解压目录/usr/local/src源码安装目录/usr/local/softnamenginx安装目录/usr/local/nginx-1.9.1/ 安装前准备# iptables -F ##清空防火墙
# iptables -X
# iptables -Z
# /etc/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]
# setenforce 0 ##临时关闭selinux
# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config ##永久关闭selinux
# yum -y install vim ntpdate wget gcc gcc-c++ patch unzip ##安装必要的软件
# ntpdate 0.pool.ntp.org ##同步时间服务器
# hwclock
安装pcre
# tar xvfz pcre-8.30.tar.gz -C /usr/local/src/
# cd /usr/local/src/pcre-8.30
# ./configure --prefix=/usr/local/pcre-8.30
# make && make install
安装openssl
# tar xvfz openssl-1.0.2a.tar.gz -C /usr/local/src/
# cd /usr/local/src/openssl-1.0.2a
# ./config --prefix=/usr/local/openssl-1.0.2a
# make && make install
安装zlib
# tar xvfz zlib-1.2.7.tar.gz -C /usr/local/src/
# cd /usr/local/src/zlib-1.2.7/
# ./configure --prefix=/usr/local/zlib-1.2.7
# make && make install
安装nginx
# groupadd www
# useradd -g www -s /sbin/nologin www
# unzip nginx_upstream_check_module-master.zip
# tar xvfz nginx-1.9.1.tar.gz -C /usr/local/src/
# cd /usr/local/src/nginx-1.9.1/src ##为nginx打补丁使其支持代理后端服务器健康检查
# patch -p1 < /root/nginx_upstream_check_module-master/check_1.9.2+.patch
patching file http/modules/ngx_http_upstream_hash_module.c
patching file http/modules/ngx_http_upstream_ip_hash_module.c
patching file http/modules/ngx_http_upstream_least_conn_module.c
patching file http/ngx_http_upstream_round_robin.c
patching file http/ngx_http_upstream_round_robin.h
# cd /usr/local/src/nginx-1.9.1/
# ./configure \ ##编译安装
--prefix=/usr/local/nginx-1.9.1 \ ##指定nginx安装目录
--sbin-path=/usr/local/nginx-1.9.1/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 \ ##进程PID文件
--lock-path=/var/lock/nginx.lock \ ##锁文件
--user=www \ ##运行nginx非特权用户
--group=www \ ##运行nginx非特权用户组
--with-http_ssl_module \ ##支持https请求
--with-http_realip_module \ ##允许从请求标头更改客户端的IP地址值
--with-http_gzip_static_module \ ##在线实时压缩输出数据流
--with-http_stub_status_module \ ##获取Nginx自上次启动以来的工作状态
--with-pcre=/usr/local/src/pcre-8.30 \ ##pcre库文件目录,指源码解压目录
--with-zlib=/usr/local/src/zlib-1.2.7 \ ##zlib库文件目录,指源码解压目录
--with-openssl=/usr/local/src/openssl-1.0.2a \ ##openssl库文件目录,指源码解压目录
--add-module=/root/nginx_upstream_check_module-master ##支持代理后端服务器健康状态检查
# make && make install
编写nginx控制脚本
# vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# 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
# pidfile: /var/run/nginx/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/local/nginx-1.9.1/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
lockfile="/var/lock/nginx.lock"
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
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
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
;;
> 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
# chmod +x /etc/init.d/nginx
# chkconfig nginx on
# chkconfig --list | grep nginx
nginx 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
# /etc/init.d/nginx start
# netstat -tnlp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 29070/nginx
安装nginx.vim使nginx配置文件支持语法检查
# mkdir -p ~/.vim/syntax
# mv /root/nginx.vim ~/.vim/syntax
# cat >> ~/.vim/filetype.vim
页:
[1]