nginx安裝筆記

雙節點安裝node

1 節點一

1.1 目錄

/usr/localnginx

cd /usr/local服務器

1.2 openssl

rpm -ql opensslless

/usr/share/doc/openssl-1.0.0tcp

# ./configure --prefix=/usr/local/nginx --with-pcre=/usr/share/doc/pcre-7.8/ --with-zlib=/usr/share/doc/zlib-1.2.3 --with-openssl=/usr/share/doc/openssl-1.0.0post

1.3 pcre庫

# rpm -qa | grep pcreui

pcre-7.8-6.el6.x86_64ip

[root@r7 software]# rpm -qa | grep pcremd5

pcre-7.8-6.el6.x86_64ssl

[root@r7 software]#

[root@r7 software]# rpm -e pcre-7.8-6.el6.x86_64

error: Failed dependencies:

libpcre.so.0()(64bit) is needed by (installed) grep-2.6.3-3.el6.x86_64

libpcre.so.0()(64bit) is needed by (installed) less-436-10.el6.x86_64

libpcre.so.0()(64bit) is needed by (installed) httpd-tools-2.2.15-26.el6.x86_64

libpcre.so.0()(64bit) is needed by (installed) sssd-1.9.2-82.el6.x86_64

libpcre.so.0()(64bit) is needed by (installed) httpd-2.2.15-26.el6.x86_64

libpcre.so.0()(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64

libpcre.so.0()(64bit) is needed by (installed) gnote-0.6.3-3.el6.x86_64

libpcrecpp.so.0()(64bit) is needed by (installed) gnote-0.6.3-3.el6.x86_64

pcre is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64

[root@r7 software]#

[root@r7 software]#

[root@r7 software]# rpm -e --nodeps pcre-7.8-6.el6.x86_64

[root@r7 software]# mkdir /usr/local/pcre

[root@r7 software]# rpm -ivh --prefix=/usr/local/pcre/ pcre-7.8-6.el6.x86_64.rpm

沒法安裝,從新只用rpm –ivh安裝後使用rpm –ql 查看安裝路徑

[root@r7 software]# rpm -ql pcre

/lib64/libpcre.so.0

/lib64/libpcre.so.0.0.1

/usr/bin/pcregrep

/usr/bin/pcretest

/usr/lib64/libpcrecpp.so.0

/usr/lib64/libpcrecpp.so.0.0.0

/usr/lib64/libpcreposix.so.0

/usr/lib64/libpcreposix.so.0.0.0

/usr/share/doc/pcre-7.8

pcre要使用源碼包,否則在安裝nginx時會編譯pcre,這時會報錯。

1.4 zlib庫

rpm -qa | grep zlib

zlib-devel-1.2.3-29.el6.x86_64

zlib-1.2.3-29.el6.x86_64

zlib也要使用源碼包

1.5 nginx安裝

cd /usr/local/

tar -xzvf nginx-1.2.8.tar.gz 

cd nginx-1.2.8

./configure --prefix=/usr/local/nginx

須要pcre包

./configure --prefix=/usr/local/nginx --with-pcre=/usr/share/doc/pcre-7.8/

須要zlib包

./configure --prefix=/usr/local/nginx --with-pcre=/usr/share/doc/pcre-7.8/ --with-zlib=/usr/share/doc/zlib-1.2.3

須要OpenSSL

# ./configure --prefix=/usr/local/nginx --with-pcre=/usr/share/doc/pcre-7.8/ --with-zlib=/usr/share/doc/zlib-1.2.3 --with-openssl=/usr/share/doc/openssl-1.0.0

Configuration summary

+ using PCRE library: /usr/share/doc/pcre-7.8/

+ using OpenSSL library: /usr/share/doc/openssl-1.0.0

+ md5: using system crypto library

+ sha1: using system crypto library

+ using zlib library: /usr/share/doc/zlib-1.2.3

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"

[root@r7 nginx-1.2.8]# make

make -f objs/Makefile

make[1]: Entering directory `/usr/local/nginx-1.2.8'

cd /usr/share/doc/pcre-7.8/ \

&& if [ -f Makefile ]; then make distclean; fi \

&& CC="gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \

./configure --disable-shared

/bin/sh: line 2: ./configure: No such file or directory

make[1]: *** [/usr/share/doc/pcre-7.8//Makefile] Error 127

make[1]: Leaving directory `/usr/local/nginx-1.2.8'

make: *** [build] Error 2

make 時,在編譯pcre時報錯。換做pcre的源碼包從新編譯ngnix

cd /usr/local/nginx-1.2.8

# ./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.02 --with-zlib=/usr/share/doc/zlib-1.2.3 --with-openssl=/usr/share/doc/openssl-1.0.0

Configuration summary

+ using PCRE library: /usr/local/pcre-8.02

+ using OpenSSL library: /usr/share/doc/openssl-1.0.0

+ md5: using system crypto library

+ sha1: using system crypto library

+ using zlib library: /usr/share/doc/zlib-1.2.3

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"

make

zlib也要使用源碼包

# ./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.02 --with-zlib=/usr/local/zlib-1.2.8 --with-openssl=/usr/share/doc/openssl-1.0.0

Configuration summary

+ using PCRE library: /usr/local/pcre-8.02

+ using OpenSSL library: /usr/share/doc/openssl-1.0.0

+ md5: using system crypto library

+ sha1: using system crypto library

+ using zlib library: /usr/local/zlib-1.2.8

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"

make install

2 節點二

nginx依賴openssl、pcre、zlib的源碼包。

2.1 安裝包

nginx-1.2.8.tar.gz

openssl-1.0.1c.tar.gz

pcre-8.02.tar.gz

zlib-1.2.8.tar.gz

解壓安裝包至 /usr/local 目錄

openssl若是使用rpm安裝的話,須要兩個都安裝

# rpm -qa | grep openssl

openssl-1.0.0-27.el6.x86_64

openssl-devel-1.0.0-27.el6.x86_64

openssl-devel 安裝須要的依賴包比較多,配置 yum 可簡化安裝

本次安裝使用

2.2 安裝nginx

[root@r8 local]# ls

bin etc games include lib lib64 libexec nginx-1.2.8 openssl-1.0.1c pcre-8.02 sbin share src zlib-1.2.8

[root@r8 local]#

[root@r8 local]# cd nginx-1.2.8/

[root@r8 nginx-1.2.8]# pwd

/usr/local/nginx-1.2.8

[root@r8 local]#

[root@r8 local]# mkdir nginx

[root@r8 local]# cd nginx-1.2.8/

[root@r8 nginx-1.2.8]# ./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.02 --with-zlib=/usr/local/zlib-1.2.8 --with-openssl=/usr/share/doc/openssl-1.0.0

有一些東西沒有找到,好比下面的資源,但不影響安裝

checking for sys/filio.h ... not found

make

make install

須要說明的是,pcre與zlib的安裝,下載相關源碼並解壓到/usr/local,在configre時使用—with-pcre和—with-zlib指向其解壓目錄便可。而openssl服務器上已經有了openssl-1.0.0-27.el6.x86_64,我以yum方式安裝了openssl-devel-1.0.0-27.el6.x86_64,也能夠卸載openssl進行源碼安裝,而後使用—with-openssl指向其安裝目錄便可。

3 經常使用操做

3.1 啓動

[root@r8 sbin]# netstat -ntpl | grep 80

tcp 0 0 0.0.0.0:31713 0.0.0.0:* LISTEN 2803/gpnpd.bin

[root@r8 sbin]# pwd

/usr/local/nginx/sbin

[root@r8 sbin]# ./nginx

[root@r8 sbin]# netstat -ntpl | grep 80

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 27496/nginx

tcp 0 0 0.0.0.0:31713 0.0.0.0:* LISTEN 2803/gpnpd.bin

3.2 配置conf

[root@r8 nginx]# cd conf/

[root@r8 conf]# pwd

/usr/local/nginx/conf

[root@r8 conf]# ls

fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params

fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default

fastcgi_params koi-win nginx.conf scgi_params.default win-utf

[root@r8 conf]# vi nginx.conf

#user nobody;

worker_processes 1;

 

3.3 重啓

# 語法檢查

[root@r8 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

# 重啓

[root@r8 sbin]# ./nginx -s reload

4 經常使用配置

5 遇到問題

5.1 PID錯誤

[root@r8 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

[root@r8 sbin]#

[root@r8 sbin]#

[root@r8 sbin]#

[root@r8 sbin]# ./nginx -s reload

nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

查看nginx.conf配置文件

[root@r8 conf]# vi nginx.conf

#user nobody;

worker_processes 1;

error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

pid logs/nginx.pid;

events {

worker_connections 1024;

}

解決方法:使用nginx –c從新配置nginx.conf文件

[root@r8 sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf

[root@r8 sbin]# ./nginx -s reload

[root@r8 sbin]#

相關文章
相關標籤/搜索