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

[经验分享] nginx 安装 与 平滑升级

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-3-16 09:47:53 | 显示全部楼层 |阅读模式
首先获取两个 nginx 源码包
nginx-1.4.7.tar.gz
nginx-1.6.2.tar.gz

------------安装nginx----------

# yum install -y gcc gcc-c++ make //安装gcc由于实验环境缺少编译工具
# yum install -y pcre-devel zlib-devel    // nginx rewrite gzip 需要依赖的库

解压nginx

# tar -xzvf nginx-1.4.7.tar.gz
# cd nginx-1.4.7
# ./configure --prefix=/usr/local/nginx    //简单安装,生产环境勿模仿(ˉ﹃ˉ)

成功会提示类似以下信息
Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using builtin md5 code
  + sha1 library is not found
  + using system zlib library

然后执行
# make && make install   //编译 、安装
# cd /usr/local/nginx    //进入nginx 目录


#./sbin/nginx -c ./conf/nginx.conf   //让nginx加载配置文件并启动
# ps aux | grep nginx            //nginx 进程已经启动
root      7012  0.0  0.1  19824   604 ?        Ss   09:35   0:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
nobody    7013  0.0  0.2  20220  1176 ?        S    09:35   0:00 nginx: worker process

测试访问下本地web ,会有如下提示 因为我们没有配置所以是默认的页面,注意iptables 规则
# elinks --dump http://localhost
                               Welcome to nginx!

   If you see this page, the nginx web server is successfully installed and
   working. Further configuration is required.


---------安装结束-------以下是平滑升级-------

nginx 信号:
QUIT   执行完当前的请求后退出
HUP    重新加载配置文件,平滑重启
USR1   重新打开日志文件
USR2   平滑升级 nginx 二进制文件
WINCH  优雅的关闭worker进程

注意 :既然是平滑升级当然不需要重启服务或者暂停web服务

# cd /usr/local/nginx/
# ./sbin/nginx -V              //查看当前nginx版本与配置参数
nginx version: nginx/1.4.7
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
configure arguments: --prefix=/usr/local/nginx    //以前版本的配置信息

去解压我们更高版本的nginx
# tar -xzvf nginx-1.6.2.tar.gz
# cd nginx-1.6.2
# ./configure --prefix=/usr/local/nginx/    //注意:这里引用1.4.x 版本 nginx -V 命令查看的配置信息

# make                //这里只有make没有make install

# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old //改变原理程序的名字
# cp ./objs/nginx /usr/local/nginx/sbin/    //把新程序copy过去
此时注意进程
# ps aux | grep nginx | grep -v 'grep'
root      7012  0.0  0.1  19824   604 ?        Ss   09:35   0:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
nobody    7013  0.0  0.2  20220  1408 ?        S    09:35   0:00 nginx: worker process
此时的nginx pid 为 7012
# cd /usr/local/nginx/
# kill -USR2 ./log/nginx.pid    //给旧进程发信号,他会把自己的pid文件改为nginx.pid.oldbin

#cat ./logs/nginx.pid.oldbin     //此时旧进程的pid文件已经变了
7012

# ps aux | grep nginx | grep -v 'grep'   //此时两个进程一起工作
root      7012  0.0  0.1  19824   704 ?        Ss   09:35   0:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
nobody    7013  0.0  0.2  20220  1408 ?        S    09:35   0:00 nginx: worker process            
root      9243  0.0  0.2  19832  1424 ?        S    10:03   0:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
nobody    9244  0.0  0.2  20256  1200 ?        S    10:03   0:00 nginx: worker process

# kill -QUIT `cat ./logs/nginx.pid.oldbin`   //让旧的进程退出
[iyunv@c4d96299f8ce nginx]# ps aux | grep nginx | grep -v 'grep'  //只剩下新的进程了
root      9243  0.0  0.2  19832  1424 ?        S    10:03   0:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
nobody    9244  0.0  0.2  20256  1200 ?        S    10:03   0:00 nginx: worker process


# elinks --dump http://localhost/test         //此时我们故意用错URL报错信息显示是新版本
                                 404 Not Found

   --------------------------------------------------------------------------

                                  nginx/1.6.2

平滑升级到此结束
end .


运维网声明 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.yunweiku.com/thread-47204-1-1.html 上篇帖子: nginx全局常用参数(核心功能参数)和其他模块参考 下篇帖子: 详解Linux下安装配置Nginx
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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