linux nginx 安装

参考文章:
http://blog.csdn.net/dyllove98/article/details/8892509 
http://www.open-open.com/lib/view/open1387774089140.html 
http://blog.sina.com.cn/s/blog_4f925fc30102eo76.html 

安装软件通用:
perl Makefile.PL 是生成makefile之前的check!!!!
要是有报错:就把其他机器上的perl Makefile.PL后的整个文件夹全部拿到不能安装的机器上,这时候 make test 下就能看出问题。少库和软件的信息就出现了

Nginx的安装:

确保系统安装了g++、gcc、openssl-devel、pcre-devel和zlib-devel软件。
可以用     rpm -qa | grep xxx来查询是否安装了。

依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包.
模块依赖性Nginx需要依赖下面3个包
1. gzip 模块需要 zlib 库 ( 下载:  http://www.zlib.net/  )
2. rewrite 模块需要 pcre 库 ( 下载:  http://www.pcre.org/  )
3. ssl 功能需要 openssl 库 ( 下载:  http://www.openssl.org/  )

Nginx包下载:  http://nginx.org/en/download.html


第一步:安装依赖软件

     可以 yum -y install openssl   zlib zlib-devel  pcre pcre-devel   按顺序安装相应的软件
或者如下一例
      1.安装openssl-fips-2.0.2.tar.gz
[root@localhost mrms]# tar -zxvf openssl-fips-2.0.2.tar.gz   //解压下载
[root@localhost mrms]# cd openssl-fips-2.0.2
[root@localhost openssl-fips-2.0.2]# ./config 
[root@localhost openssl-fips-2.0.2]# make         //编译
[root@localhost openssl-fips-2.0.2]# make install //安装

第二步:安装nginx    tar包安装

官网: http://nginx.org 
下载页面: http://nginx.org/en/download.html 

下载nginx 压缩包
     wget  http://nginx.org/download/nginx-1.8.0.tar.gz  
[root@localhost ~]# tar -zxvf    nginx-1.8.0.tar.gz
[root@localhost ~]#mkdir /usr/local/nginx
[root@localhost ~]# cd  nginx-1.8.0
[root@localhost    nginx-1.8.0 ] ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
                                   //安装软件指定到这个目录 和加载后面这个模块来为后面检测用

报错,缺少pcre库,需安装pcre-devel软件:
..................
checking for getaddrinfo() ... found
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.

[root@shtest nginx-1.8.0]#
configure报错: http://codingstandards.iteye.com/blog/1560835  

正常状态输出内容:   下面也有显示哪里未找到,不报错就没有关系的吧。
...................................................
checking for system md5 library ... not found       md5 是一种加密的策略
checking for OpenSSL md5 crypto library ... not found
checking for sha1 in system md library ... not found
checking for OpenSSL sha1 crypto library ... not found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using builtin md5 code
  + sha1 library is not found
  + using system zlib library

  nginx path prefix: "/opt/nginx"
  nginx binary file: "/opt/nginx/sbin/nginx"
  nginx configuration prefix: "/opt/nginx/conf"
  nginx configuration file: "/opt/nginx/conf/nginx.conf"
  nginx pid file: "/opt/nginx/logs/nginx.pid"
  nginx error log file: "/opt/nginx/logs/error.log"
  nginx http access log file: "/opt/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@localhost  nginx-1.8.0] ]#

[root@localhost    nginx-1.8.0 ] make
[root@localhost    nginx-1.8.0 ]  make install      或者make&&make install 

正确显示状态:
......................
test -d '/usr/local/nginx/conf'           || mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types'           || cp conf/mime.types '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
test -f '/usr/local/nginx/conf/fastcgi_params'           || cp conf/fastcgi_params '/usr/local/nginx/conf'
cp conf/fastcgi_params           '/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf'           || cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params'           || cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params           '/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params'           || cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params           '/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf'           || cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs'           || mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' ||           mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html'           || cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' ||           mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/root/nginx-1.8.0'

检查是否安装成功: 
[root@localhost    nginx-1.8.0 ]  cd  /usr/local/nginx/sbin
[root@localhost    nginx-1.8.0 ]  ./nginx -t

报错解决:
./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
从错误看出是缺少lib文件导致,进一步查看下:
ldd $(which /usr/local/nginx/sbin/nginx)
linux nginx 安装_第1张图片

可以看出 libpcre.so.1 => not found 并没有找到,进入/lib目录中手动链接下(这里的/lib目录指的是系统的根目录下面的lib目录)
32位系统 [root@mysqlslave lib]# ln -s /usr/local/lib/libpcre.so.1 /lib
64位系统 [root@mysqlslave lib]# ln -s /usr/local/lib/libpcre.so.1 /lib64

结果显示正常:
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


启动nginx:
[root@localhost sbin]# pwd
/usr/local/nginx/sbin

[root@localhost sbin]# ll
total 3060
-rwxr-xr-x 1 root root 3125764 Jun 12 07:17 nginx
[root@localhost sbin]# ./nginx 
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)   (报错)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@localhost sbin]#
[root@localhost sbin]#
[root@localhost sbin]# lsof -i:80                                                           (默认端口被占用)
COMMAND   PID   USER   FD   TYPE DEVICE SIZE NODE NAME
httpd   14294 apache    4u  IPv6  42918       TCP *:http (LISTEN)
httpd   14295 apache    4u  IPv6  42918       TCP *:http (LISTEN)
httpd   14296 apache    4u  IPv6  42918       TCP *:http (LISTEN)
httpd   17230   root    4u  IPv6  42918       TCP *:http (LISTEN)
httpd   27443 apache    4u  IPv6  42918       TCP *:http (LISTEN)
httpd   27444 apache    4u  IPv6  42918       TCP *:http (LISTEN)
httpd   27445 apache    4u  IPv6  42918       TCP *:http (LISTEN)
httpd   27446 apache    4u  IPv6  42918       TCP *:http (LISTEN)
httpd   27447 apache    4u  IPv6  42918       TCP *:http (LISTEN)
httpd   27448 apache    4u  IPv6  42918       TCP *:http (LISTEN)
httpd   27449 apache    4u  IPv6  42918       TCP *:http (LISTEN)
httpd   27450 apache    4u  IPv6  42918       TCP *:http (LISTEN)
[root@localhost sbin]#  ps -ef | grep httpd | grep -v grep | cut -c 9-15 | xargs kill -s 9       //查找出来nginx的pid,并杀掉其进程
[root@localhost sbin]# ./nginx
[root@localhost sbin]#
[root@localhost sbin]# ps -ef | grep nginx
root     14389     1  0 11:20 ?        00:00:00 nginx: master process ./nginx
root     14393 10845  0 11:20 pts/2    00:00:00 grep nginx
[root@localhost sbin]# 
[root@localhost sbin]# ps -ef | grep 14389
root     14389     1  0 11:20 ?        00:00:00 nginx: master process ./nginx
root     14400 10845  0 11:22 pts/2    00:00:00 grep 14389

报错:Q&A

linux nginx 安装_第2张图片



后面的nginx的配置等等还未操作
/usr/local/nginx/conf/nginx.conf文件的配置详细

下面来说说基本的操作命令,在nginx目录下的sbin目录下。

./nginx -h #帮助  

./nginx -v #显示版本  

./nginx -V #显示版本和配置信息  

./nginx -t #测试配置  

./nginx -q #测试配置时,只输出错误信息  

./nginx -s stop #停止服务器  

./nginx -s reload #重新加载配置  

然后请看图片所示conf文件的配置,来配置nginx的方法

Nginx的默认配置文件就是在nginx/conf/nginx.conf,/etc/nginx/conf.d 的路径是需要自己去创建的。
如果你需要把 nginx.conf 这个主配置放在其他位置,可以在启动nginx的时候用 -c 参数指定

sudo /opt/nginx/sbin/ngixn -c /etc/nginx/conf.d/nginx.conf

最后再多提一句日志的问题,nginx的默认日志目录为/usr/local/nginx/logs目录。
这个目录下面有3个文件,分别是access.log,error.log和nginx.pid;
其中error.log是错误日志,如果在启动nginx时遇到错误可以到这里来查看错误问题。
对应的日志,nginx.pid里存放的是进程的pid。
linux nginx 安装_第3张图片

你可能感兴趣的:(应用运维,linux,nginx,tar,gz)