zoukankan      html  css  js  c++  java
  • 第二章Nginx服务器的安装、升级详情

    一、获取Nginx服务器安装文件的途径

    二、Linux平台下Nginx服务器的编译和安装

    一、如何获取Nginx服务器安装文件

    1.1.nginx服务器的软件版本包括windows和Linux版两种,在官方网站上可以找到对应版本的下载链接,nginx的官方下载网站为

    http://nginx.org/en/download.html
    

    1.2分别介绍页面上下载部分各个链接的具体含义

    CHANGES-x.x链接,记录的是对应版本的功能变更日志。包括新增功能、功能的优化和功能的缺陷的修复等。
    紧接着“CHANGES-x.x”链接后面的nginx-x.x.x链接,是Nginx服务器的Linux版本下载链接。右击链接,选择
    另存为命令或者专用工具下载
    pap链接,记录的是提供下载版本使用PGP加密自由软件GnuPG计算后的签名。
    nginx/windows-x.x.x链接,是Nginx服务器的windows版本下载链接。

    1.3.获取历史版本

    http://nginx.org/download
    

    二、Nginx服务器安装

    2.1安装依赖

    为了编译nginx源代码,需要标准的GCC编译器 由于Nginx的一些模块需要依赖其他第三方库,通常有pcre库(支持rewrite模块)、zlib(支持gzip模块)和openssl(支持ssl模块)等。

    yum install -y gcc.x86_64 gcc-c++.x86_64 pcre pcre-devel.x86_64 zlib-devel.x86_64 zlib open openssl-devel
    

    2.2linux版本的编译和安装

    解压nginx-1.10.1.tar.gz
    tar xf /usr/local/nginx-1.10.1.tar.gz
    
    进入目录
    cd nginx-1.10.1/
    
    目录详情 [root@Nginx nginx-1.10.1]# ll total 688 drwxr-xr-x 6 1001 1001 4096 Oct 29 12:00 auto -rw-r--r-- 1 1001 1001 262898 May 31 21:47 CHANGES -rw-r--r-- 1 1001 1001 400701 May 31 21:47 CHANGES.ru drwxr-xr-x 2 1001 1001 4096 Oct 29 12:00 conf -rwxr-xr-x 1 1001 1001 2481 May 31 21:47 configure drwxr-xr-x 4 1001 1001 4096 Oct 29 12:00 contrib drwxr-xr-x 2 1001 1001 4096 Oct 29 12:00 html -rw-r--r-- 1 1001 1001 1397 May 31 21:47 LICENSE drwxr-xr-x 2 1001 1001 4096 Oct 29 12:00 man -rw-r--r-- 1 1001 1001 49 May 31 21:47 README drwxr-xr-x 9 1001 1001 4096 Oct 29 12:00 src

    目录介绍

    src目录中放了nginx软件的所有源代码。
    man目录中存放了nginx软件的帮助文档。
    html目录中存放了两个后缀名为.html的静态网页文件。
    config存放了配置文件,包含nginx服务器的基本配置文件和对部分特性的配置文件。
    auto目录,我们可以看到各种脚本资源。
    

    nginx源代码的编译需要使用configure脚本,一是检查环境,根据环境检查结果生成C代码,二是生成makefile文件。 生成makefile文件,并且指定一个安装目录

    ./configure --prefix=/application/nginx-1.10.1
    

    按Enter键运行命令,可以在屏幕上看到configure脚本调用auto目录中的各种脚本对系统环境以及设置进行 检测

    #可以看编译过程 
    [root@Nginx nginx-1.10.1]# make
    #安装
    [root@Nginx nginx-1.10.1]# make install
    

    2.3启动nginx服务,并且查看文件

    检查配置语法
    [root@Nginx nginx-1.10.1]# /application/nginx-1.10.1/sbin/nginx -t
    nginx: the configuration file /application/nginx-1.10.1/conf/nginx.conf syntax is ok
    nginx: configuration file /application/nginx-1.10.1/conf/nginx.conf test is successful
    
    启动
    [root@Nginx nginx-1.10.1]# /application/nginx-1.10.1/sbin/nginx 
    
    查看Ningx目录
    [root@Nginx nginx-1.10.1]# ll
    total 36
    drwx------ 2 nobody root 4096 Oct 29 14:46 client_body_temp
    drwxr-xr-x 2 root   root 4096 Oct 29 14:44 conf
    drwx------ 2 nobody root 4096 Oct 29 14:46 fastcgi_temp
    drwxr-xr-x 2 root   root 4096 Oct 29 14:44 html
    drwxr-xr-x 2 root   root 4096 Oct 29 14:46 logs
    drwx------ 2 nobody root 4096 Oct 29 14:46 proxy_temp
    drwxr-xr-x 2 root   root 4096 Oct 29 14:44 sbin
    drwx------ 2 nobody root 4096 Oct 29 14:46 scgi_temp
    drwx------ 2 nobody root 4096 Oct 29 14:46 uwsgi_temp
    

    另外,在没有改动源代码的情况下如果需要重新编译和安装nginx软件,就不必再使用configure脚本生成makefile了。可以先删除上次安装的nginx软件。 

    rm -rf /application/nginx-1.10.1
    

    然后回到/cd/usr/local/nginx-1.10.1目录,清除上次编译的遗留文件,make clean 之后再使用make install

    nginx服务器的安装目录中主要包括了conf、html、logs和sbin等4个目录

    conf目录中存放的是nginx所有配置文件,其中nginx.conf文件是nginx服务器的主配置文件
    html目录中存放了Nginx服务器在运行过程中调用的一些html网页文件。
    log目录,是用来存放Nginx服务器日志的
    sbin目录,就是nginx服务器的主程序
    

    2.4nginx服务的启停控制  

     Nginx在运行时,会保持一个和多个worker process工作进程。

    [root@Nginx nginx-1.10.1]# ps -ef | grep 'nginx'
    root       6857      1  0 14:46 ?        00:00:00 nginx: master process /application/nginx-1.10.1/sbin/nginx
    nobody     6858   6857  0 14:46 ?        00:00:00 nginx: worker process  
    

    nginx服务的启动

    -t 检测是否要错误,可以结合-q 如果没有错误信息,将不会输出内容
    [root@Nginx nginx-1.10.1]# nginx -t
    nginx: the configuration file /application/nginx-1.10.1/conf/nginx.conf syntax is ok
    nginx: configuration file /application/nginx-1.10.1/conf/nginx.conf test is successful
    
    查看版本号,和编译的参数
    [root@Nginx nginx-1.10.1]# nginx -V
    nginx version: nginx/1.10.1
    built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) 
    configure arguments: --prefix=/application/nginx-1.10.1
    
    查看版本号
    [root@Nginx nginx-1.10.1]# nginx -v
    nginx version: nginx/1.10.1
    
    平滑重启
    [root@Nginx nginx-1.10.1]# nginx -s reload
    
    启动nginx服务
    [root@Nginx nginx-1.10.1]# nginx 
    

    nginx服务的信号控制在nginx服务的启停办法中,有一类是通过信号机制来实现的。 通过给nginx服务的主进程发送信号就可以控制服务的启停了。

    2.5查看nginx主进程号的两种途径

    查看Logs目录下的nginx.pid
    
    使用ps -ef | grep nginx
    

    2.6nginx服务可接收的信号

    信号                作用
    TERM或INT	快速停止nginx服务
    QUIT	        平缓停止nginx服务
    HUP		使用新的配置文件启动进程,之后平缓停止原有进程,也就是所谓的平滑重启
    USR1		重新打开日志文件,常用于日志切割,
    USR2		使用新版本的nginx文件启动服务,之后平缓停止原有Nginx进程,也就是所谓的平滑升级
    WINCH		平缓停止worker process,用于nginx服务器平滑升级
    

    向nginx服务主进程发送信号也有两种方法。一种是使用nginx二进制文件,另一种方法是使用kill命令发送信号

    kill -s signal pid
    signal,用于指定信号,即上面的信号
    pid 指定nginx服务主进程的PID,也可以使用nginx.pid动态获取PID号
    

    三、Nginx服务器的升级  

    例如:公司业务需求,需要升级nginx-1.11.5 ,首先要备份好

    [root@Nginx application]# tar zcvf nginx-1.10.1.tar.gz nginx-1.10.1/
    

    3.1.查看老版本的编译参数

    [root@Nginx nginx-1.10.1]# nginx -V
    nginx version: nginx/1.10.1
    built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) 
    configure arguments: --prefix=/application/nginx-1.10.1
    

    3.2升级nginx-1.11.5

    tar xf nginx-1.11.5.tar.gz
    cd nginx-1.11.5/
    ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.10.1 --with-http_stub_status_module
     make && make install
    

    3.3备份并替换老nginx程序

    mv /application/nginx-1.10.1/sbin/nginx /application/nginx-1.10.1/sbin/nginx_1.10.1
    cp /usr/local/nginx-1.11.5/objs/nginx /application/nginx-1.10.1/sbin/nginx
    

    3.4查看替换的版本

    [root@Nginx application]# nginx -V
    nginx version: nginx/1.11.5
    built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) 
    configure arguments: --user=nginx --group=nginx --prefix=/application/nginx-1.10.1 --with-http_stub_status_module
    

    3.5检测配置文件并重新启动

    /application/nginx-1.10.1/sbin/nginx -t
    /application/nginx-1.10.1/sbin/nginx -s reload
    

    3.6用浏览器访问以下是否可以

  • 相关阅读:
    rename 批量重命名
    shell脚本实现轮询查看进程是否结束
    mysql 修改max_connections
    window10下的solr6.1.0入门笔记之---安装部署
    php下载大文件
    【转】Pyhton 单行、多行注释符号使用方法及规范
    window10系统下使用python版本实现mysql查询
    Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
    【Visual Studio】 使用EF、 Linq2Sql快速创建数据交互层(一)
    【OPCAutomation】 使用OPCAutomation实现对OPC数据的访问
  • 原文地址:https://www.cnblogs.com/lucktomato/p/15171813.html
Copyright © 2011-2022 走看看