zoukankan      html  css  js  c++  java
  • 【运维技术】Nginx安装教程(yum安装,源码编译)

    安装方式

    1. yum直接更新源安装
    2. 源码直接编译之后安装

    使用yum进行直接安装

    Installing a Prebuilt CentOS/RHEL Package from an OS Repository

    1. Install the EPEL repository:
    $ sudo yum install epel-release
    
    1. Update the repository and install NGINX Open Source:
    $ sudo yum update
    
    1. Install Nginx
    $ sudo yum install nginx
    
    1. Verify the installation:
    $ sudo nginx -v
    nginx version: nginx/1.6.3
    

    源码直接编译之后安装

    注意点,centos默认需要先安装c以及c++的的编译环境执行命令,在继续后续的操作
    $ yum -y install gcc
    $ yum -y install gcc-c++

    一、安装nginx依赖

    • PCRE – Supports regular expressions. Required by the NGINX Core and Rewrite modules
    $ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
    $ tar -zxf pcre-8.41.tar.gz
    $ cd pcre-8.41
    $ ./configure
    $ make
    $ sudo make install
    
    • zlib – Supports header compression. Required by the NGINX Gzip module.
    $ wget http://zlib.net/zlib-1.2.11.tar.gz
    $ tar -zxf zlib-1.2.11.tar.gz
    $ cd zlib-1.2.11
    $ ./configure
    $ make
    $ sudo make install
    
    • OpenSSL – Supports the HTTPS protocol. Required by the NGINX SSL module and others.
    $ wget http://www.openssl.org/source/openssl-1.0.2k.tar.gz
    $ tar -zxf openssl-1.0.2k.tar.gz
    $ cd openssl-1.0.2k
    $ ./Configure darwin64-x86_64-cc --prefix=/usr
    $ make
    $ sudo make install
    

    遇到问题死都安装不上去,所以使用yum的包进行安装了
    yum -y install openssl openssl-devel

    二、获取源码,编译源码

    • 可以通过官方网站获取版本,我们这边获取的是stable版本,使用脚本处理
    $ wget http://nginx.org/download/nginx-1.13.4.tar.gz
    $ tar zxf nginx-1.13.4.tar.gz
    $ cd nginx-1.13.4
    
    $ ./configure
    --sbin-path=/usr/local/nginx/nginx
    --conf-path=/usr/local/nginx/nginx.conf
    --pid-path=/usr/local/nginx/nginx.pid
    --with-pcre=../pcre-8.41
    --with-zlib=../zlib-1.2.11
    --with-http_ssl_module
    --with-stream
    --with-mail=dynamic
    --add-module=/usr/build/nginx-rtmp-module
    --add-dynamic-module=/usr/build/3party_module
    
    • Completing the Installation from Source
      编译安装
    $ make
    $ sudo make install
    
    • 启动
    # 启动nginx
    $ sudo nginx
    # 启动nginx(守护模式进程常驻)
    $ sudo nginx
    # 停止nginx
    $ nginx pid file: "/usr/local/nginx/logs/nginx.pid"
    $ sudo kill `cat /usr/local/nginx/logs/nginx.pid`
    
    • 卸载nginx
    # 方式一:https://unix.stackexchange.com/questions/22708/how-to-uninstall-nginx-installed-from-source
    $ sudo rm -f -R /usr/local/nginx && rm -f /usr/local/sbin/nginx
    # 方式二:https://serverfault.com/questions/645110/how-to-uninstall-nginx-on-centos7
    $ make uninstall
    
    • 安装两个nginx
      一般一台服务器不会安装两个nginx的,但是特殊情况会,所以一个使用源码编译安装,一个使用yum源安装
      编译的时候使用命令切换路径

    ./configure --prefix=/usr/local/nginx2 --sbin-path=/usr/local/nginx2/nginx2 --conf-path=/usr/local/nginx2/nginx.conf --pid-path=/usr/local/nginx2/nginx.pid

    • 安装路径
    • 启动bin路径
    • 配置路径
    • pid路径

    遇到问题

    1. 源码安装的时候,yum update docker的镜像的使用十分慢,所以我进行了一段时间的等待,但是依旧没有处理完
      解决方案,yum update的时候排除某些。http://blog.51cto.com/pizibaidu/1342925
    yum update --exclude=docker-ce*
    
    1. 发现启动后,有两个进程
      按照进程号的关系判断,master和worker的进程是一定有关联关系的,删除master即可
      参考网址
    root     30870     1  0 16:10 ?        00:00:00 nginx: master process nginx
    nginx    30871 30870  0 16:10 ?        00:00:00 nginx: worker process
    root     31028  8302  0 16:13 pts/0    00:00:00 grep --color=auto nginx
    

    直接使用命令启动

    $ nginx
    

    使用命令停止启动

    $ systemctl stop nginx
    $ systemctl start nginx
    

    参考

  • 相关阅读:
    hdu1087Super Jumping! Jumping! Jumping!
    hdu1159Common Subsequence(最长公共子序列)
    hdu1069Monkey and Banana(最长递增子序列)
    poj2533(最长递增子序列)
    hdu1029Ignatius and the Princess IV
    uva10622(唯一分解定理)
    myeclipse设置技巧
    myeclipse2014新感悟
    小错误汇总
    字符串反转
  • 原文地址:https://www.cnblogs.com/fly-piglet/p/8596274.html
Copyright © 2011-2022 走看看