• [nginx学习之道]linux的nginx安装


    准备:首先要安装下一些gcc库用于编译 和一些nginx的扩展lib包:

    [root@localhost nginx-1.8.1]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel

    1.首先去nginx的官网选择要安装的nginx版本并复制其下载的url,并在linux用wget进行下载,tar解压和进入安装的源码目录:

    [root@localhost ~]# wget -c http://nginx.org/download/nginx-1.8.1.tar.gz && tar zxvf ./nginx-1.8.1.tar.gz && cd ./nginx-1.8.1

    然后根据自己的情况以及./configure --help命令查看下一些主要的配置选项:然后进行配置make三部中的一部./configure

    [root@localhost nginx-1.8.1]# ./configure 
     --prefix=/usr/local/nginx 
     --sbin-path=/usr/local/nginx/sbin/ 
     --conf-path=/usr/local/nginx/conf/nginx.conf 
     --error-log-path=/var/log/nginx/error.log 
     --pid-path=/var/run/nginx/nginx.pid 
     --lock-path=/var/lock/nginx.lock 
     --user=nginx 
     --group=nginx 
     --with-http_ssl_module 
     --with-http_flv_module 
     --with-http_gzip_static_module 
     --http-log-path=/var/log/nginx/access.log 
     --http-client-body-temp-path=/var/tmp/nginx/cilent/ 
     --http-proxy-temp-path=/var/tmp/nginx/proxy/ 
     --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/

    遇到的一些问题:

    问题1:(没有安装gcc)

    checking for OS
     + Linux 3.10.0-327.el7.x86_64 x86_64
    checking for C compiler ... not found
    
    ./configure: error: C compiler cc is not found
    解决:
    [root@localhost nginx-1.8.1]# yum -y install gcc gcc-c++ autoconf automake

    问题2:(没有安装一些库,因为在./configure中我用到了 例如ssl等等这个根据自己的实际需求进行安装)

    ./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=<path> option.
    解决:
    [root@localhost nginx-1.8.1]# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

    好接下来用make 去尝试编译下检测下是否有问题(很多时候我们习惯用 make && make install直接进编译安装,那是因为我在下面已经做了测试没有问题在搭建生产环境的时候为了节约时间才这样做的)

    [root@localhost nginx-1.8.1]# make

    如果没有出现error的字眼就说明make检测没有问题。这时候运行make install就会很少有错误。

    [root@localhost nginx-1.8.1]# make install

    Ok到此已经安装完成:

    这个时候我尝试启动下:(根据我上面的./configure 的配置sbin-path是在/usr/local/nginx/sbin/nginx 我的默认配置文件在/usr/local/nginx/conf/nginx.conf)

    [root@localhost nginx-1.8.1]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    nginx: [emerg] getpwnam("nginx") failed

    上面错误提示我没有nginx这个用户和主:两种方式1.将nginx.conf中的user和group修改成已经存在的其他用户。不建议用root;2.创建我指定的用户和组命令如下:

    [root@localhost nginx-1.8.1]# /usr/sbin/groupadd -f nginx
    [root@localhost nginx-1.8.1]# /usr/sbin/useradd -g nginx nginx

    在尝试启动还有错误提示:

    [root@localhost nginx-1.8.1]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    nginx: [emerg] mkdir() "/var/tmp/nginx/cilent/" failed (2: No such file or directory)
    [root@localhost nginx-1.8.1]# mkdir /var/tmp/nginx/cilent
    mkdir: 无法创建目录"/var/tmp/nginx/cilent": 没有那个文件或目录

    解决办法创建:

    [root@localhost nginx-1.8.1]# mkdir -p /var/tmp/nginx/cilent

    然后启动:

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

    OK没有报错:确认是否启动可以用ps -ef | grep nginx去检索下(这里有个技巧,一般nginx的启动都是这种形式,如果你的linux服务器上有很多的nginx.conf这个命令可以帮你更快的锁定现在用的配置文件。)

    [root@localhost nginx-1.8.1]# ps -ef | grep nginx
    root      42388      1  0 15:58 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    nginx     42389  42388  0 15:58 ?        00:00:00 nginx: worker process
    root      42391  10803  0 15:58 pts/1    00:00:00 grep --color=auto nginx
    

    解释下上面的参数   master process 是主进程的意思  pid是 42388 下面的是子进程。

    ok这个进程我们其实还可以去一个文件中看到,对就是我们在./configure 的配置的pid文件:cat下这个文件会看到里面已经有了对应的pid号:

    [root@localhost nginx-1.8.1]# cat /var/run/nginx/nginx.pid 
    42388
    

    这个pid的作用可以让我们在操作nginx和方便:比如说重启 或者停止服务(kill) 或者平滑重启。

    从容停止nginx:
    kill - QUIT `/var/run/nginx/nginx.pid`
    快速停止:
    kill - TERM `/var/run/nginx/nginx.pid`
    强制停止:
    kill - 9 `/var/run/nginx/nginx.pid`
    以上都可以直接指定pid号例如
    kill - QUIT 42388
  • 相关阅读:
    容斥原理学习(Hdu 4135,Hdu 1796)
    ACdream 1112
    CodeChef--Cards, bags and coins
    ACdream 1108(莫队)
    Hdu 2586(LCA)
    CodeChef--EQUAKE
    Hackerrank--Mixing proteins(Math)
    Clash Credenz 2014 Wild Card Round题解
    Codeforces 463D
    CodeChef August Lunchtime 2014 题解
  • 原文地址:https://www.cnblogs.com/patf/p/5796601.html
Copyright © 2020-2023  润新知