本次安装的nginx版本是nginx-1.13.7,仅仅测试使用。
1 [root@yugang home]# cat /etc/issue //查看操作系统版本 2 CentOS release 6.8 (Final) 3 Kernel on an m 4 5 [root@yugang home]# ls 6 nginx-1.13.7 //本次测试安装nginx版本
在安装nginx之前准备工作:
一、环境准备:
安装nginx时必须先安装相应的编译工具:
1 [root@yugang home]# yum -y install gcc gcc-c++ autoconf automake 2 [root@yugang home]# yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
其中gcc gcc-c++属于编译工具,autoconf和automake是安装工具。zlib提供gzip模块,需要zlib库支持,openssl提供ssl功能,pcre支持地址重写rewrite功能
二、编译、安装:
先添加nginx组合nginx用户,具体操作如下:
1 [root@yugang nginx-1.13.7]# groupadd -r nginx # 添加nginx组 2 [root@yugang nginx-1.13.7]# useradd -s /sbin/nologin -g nginx -r nginx #添加nginx用户到nginx组 3 [root@yugang nginx-1.13.7]# id nginx 4 uid=498(nginx) gid=498(nginx) groups=498(nginx) #查看nginx用户信息,是否加入到nginx组里面,以及id标识信息
nginx的安装需要到官网下载相关的包,链接:www.nginx.org。
#tar -zxvf nginx-1.13.7.tar.gz #cd nginx-1.13.7 #编译安装并且指定安装位置和模块 [root@yugang nginx-1.13.7]# ./configure > --prefix=/usr/local > --sbin-path=/usr/sbin/nginx > --conf-path=/etc/nginx/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/client > --http-proxy-temp-path=/var/tmp/nginx/proxy > --http-fastcgi-temp-path=/var/tmp/nginx/fcgi > --with-http_stub_status_module 运行发现提示以下错误,发现是模块写错了。 可以通过./configure --help查看,修改成正确的即可: 问题1:./configure: error: invalid option "--with-http-flv_module" 解决办法:修改成正确的模块名,通过./configure --help查看flv模块全名,也可以不加此模块
部署1.3.7发现上面部分模块已经没有,报错的模块我们先查看模块名是否完全一致,如果查找不到的话我们就先不添加,仅添加几个需要使用到的模块,后期需要再安装。
查看错误并根据查看模块组件我们在此次仅仅安装一下模块。
1 编译: 2 [root@yugang nginx-1.13.7]# ./configure --prefix=/usr/local --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/etc/nginx/nginx.conf --pid-path=/var/log/nginx/nginx.pid --user=nginx --group=nginx --with-http_ssl_module --conf-path=/etc/nginx/nginx.conf --error-log-path=/etc/nginx/nginx.conf --pid-path=/var 3
4 结果: 5 checking for getaddrinfo() ... found 6 checking for PCRE library ... found 7 checking for PCRE JIT support ... not found 8 checking for OpenSSL library ... found 9 checking for zlib library ... found 10 creating objs/Makefile 11 12 Configuration summary 13 + using system PCRE library 14 + using system OpenSSL library 15 + using system zlib library 16 17 nginx path prefix: "/usr/local" 18 nginx binary file: "/usr/sbin/nginx" 19 nginx modules path: "/usr/local/modules" 20 nginx configuration prefix: "/etc/nginx" 21 nginx configuration file: "/etc/nginx/nginx.conf" 22 nginx pid file: "/var/log/nginx/nginx.pid" 23 nginx error log file: "/etc/nginx/nginx.conf" 24 nginx http access log file: "/usr/local/logs/access.log" 25 nginx http client request body temporary files: "client_body_temp" 26 nginx http proxy temporary files: "proxy_temp" 27 nginx http fastcgi temporary files: "fastcgi_temp" 28 nginx http uwsgi temporary files: "uwsgi_temp" 29 nginx http scgi temporary files: "scgi_temp
安装:
1 [root@yugang nginx-1.13.7]# make &&make install 2 以下仅仅显示最后信息,没有报错 3 cp conf/mime.types '/etc/nginx/mime.types.default' 4 test -f '/etc/nginx/fastcgi_params' 5 || cp conf/fastcgi_params '/etc/nginx' 6 cp conf/fastcgi_params 7 '/etc/nginx/fastcgi_params.default' 8 test -f '/etc/nginx/fastcgi.conf' 9 || cp conf/fastcgi.conf '/etc/nginx' 10 cp conf/fastcgi.conf '/etc/nginx/fastcgi.conf.default' 11 test -f '/etc/nginx/uwsgi_params' 12 || cp conf/uwsgi_params '/etc/nginx' 13 cp conf/uwsgi_params 14 '/etc/nginx/uwsgi_params.default' 15 test -f '/etc/nginx/scgi_params' 16 || cp conf/scgi_params '/etc/nginx' 17 cp conf/scgi_params 18 '/etc/nginx/scgi_params.default' 19 test -f '/etc/nginx/nginx.conf' 20 || cp conf/nginx.conf '/etc/nginx/nginx.conf' 21 cp conf/nginx.conf '/etc/nginx/nginx.conf.default' 22 test -d '/var/log/nginx' 23 || mkdir -p '/var/log/nginx' 24 test -d '/usr/local/logs' 25 || mkdir -p '/usr/local/logs' 26 test -d '/usr/local/html' 27 || cp -R html '/usr/local' 28 test -d '/etc/nginx' 29 || mkdir -p '/etc/nginx' 30 make[1]: Leaving directory `/home/nginx-1.13.7' 31 [root@yugang nginx-1.13.7]# make &&make install
启动nginx:
1 启动nginx 2 [root@yugang nginx]# /usr/sbin/nginx -c /etc/nginx/nginx.conf 3 查看nginx进程是否启动 4 [root@yugang nginx]# ps -ef | grep nginx 5 root 3654 1 0 15:26 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf 6 nginx 3655 3654 0 15:26 ? 00:00:00 nginx: worker process 7 root 3661 28754 0 15:28 pts/0 00:00:00 grep nginx 8 停止nginx,根据前面进程号来发送强制停止信号 9 [root@yugang nginx]# ps -ef | grep nginx 10 root 3654 1 0 15:26 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf 11 nginx 3655 3654 0 15:26 ? 00:00:00 nginx: worker process 12 root 3661 28754 0 15:28 pts/0 00:00:00 grep nginx 13 [root@yugang nginx]# kill -9 3654 3655
平滑启动nginx和监测nginx配置文件
1 [root@yugang nginx]# kill -HUP 3669 平滑启动nginx 2 [root@yugang nginx]# /usr/sbin/nginx -t -c /etc/nginx/nginx.conf 3 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 4 nginx: configuration file /etc/nginx/nginx.conf test is successful