Linux下安装与升级nginx

软件下载地址: http://nginx.org/en/download.html

安装使用的版本:nginx-0.8.55.tar.gz

升级使用的版本:nginx-1.0.15.tar.gz 

一、nginx 安装与测试

1、先决条件

[root@svr5 data]# yum -y install gcc pcre-devel openssl-devel    # 安装必要的软件包
[root@svr5 data]# rpm -q  gcc pcre-devel openssl-devel           # 检查软件包是否安装成功
gcc-4.4.7-4.el6.x86_64
pcre-devel-7.8-6.el6.x86_64
openssl-devel-1.0.1e-15.el6.x86_64
[root@svr5 data]# 


2、添加 nginx 用户

[root@svr5 data]# useradd -s /sbin/nologin nginx    

# 1. 创建这个 nginx 用户是为了启动和运行 nginx 程序 (也就是nginx进程的拥有者是 nginx 用户)
# 2. nginx 用户不需要登录系统, 所以使用 -s /sbin/nologin 指定其内核

3、上传 nginx 源码文件到 /data 目录下,将其解压,并进入解压后的目录

[root@svr5 data]# rz                                # 1. 使用 rz 命令上传文件

[root@svr5 data]# 
[root@svr5 data]# tar -zxvf nginx-0.8.55.tar.gz     # 2. 解压 nginx 源码文件
[root@svr5 data]# cd nginx-0.8.55                   # 3. 进入解压目录

4、安装参数的配置


[root@svr5 nginx-0.8.55]# ./configure  \
> --prefix=/usr/local/nginx   \                 # 指定 nginx 主目录
> --user=nginx  \                               # 指定安装的用户为 nginx 用户
> --group=nginx  \                              # 指定安装的组为 nginx 组
> --with-http_stub_status_module  \             # 指定安装监控模块
> --with-http_ssl_module                        # 指定安装 SSL 模块



................省略中间的输出...............
................输出结果中 比较有用的信息...............
................如: 安装完成后的 nginx 的主目录, 主程序,配置文件,日志文件的路径等.......... 
Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1 library is not used
  + using system zlib library

  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"

注: 安装时的参数 在最后补充说明

5、编译并安装

[root@svr5 nginx-0.8.55]# make && make install

6、使用浏览器测试

浏览器地址栏中输入: http://192.168.174.151/

注: ① 、192.168.174.151 是安装 nginx 服务器的地址

     ②、  输入地址后显示的主页是 安装 nginx服务时在 nginx主目录下的/html/index.html 文件系统默认提供

     ③、 测试有问题的话,检查防火墙 和网络 问题


二、将 nginx 升级到 1.0.15

1、下载软件, 并上传到 /data目录下(步骤略)

2、 解压软件包, 并进去解压目录

[root@svr5 data]# tar -zxvf nginx-1.0.15.tar.gz    
[root@svr5 data]# 
[root@svr5 data]# cd nginx-1.0.15

3、升级参数的配置


[root@svr5 nginx-0.8.55]# ./configure  \
> --prefix=/usr/local/nginx   \
> --user=nginx  \
> --group=nginx  \
> --with-http_stub_status_module  \
> --with-http_ssl_module
...............................

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1 library is not used
  + using system zlib library

  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"

4、编译

[root@svr5 nginx-1.0.15]# make


5、老版本的备份

[root@svr5 nginx-1.0.15]# mv /usr/local/nginx/sbin/nginx  /usr/local/nginx/sbin/nginxbak

6、将拷贝新版本

[root@svr5 nginx-1.0.15]# cp /data/nginx-1.0.15/objs/nginx /usr/local/nginx/sbin/

7、软件升级

[root@svr5 nginx-1.0.15]# 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 nginx-1.0.15]# 

8、查看当前版本

[root@svr5 nginx-1.0.15]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.0.15
[root@svr5 nginx-1.0.15]#

三、补充说明

1、安装或升级时的指定配置信息

[root@svr5 nginx-0.8.55]# pwd
/data/nginx-0.8.55                                # 1. 进去到 nginx 源码主目录
[root@svr5 nginx-0.8.55]# ./configure --help      # 2. 查看配置的帮助信息

2、nginx 主程序(/usr/local/nginx/sbin/nginx) 

注:

① 、nginx 服务默认情况下是没有启动和停止服务的脚本的

②、nginx 服务启动

[root@svr5 sbin]# netstat -naptu | grep nginx
[root@svr5 sbin]# /usr/local/nginx/sbin/nginx      # 启动 nginx 服务
[root@svr5 sbin]# netstat -naptu | grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      13483/nginx         
[root@svr5 sbin]# 

③、nginx 服务关闭

方式1:在主程序(/usr/local/nginx/sbin/nginx)上加参数( -s stop ) 方式关闭

[root@svr5 sbin]# netstat -naptu | grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      13483/nginx         
[root@svr5 sbin]# /usr/local/nginx/sbin/nginx -s stop        # 停止 nginx 服务
[root@svr5 sbin]# netstat -naptu | grep nginx
[root@svr5 sbin]# 

方式2:使用 ps + kill 命令关闭

[root@svr5 sbin]# /usr/local/nginx/sbin/nginx              # 1. 启动 nginx 服务
[root@svr5 sbin]# ps aux | grep nginx | grep -v "grep"     # 2. 查看主程序的pid, 这里是 13523
root      13523  0.0  0.0  45032  1032 ?        Ss   15:45   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx     13524  0.0  0.0  45452  1580 ?        S    15:45   0:00 nginx: worker process      
[root@svr5 sbin]# netstat -naput | grep nginx              # 3. 端口也处于监听状态
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      13523/nginx         
[root@svr5 sbin]# 
[root@svr5 sbin]# 
[root@svr5 sbin]# kill 13523                               # 4. 杀死 nginx 服务的主程序
[root@svr5 sbin]# 
[root@svr5 sbin]# 
[root@svr5 sbin]# ps aux | grep nginx | grep -v "grep"     # 5. 再次确认nginx 服务进程已经被杀死
[root@svr5 sbin]# netstat -naput | grep nginx              # 6. 再次确认 nginx 服务端口已经被关闭
[root@svr5 sbin]# 

④、主程序 ( /usr/local/nginx/sbin/nginx ) 的帮助信息

[root@svr5 sbin]# /usr/local/nginx/sbin/nginx -h
nginx version: nginx/1.0.15
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

[root@svr5 sbin]# 

猜你喜欢

转载自blog.csdn.net/u010559460/article/details/88776512
今日推荐