您的位置:首页 > 运维架构 > Nginx

Nginx负载均衡优化插件编译及配置

2014-09-04 21:29 393 查看
一、 Ngix依赖模块安装

Ngix依赖模块有:pcre、zlib、openssl、md5 /sha1(如果系统中没有安装相应模块,需要按照下列方式安装)

1、 安装pcre模块(8.35)

官方网站:http://www.pcre.org/

安装命令:

# unzip pcre-8.35.zip

# cd pcre-8.35

# ./configure

# make && make install

在64位linux系统中,nginx搜索的库位置为lib64;所以,需要建立软连接:

# ln -s /usr/local/lib/libpcre.so.1 /lib64/

# ln -s /usr/local/lib/libpcre.so.1 /lib/

# ln -s /usr/local/lib/libpcre.so.1 /usr/local/lib64/

2、 安装zlib模块(1.2.8)

官方网站:http://www.zlib.net/

安装命令:

# tar zxvf zlib-1.2.8.tar.gz

# cd zlib-1.2.8

# ./configure

# make && make install

3、 安装openssl模块(1.0.1h)

官方网站:http://www.openssl.org/

安装命令:

# tar zxvf openssl-1.0.1h.tar.gz

# cd openssl-1.0.1h

# ./config

# make &&make install

4、 解压Nginx插件

1) nginx_upstream_hash插件

负载均衡Hash策略插件。

官方网站:https://github.com/evanmiller/nginx_upstream_hash

# unzip nginx_upstream_hash-master.zip

2) nginx-sticky-module插件

负载均衡基于cooki的会话粘合插件,反向代理会话指向相同后端服务器。注:官方下载的源码,在源代码ngx_http_sticky_module.c中的295行代码编译错误,需要将第295行的 ngx_http_sticky_srv_conf_t *conf = iphp->sticky_conf; 放到第297行。

官方网站:https://github.com/yaoweibin/nginx-sticky-module

# unzip nginx-sticky-module-master.zip

3) ngx_pagespeed插件

前端网页访问提速优化插件。

官方网站:https://github.com/pagespeed/ngx_pagespeed

https://dl.google.com/dl/page-speed/psol/1.8.31.4.tar.gz

# unzip ngx_pagespeed-master.zip

# cp 1.8.31.4.tar.gz ./ngx_pagespeed-master

# cd ngx_pagespeed-master

# tar -xzvf 1.8.31.4.tar.gz

二、 Nginx安装

1、 安装Nginx(1.6.0)

官方网站:http://nginx.org/

安装命令:

# tar zxvf nginx-1.6.0.tar.gz

# cd nginx-1.6.0

# ./configure --user=TSP \

--prefix=/usr/local/nginx \

--with-http_ssl_module \

--with-http_stub_status_module \

--with-http_realip_module \

--add-module=/home/TSP/nginx/plugin/nginx_upstream_hash-master \

--add-module=/home/TSP/nginx/plugin/nginx-sticky-module-master \

--add-module=/home/TSP/nginx/plugin/ngx_pagespeed-master

# make && make install

安装完成后的Nginx的目录结构:

[root@AP nginx-1.6.0]# ll /usr/local/nginx/

total 16

drwxr-xr-x 2 root root 4096 Jun 24 14:42 conf

drwxr-xr-x 2 root root 4096 Jun 24 14:42 html

drwxr-xr-x 2 root root 4096 Jun 24 14:42 logs

drwxr-xr-x 2 root root 4096 Jun 24 14:42 sbin

2、 修改配置文件中的监听端口,确保不被其他程序占用

修改配置文件:/usr/local/nginx/conf/nginx.conf

修改端口:80->9090

2.1、设置Linux防火墙,打开端口9090

执行命令:

# /sbin/iptables -I INPUT -p tcp --dport 9090 -j ACCEPT

保存设置命令:

# /etc/rc.d/init.d/iptables save

查看端口打开情况命令:

#/etc/init.d/iptables status

重启防火墙服务

# /etc/rc.d/init.d/iptables restart

3、 启动、停止Nginx

A、 启动命令

#/usr/local/nginx/sbin/nginx

B、 停止命令

# /usr/local/nginx/sbin/nginx -s stop

C、 检查配置文件

# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

D、 查看nginx版本及完整版本

# /usr/local/nginx/sbin/nginx –V

nginx version: nginx/1.6.0

# /usr/local/nginx/sbin/nginx –V

nginx version: nginx/1.6.0

built by gcc 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)

configure arguments: --prefix=/usr/local/nginx --with-openssl=/usr/local/openssl --with-http_stub_status_module
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: