【運維技術】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++html

1、安裝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-devellinux

2、獲取源碼,編譯源碼

  • 能夠經過官方網站獲取版本,咱們這邊獲取的是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源安裝
    編譯的時候使用命令切換路徑nginx

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

  • 安裝路徑
  • 啓動bin路徑
  • 配置路徑
  • pid路徑docker

遇到問題

  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

直接使用命令啓動express

$ nginx

使用命令中止啓動centos

$ systemctl stop nginx
$ systemctl start nginx

參考

相關文章
相關標籤/搜索