LNMP環境部署-----之Nginx安裝部署

一、Nginx介紹

   Nginx ("engine x") 是一個高性能的HTTP反向代理服務器,也是一個IMAP/POP3/SMTP服務器。Nginx是由Igor Sysoev爲俄羅斯訪問量第二的Rambler.ru站點開發的,第一個公開版本0.1.0發佈於2004年10月4日。其將源代碼以類BSD許可證的形式發佈,因它的穩定性、豐富的功能集、示例配置文件和低系統資源的消耗而聞名。2011年6月1日,nginx 1.0.4發佈。

Nginx是一款輕量級Web 服務器/反向代理服務器及電子郵件(IMAP/POP3)代理服務器,並在一個BSD-like 協議下發行。由俄羅斯的程序設計師Igor Sysoev所開發,供俄國大型的入口網站及搜索引擎Rambler(俄文:Рамблер)使用。其特點是佔有內存少,併發能力強,事實上nginx的併發能力確實在同類型的網頁服務器中表現較好,中國大陸使用nginx網站用戶有:百度、京東新浪網易騰訊淘寶等。


二、Nginx的安裝方式的對比:

1rpm -ivh 包名.rpm

有依賴問題,安裝A,A需要先安裝B

缺點:不能定製。

2yum安裝解決rpm安裝的依賴問題,安裝更簡單。

優點:簡單、易用、高效

缺點:不能定製。

3、編譯(C語言源碼---編譯二進制等)

./configure(配置)make(編譯),make install (安裝)

優點:可以定製。

缺點:複雜、效低。

4、定製化製作rpm包,搭建yum倉庫,把我定製的rpm包放到yum倉庫,進行yum安裝。

優點:結合了2的優點和3的優點。

缺點:複雜。


三、編譯方式安裝Nginx

3.1安裝之前確認一下相關依賴包

openssl openssl-devel pcre pcre-devel

[root@web02 nginx-1.6.3]# rpm -qa openssl openssl-devel pcre pcre-devel 

pcre-7.8-7.el6.x86_64

pcre-devel-7.8-7.el6.x86_64

openssl-devel-1.0.1e-48.el6_8.3.x86_64

openssl-1.0.1e-48.el6_8.3.x86_64

有以上結果返回代表已經安裝了相關依賴包,如果沒有安裝就使用以下命令進行安裝。

3.2安裝依賴包

[root@web02 yum.repos.d]# yum install pcre pcre-devel -y

[root@web02 yum.repos.d]# yum install openssl openssl-devel -y

[root@web02 nginx-1.6.3]# rpm -qa openssl openssl-devel pcre pcre-devel #<==檢查一下。

3.3創建用戶及相關目錄

[root@web02 ~]# mkdir /home/oldboy/tools/ -p   #<====用於存放軟件的目錄

[root@web02 ~]# useradd -s /sbin/nologin/ -M www  #<=====創建給nginx服務用的虛擬用戶

[root@web02 ~]# cd /home/oldboy/tools/

[root@web02 tools]# wget -q http://nginx.org/download/nginx-1.6.3.tar.gz

[root@web02 tools]# ls

nginx-1.6.3.tar.gz

[root@web02 tools]# tar xf nginx-1.6.3.tar.gz

[root@web02 tools]# ls

nginx-1.6.3  nginx-1.6.3.tar.gz

[root@web02 tools]# cd nginx-1.6.3

[root@web02 nginx-1.6.3]# ./configure --user=www --group=www --prefix=/application/nginx-1.6.3/ --with-http_ssl_module --with-http_stub_status_module

checking for OS

 + Linux 2.6.32-573.el6.x86_64 x86_64

checking for C compiler ... found

 + using GNU C compiler

 + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) 

checking for gcc -pipe switch ... found

checking for gcc builtin atomic operations ... found

............                       #<===C源文件檢查編譯,太多文件這裏省略一部分

creating objs/Makefile


Configuration summary

  + using system PCRE library

  + using system OpenSSL library

  + md5: using OpenSSL library

  + sha1: using OpenSSL library

  + using system zlib library


  nginx path prefix: "/application/nginx-1.6.3/"

  nginx binary file: "/application/nginx-1.6.3//sbin/nginx"

  nginx configuration prefix: "/application/nginx-1.6.3//conf"

  nginx configuration file: "/application/nginx-1.6.3//conf/nginx.conf"

  nginx pid file: "/application/nginx-1.6.3//logs/nginx.pid"

  nginx error log file: "/application/nginx-1.6.3//logs/error.log"

  nginx http access log file: "/application/nginx-1.6.3//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@web02 nginx-1.6.3]# make

[root@web02 nginx-1.6.3]# make install

[root@web02 nginx-1.6.3]# ls      #<===編譯前的文件情況      

auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

[root@web02 nginx-1.6.3]# ls

conf  html  logs  sbin             #<===編譯後的文件情況   

[root@web02 nginx-1.6.3]# ln -s /application/nginx-1.6.3/ /application/nginx   #創建軟鏈接

[root@web02 nginx-1.6.3]# ls -l /application/nginx/

總用量 16

drwxr-xr-x 2 root root 4096 12月 11 10:44 conf

drwxr-xr-x 2 root root 4096 12月 11 10:44 html

drwxr-xr-x 2 root root 4096 12月 11 10:44 logs

drwxr-xr-x 2 root root 4096 12月 11 10:44 sbin

到此軟件編譯安裝完成。

四、啓動Nginx服務

[root@web02 nginx-1.6.3]# /application/nginx/sbin/nginx

[root@web02 nginx-1.6.3]# lsof -i :80

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

nginx   11067 root    6u  IPv4  22775      0t0  TCP *:http (LISTEN)

nginx   11068  www    6u  IPv4  22775      0t0  TCP *:http (LISTEN)


經驗小結:

ln -s /application/nginx-1.6.3/ /application/nginx

軟連接妙用:這條命令可是生產環境的經驗。

1)將nginx安裝的路徑通過軟鏈接的方式更改爲/application/nginx/ 方便人員使用。

2)安裝時指定版本號路徑是爲了便於查看區分當前使用的Nginx版本,也方便以後升級。

3)內部人員使用路徑/application/nginx/

4)當nginx軟件升級編譯成帶新版本號和版本後,刪除原來的軟鏈接,再重新建立尊重的到/application/nginx/的軟鏈接就好。即版本升級,重新創建軟鏈接的路徑不變還是/application/nginx/

5)程序中如果有引用nginx路徑的地方,不需要做任何更改,因爲升級後訪問路徑還是/application/nginx/






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章