阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

142次阅读
没有评论

共计 3299 个字符,预计需要花费 9 分钟才能阅读完成。

一、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

搭建 LVS 负载均衡测试环境  http://www.linuxidc.com/Linux/2014-09/106636.htm

实用负载均衡技术网站性能优化攻略 高清中文 PDF 版  http://www.linuxidc.com/Linux/2014-10/107739.htm

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx 安装配置使用详细笔记 http://www.linuxidc.com/Linux/2014-07/104499.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计3299字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中