Centos 环境 nginx 部署安装指导

Centos 环境 nginx 部署安装指导

环境及工具:

Centos 版本 7.2

[root@localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

 

Nginx 版本 1.10

[root@localhost sbin]# ./nginx -v

nginx version: nginx/1.10.2

 

安装过程

1. 将软件安装所需的软件包和补丁上传到 /opt/tools 目录下:

nginx-1.10.2.tar.gz (主安装程序)

nginx_upstream_check_module-master.zip (健康检查补丁包)

nginx-goodies-nginx-sticky-module-ng-08a395c66e42.zip (session 粘连补丁包)

nginx.conf  (nginx 配置文件)

 

2. 安装 nginx 依赖的三方组件包

yum install -y gcc pcre-devel openssl openssl-devel unzip patch

 

3. 解压 nginx 安装包和补丁包

cd /opt/tools

tar -zxvf nginx-1.10.2.tar.gz

unzip nginx_upstream_check_module-master.zip

unzip nginx-goodies-nginx-sticky-module-ng-08a395c66e42.zip

 

4. 安装前打健康检查补丁

cd /opt/tools/nginx-1.10.2

patch -p0 < ../nginx_upstream_check_module-master/check_1.9.2+.patch

 

5. 配置 makefile

./configure  –prefix=/opt/nginx –add-module=../nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ –add-module=../nginx_upstream_check_module-master/

注意:–prefix=/opt/nginx 指定安装目录为 /opt/nginx,若不配置此参数默认路径为 /usr/local/nginx/

 

6. 编译安装 nginx

make

make install

 

7. 覆盖 nginx 默认配置文件

cp /opt/tools/nginx.conf /opt/nginx/conf/

 

8. 根据项目配置 nginx

vi /opt/nginx/conf/ nginx.conf

部分配置项如下

    upstream uma-unimax-web {

    #ip_hash;

    sticky;

    server 10.1.1.124:8330;

    server 10.1.1.124:8331;

    #server 127.0.0.1:8332 down;

    #server 127.0.0.1:8333 down;

    check interval=3000 rise=2 fall=5 timeout=1000 type=http;

}

保存退出后测试配置

cd /opt/nginx/sbin

./nginx -t

 

9. 重启 nginx 服务

查看 nginx 端口号然后 kill 掉

ps -ef | grep nginx

kill -QUIT 进程号

cd /opt/nginx/sbin

./nginx -s reload

 

如果包 pid 的错误

/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf

  

10. 访问 nginx 主页和健康检查页面

http://10.1.1.211/uma-unimax-web

http://10.1.1.211/status

 

11. (可选)为了方便系统配置环境变量

cd

vi .bashrc

export NGINX_HOME=/opt/nginx

export PATH=$PATH:$NGINX_HOME/sbin

保存退出

source .bashrc

配置好以后,可在任意目录输入 nginx 命令

nginx-goodies-nginx-sticky-module-ng-08a395c66e42.zip
nginxPid.zip
Centos 环境 nginx 部署安装指导 - 修正版.docx
nginx.conf.rar
nginx_upstream_check_module-master.zip
nginx-1.10.2.tar.gz