设为首页 收藏本站
查看: 806|回复: 0

[经验分享] nginx-1.9.1平滑升级到nginx-1.9.7

[复制链接]

尚未签到

发表于 2018-11-13 12:21:33 | 显示全部楼层 |阅读模式
操作系统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/  安装前准备
  [root@lb ~]# iptables -F    ##清空防火墙
  [root@lb ~]# iptables -X
  [root@lb ~]# iptables -Z
  [root@lb ~]# /etc/init.d/iptables save
  iptables:将防火墙规则保存到 /etc/sysconfig/iptables:     [确定]
  [root@lb ~]# setenforce 0    ##临时关闭selinux
  [root@lb ~]# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config    ##永久关闭selinux
  [root@lb ~]# yum -y install vim ntpdate wget gcc gcc-c++ patch unzip    ##安装必要的软件
  [root@lb ~]# ntpdate 0.pool.ntp.org    ##同步时间服务器
  [root@lb ~]# hwclock
  安装pcre
  [root@lb ~]# tar xvfz pcre-8.30.tar.gz -C /usr/local/src/
  [root@lb ~]# cd /usr/local/src/pcre-8.30
  [root@lb pcre-8.30]# ./configure --prefix=/usr/local/pcre-8.30
  [root@lb pcre-8.30]# make && make install
  安装openssl
  [root@lb ~]# tar xvfz openssl-1.0.2a.tar.gz -C /usr/local/src/
  [root@lb ~]# cd /usr/local/src/openssl-1.0.2a
  [root@lb openssl-1.0.2a]# ./config --prefix=/usr/local/openssl-1.0.2a
  [root@lb openssl-1.0.2a]# make && make install
  安装zlib
  [root@lb ~]# tar xvfz zlib-1.2.7.tar.gz -C /usr/local/src/
  [root@lb ~]# cd /usr/local/src/zlib-1.2.7/
  [root@lb zlib-1.2.7]# ./configure --prefix=/usr/local/zlib-1.2.7
  [root@lb zlib-1.2.7]# make && make install
  安装nginx
  [root@lb ~]# groupadd www
  [root@lb ~]# useradd -g www -s /sbin/nologin www
  [root@lb ~]# unzip nginx_upstream_check_module-master.zip
  [root@lb ~]# tar xvfz nginx-1.9.1.tar.gz -C /usr/local/src/
  [root@lb ~]# cd /usr/local/src/nginx-1.9.1/src    ##为nginx打补丁使其支持代理后端服务器健康检查
  [root@lb src]# 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
  [root@lb src]# cd /usr/local/src/nginx-1.9.1/
  [root@lb 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控制脚本
  [root@lb nginx-1.9.1]# 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
  [root@lb nginx-1.9.1]# chmod +x /etc/init.d/nginx
  [root@lb nginx-1.9.1]# chkconfig nginx on
  [root@lb nginx-1.9.1]# chkconfig --list | grep nginx
  nginx           0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
  [root@lb nginx-1.9.1]# /etc/init.d/nginx start
  [root@lb nginx-1.9.1]# netstat -tnlp | grep :80
  tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      29070/nginx
  安装nginx.vim  使nginx配置文件支持语法检查
  [root@lb nginx-1.9.1]# mkdir -p ~/.vim/syntax
  [root@lb nginx-1.9.1]# mv /root/nginx.vim ~/.vim/syntax
  [root@lb nginx-1.9.1]# cat >> ~/.vim/filetype.vim

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-634580-1-1.html 上篇帖子: 配置nginx+apache 其中动态由apache处理,静态由nginx处理 下篇帖子: 安装nginx并为nginx添加sysguard模块
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表