一次Nginx负载均衡的安装与配置
1、环境介绍
3台linux服务器,其中两台tomcat作应用,一台nginx作两台tomcat的负载
OS:redhat 5.4
app:tomcat6
nginx:1.0.5
2、实现功能
通过配置nginx,实现负载均衡,会话保持,高速缓存静态文件以及手动清除缓存文件
3、所需组件
所有文件放在/home/install/目录下
pcre-8.12.zip 、openssl-1.0.0d.tar.gz、nginx-upstream-jvm-route-0.1.tar.gz、ngx_cache_purge-1.3.tar.gz
4、安装过程
安装会话保持组件
cd nginx-1.0.5
patch -p0 < /home/install/nginx_upstream_jvm_route/jvm_route.patch
减压各组件
配置nginx
./configure --prefix=/usr/local/nginx --with-http_ssl_module --without-http_fastcgi_module --with-http_flv_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/client/ --http-proxy-temp-path=/usr/local/nginx/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/cgi/ --with-openssl=/home/install/openssl/ --add-module=/home/install/nginx_upstream_jvm_route --with-http_stub_status_module --add-module=/home/install/ngx_cache_purge-1.3 --with-http_perl_module --with-pcre=/home/install/pcre-8.12
部分组件说明
会话保持: --add-module=/home/install/nginx_upstream_jvm_route
缓存清除组件: --add-module=/home/install/ngx_cache_purge-1.3
编译安装
make &&make install
5、配置nginx.conf
#Nginx.conf version Nginx 1.0.5
#by Wugh Email:wjlw2008@hotmail.com QQ:5951083
user nobody;
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 51200;
events {
use epoll;
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
limit_zone one $binary_remote_addr 10m;
open_file_cache max=51200 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 30s;
server_names_hash_bucket_size 128;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
request_pool_size 4k;
client_max_body_size 8m;
server_name_in_redirect off;
include gzip.conf;
proxy_temp_path /opt/data/proxy_temp_dir;
proxy_cache_path /opt/data/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=20g;
upstream www.test.com {
server 192.168.0.10 srun_id=server1 weight=6;
server 192.168.0.20 srun_id=server2 weight=4;
jvm_route $cookie_JSESSIONID reverse;
}
server
{
listen 80;
server_name www.test.com;
#oldweb cache files
location ~ /oldweb(/.*)
{
#allow 192.168.0.0/24;
#deny all;
proxy_cache_purge cache_one $scheme$host$1$is_args$args;
error_page 405 =200 /oldweb$1;
access_log off;
}
#auto purge webold cache
if ( $request_method = "PURGE" ) {
rewrite ^(.*)$ /oldweb$1 last;
}
#auto "/"
# if (-d $request_filename){
# rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
# }
#pass files
location /
{
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://www.test.com;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 75;
proxy_send_timeout 75;
proxy_read_timeout 75;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
access_log off;
}
#cache files 只缓存htm、html、gif、jpg、jpeg、png、ico、css、js、txt、flv、swf、doc、ppt、xls、docx、pptx、xlsx、pdf文件
#并通过"Ctrl+F5"刷新清除指定缓存文件
location ~ .*\.(htm|html|gif|jpg|jpeg|png|ico|css|js|txt|flv|swf|doc|ppt|xls|docx|pptx|xlsx|pdf)$
{
if ($http_Cache_Control = "no-cache") {
rewrite ^(.*)$ /oldweb$1 last;
}
add_header X-Cache $upstream_cache_status;
proxy_cache cache_one;
proxy_cache_valid 200 304 2m;
proxy_cache_valid 301 302 1m;
proxy_cache_valid any 1m;
proxy_cache_key $scheme$host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://www.test.com;
expires 1d;
access_log off;
}
#nginx status 显示在线情况
location /fwtj {
#allow 192.168.0.0/24;
#deny all;
stub_status on;
access_log off;
}
}
}
6、配置gzip.conf
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
7、操作系统sysctl.conf优化
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536
# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536
# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736
# Controls the maximum number of shared memory segments, in pages
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 4096 4194304
net.ipv4.tcp_wmem = 4096 4096 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 786432 2097152 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000
8、nginx常用命令
检查配置文件是否错误: ./nginx -t
启动nginx:./nginx
重新加载配置文件:/nginx -s reload 或 kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
停止nginx: ./nginx -s stop
转载于:https://blog.51cto.com/tetop/756198
一次Nginx负载均衡的安装与配置相关推荐
- 50.Nginx负载均衡 ssl原理 密钥对 配置ssl
2019独角兽企业重金招聘Python工程师标准>>> 12.17 Nginx负载均衡 12.18 ssl(https)原理 12.19 生成ssl密钥对 12.20 Nginx配置 ...
- Linux: ------安装JDK、Tomcat、MySQL、Nginx、Tomcat负载均衡集群、Nginx负载均衡策略、MSM配置
1.安装JDK 1.1 下载jdk # 1.下载jdkhttps://www.oracle.com/technetwork/java/javase/downloads/index.html# 2.通过 ...
- Nginx负载均衡:分布式/热备Web Server的搭建
Nginx是一款轻量级的Web server/反向代理server及电子邮件(IMAP/POP3)代理server.并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开 ...
- 宝塔Nginx负载均衡
宝塔Nginx负载均衡 注意点: 配置了负载均衡后,前端没有分配服务器,先检查后端服务器的端口是否被放行 在站点的配置文件中添加多个后端服务器 upstream myschool {server 12 ...
- Docker集群环境下安装Fastdfs集群+Nginx负载均衡
一.环境配置 现有两台服务器10.168.103.110(旧服务器)和10.168.103.111(新服务器),其中110服务器上有swarm集群,一个tracker和一个storage,现在要做Fa ...
- Nginx负载均衡的详细配置及使用案例
Nginx负载均衡的详细配置及使用案例详解 感谢看过这一些列博文和评论的小伙伴, 我把自己所看到的学到的拿到这里来分享是想和大家一起学习进步, 想听听园友给出的意见, 也是对自己学习过程的一个总结. ...
- [ 总结 ] nginx 负载均衡 及 缓存
操作系统:centos6.4 x64 前端使用nginx做反向代理,后端服务器为:apache + php + mysql 1. nginx负载均衡. nginx编译安装(编译安装前面的文章已经写过) ...
- docker初体验:docker部署nginx负载均衡集群
Docker 是一个用于开发,交付和运行应用程序的开放平台.Docker 使您能够将应用程序与基础架构分开,从而可以快速交付软件.今天来为大家演示一下docker部署nginx负载均衡集群 环境 ce ...
- Keepalived+LVS+Nginx负载均衡之高可用
2019独角兽企业重金招聘Python工程师标准>>> 上一篇写了nginx负载均衡,此篇实现高可用(HA).系统整体设计是采用Nginx做负载均衡,若出现Nginx单机故障,则导致 ...
最新文章
- Oracle中不同条件的日期查询
- 探讨Java I/O类和接口
- 第一阶段_第一部分_工具介绍
- 布局中常见的居中问题
- Scrapy源码阅读分析_1_整体框架和流程介绍
- cortex m4 中文手册_江淮瑞风M4柴油版上市 售13.88-15.48万
- python3.8.2安装ipython_CentOS系统 python3+python2 Ipython安装
- DispatcherHelper
- 3.2 决策树可视化
- 计算机cpu基础知识ppt,计算机硬件基础知识ppt课件
- gcode 解析入门1-1
- hash和history路由的区别
- html5 fa图标库,axure官方制作FontAwesome图标元件库V5.5.0版
- SaaS订阅收费模式的精髓是:预充值
- 不是python文件操作的相关函数_从零开始学Python(七):文件存储I/O流和异常捕捉
- xshell用rz上传文件,彻底解决乱码
- arcgis中python坡度计算_ArcGIS坡度计算
- 2023年日程安排APP哪个好用?日程提醒软件用哪个?
- 天野第四期易语言半内存辅助培训课程
- ERP系统解决机械设备制造企业售后管理难题
热门文章
- 小程序版本独立微信社群人脉系统社群空间站源码全开源
- 自动采集电脑壁纸PHP源码美化版
- ajax-FormData快速序列化表单数据以及文件上传
- quot;在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvokequot;
- asp.net c# lock 有关
- Flexslider图片轮播、文字图片相结合滑动切换效果
- Flex 中 12 个简单实用的小技巧
- 大数——大数判等(hdu2054)
- composer中文阿里云镜像地址
- VS2010生成的文件在别的机器上运行提示“丢失MSVCR100D.dll”