您的位置:首页 > 运维架构 > Nginx

在线升级nginx

2019-05-26 10:34 1386 查看

步骤一:构建Nginx服务器

1)使用源码包安装nginx软件包

[root@svr5 ~]# yum –y install gcc pcre-devel openssl-devel		//安装常见依赖包
[root@svr5 ~]# useradd –s /sbin/nologin nginx
[root@svr5 ~]# tar  -zxvf   nginx-1.7.10.tar.gz
[root@svr5 ~]# cd  nginx-1.7.10
[root@svr5 nginx-1.7.10]# ./configure   \
> --prefix=/usr/local/nginx   \				//指定安装路径
> --user=nginx   \							//指定用户
> --group=nginx  \							//指定组
> --with-http_stub_status_module  \			//开启状态统计功能
> --with-http_ssl_module						//开启SSL加密功能
.. ..
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
[root@svr5 nginx-1.7.10]# make && make install	//编译并安装

2)启用nginx服务

[root@svr5 ~]# /usr/local/nginx/sbin/nginx –c /usr/local/nginx/conf/nginx.conf
nginx服务默认通过TCP 80端口监听客户端请求:
[root@svr5 ~]# netstat  -anptu  |  grep nginx
tcp		0		0 0.0.0.0:80		0.0.0.0:*		LISTEN		10441/nginx

3)为Nginx Web服务器建立测试首页文件
Nginx Web服务默认首页文档存储目录为/usr/local/nginx/html/,在此目录下建立一个名为index.html的文件:

[root@svr5 ~]# cat  /usr/local/nginx/html/index.html
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>

步骤二:升级Nginx服务器

1)编译新版本nginx软件

[root@svr5 ~]# tar  -zxvf   nginx-1.8.0.tar.gz
[root@svr5 ~]# cd nginx-1.8.0
[root@svr5 nginx-1.8.0]# ./configure   \
> --prefix=/usr/local/nginx   \
> --user=nginx   \
> --group=nginx  \
> --with-http_stub_status_module  \
> --with-http_ssl_module
[root@svr5 nginx-1.8.0]# make

2)备份老的nginx主程序,并使用编译好的新版本nginx替换老版本

[root@svr5 nginx-1.8.0]# cd /usr/local/nginx/sbin/
[root@svr5 sbin]# mv nginx  nginxold						//备份旧版本
[root@svr5 sbin]# cd /root/ nginx-1.8.0/objs/
[root@svr5 objs]# cp nginx  /usr/local/nginx/sbin/			//拷贝新版本
[root@svr5 objs]# cd /root/nginx-1.0.5
[root@svr5 nginx-1.8.0]# make upgrade						//升级
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
[root@svr5 ~]# /usr/local/nginx/sbin/nginx –v				//查看版本

步骤三:客户端访问测试

1)分别使用浏览器和命令行工具curl测试服务器页面
[root@client ~]# firefox http://192.168.4.5
[root@client ~]# curl http://192.168.4.5
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: