RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx

上传人:b****1 文档编号:10156058 上传时间:2023-05-24 格式:DOCX 页数:9 大小:17.86KB
下载 相关 举报
RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx_第1页
第1页 / 共9页
RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx_第2页
第2页 / 共9页
RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx_第3页
第3页 / 共9页
RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx_第4页
第4页 / 共9页
RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx_第5页
第5页 / 共9页
RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx_第6页
第6页 / 共9页
RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx_第7页
第7页 / 共9页
RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx_第8页
第8页 / 共9页
RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx_第9页
第9页 / 共9页
亲,该文档总共9页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx

《RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx》由会员分享,可在线阅读,更多相关《RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx(9页珍藏版)》请在冰点文库上搜索。

RedHat65 Linux Nginx+Tomcat负载均衡图文详解.docx

RedHat65LinuxNginx+Tomcat负载均衡图文详解

 

运维资料

(最后修改时间:

2015-6-2415)

目录

Linux下Nginx+tomcat实现负载均衡2

1.1JDK安装2

1.2Tomcat安装2

1.2.1指定JDK2

1.2.2修改端口号2

1.3Nginx安装4

1.3.1安装prce包4

1.3.2安装Nginx5

1.4Nginx配置修改6

1.4.1proxy.conf6

1.4.2gzip.conf6

1.4.3nginx.conf6

1.5负载均衡测试10

Linux下Nginx+tomcat实现负载均衡

Linux下利用Nginx+tomcat实现负载均衡,本次配置如下

10.161.200.90:

nginx服务器端口:

80

10.161.200.91:

tomcat1服务器端口:

8080

10.161.200.92:

tomcat2服务器端口:

8080

1.1JDK安装

Linux系统在不清楚具体部署了那些程序之前最好不要用“.bin”格式的JDK安装文件自动安装。

此操作会更改到其他用户默认环境。

一般选择解压包方式安装,然后在应用程序上直接指定JDK路径。

将jdk-7u51-linux-x64.tar.gz上传到91、92服务器并执行以下语句

tarxvzfjdk-7u51-linux-x64.tar.gz

为方便管理,将解压出的文件夹移动到/opt下并更名为jdk1.7

1.2Tomcat安装

将apache-tomcat-7.0.53上传到需要应用服务器(10.161.200.91以及10.160.121.200.92)

unzipapache-tomcat-7.0.53

为方便管理,将解压出的apache-tomcat-7.0.53文件夹复制到/home文件夹下并更名为tomcat7_v3

1.2.1指定JDK

进入/home/tomcat7_v3/bin,修改catalina.sh文件如下

#OSspecificsupport.$var_must_besettoeithertrueorfalse.

JAVA_HOME='/opt/jdk1.7'#加入jdk路径

1.2.2修改端口号

如果每个Tomcat在不同服务器上则不需要更改端口号,反之则需要修改。

进入/home/tomcat7_v3/conf/修改server.xml文件,

第一处修改(修改时最好按照tomcat顺序,不易出错):

第一个tomcat默认全部不修改

剩下的Tomcat依次修改为8105、8205、8305……

第二处修改:

第一个tomcat默认全部不修改,剩下的Tomcat依次修改为(8180,8444)、(8280,8445)、(8380,8446)……

第三处修改:

第一个tomcat默认全部不修改,剩下的Tomcat依次修改为(8109,8444)、(8209,8445)、(8309,8446)……

第四处修改:

所有得Tomcat依次修改为tomcat1、tomcat2、tomcat3……

完成后启动tomcat分别访问http:

//localhost:

prot以及可以看见tom猫表示tomcat部署成功

1.3Nginx安装

1.3.1安装prce包

Prce包为Nginx正则表达式支持包,将pcre-8.35.tar.gz上传到服务器/soft目录下(该包为nginx依赖包)

tarxvzfpcre-8.35.tar.gz

cdpcre-8.35

./configure

Make

Makeinstall

1.3.2安装Nginx

tarxvzfnginx-1.6.0.tar.gz

cdnginx-1.6.0

./configure--prefix=/opt/nginx

make

makeinstall

安装完成后进入/opt/nginx/sbin目录

Cd/opt/nginx/sbin

nginx

或者

opt/nginx/sbin/nginx

注:

redhat64位机器上nginx可能会读取pcre文件为/lib64/libpcre.so.1文件,所以需要做一个软连接:

ln–s/usr/local/lib/libpcre.so.1/lib64/

在启动nginx(nginx启动不会有任何反馈信息)在浏览器地址栏输入http:

//localhost

提示it’swork或者是nginx的欢迎页面表示成功

1.4Nginx配置修改

1.4.1proxy.conf

在conf文件夹下新建proxy.conf文件并加入如下代码

proxy_redirectoff;

proxy_set_headerHost$host;

proxy_set_headerX-Real-IP$remote_addr;

proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;

client_max_body_size10m;

client_body_buffer_size128k;

proxy_connect_timeout300;

proxy_send_timeout300;

proxy_read_timeout300;

proxy_buffer_size4k;

proxy_buffers432k;

proxy_busy_buffers_size64k;

proxy_temp_file_write_size64k;

1.4.2gzip.conf

在conf文件夹下新建gzip.conf文件并加入如下代码

gzipon;

gzip_min_length1000;

gzip_typestext/plaintext/cssapplication.x-javascript;

1.4.3nginx.conf

打开nginx.conf修改如下

#usernobody;

worker_processes4;#nginx进程数,建议设置为等于CPU总核心数

error_loglogs/error.log;#取消本行及以下三行注释

error_loglogs/error.lognotice;

error_loglogs/error.loginfo;

pidlogs/nginx.pid;

#单个进程最大连接数(最大连接数=连接数*进程数)

events{

worker_connections1024;

}

#设定http服务器

http{

includemime.types;

default_typeapplication/octet-stream;

#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'

#'$status$body_bytes_sent"$http_referer"'

#'"$http_user_agent""$http_x_forwarded_for"';

#access_loglogs/access.logmain;

sendfileon;

#tcp_nopushon;

#keepalive_timeout0;

keepalive_timeout65;

gzipon;#取消注释

server{

listen80default;

server_namelocalhost;

#charsetkoi8-r;

#access_loglogs/host.access.logmain;

location/{

#roothtml;

indexindex.htmlindex.htm;

}

#error_page404/404.html;

#redirectservererrorpagestothestaticpage/50x.html

#

error_page500502503504/50x.html;

location=/50x.html{

roothtml;

}

#proxythePHPscriptstoApachelisteningon127.0.0.1:

80

#

#location~\.php${

#proxy_passhttp:

//127.0.0.1;

#}

#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:

9000

#

#location~\.php${

#roothtml;

#fastcgi_pass127.0.0.1:

9000;

#fastcgi_indexindex.php;

#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;

#includefastcgi_params;

#}

#denyaccessto.htaccessfiles,ifApache'sdocumentroot

#concurswithnginx'sone

#

#location~/\.ht{

#denyall;

#}

}

#anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration

#

#server{

#listen8000;

#listensomename:

8080;

#server_namesomenamealiasanother.alias;

#location/{

#roothtml;

#indexindex.htmlindex.htm;

#}

#}

#upstream的负载均衡,weight是权重,可以根据机器配置定义权重。

weigth参数表示权值,权值越高被分配到的几率越大,此处为配置权值,默认为轮巡方式。

upstreamlocalhost{

#ip_hash;

server192.168.56.102:

8180;#server{ip}:

{prot}[weight];

server192.168.56.102:

8280;

}

server{

listen80;#nginx监听端口

server_name192.168.56.102;#nginx服务名

location/{

proxy_connect_timeout3;

proxy_send_timeout30;

proxy_read_timeout30;

proxy_passhttp:

//localhost;#nginx监听地址

}

}

#HTTPSserver

#

#server{

#listen443ssl;

#server_namelocalhost;

#ssl_certificatecert.pem;

#ssl_certificate_keycert.key;

#ssl_session_cacheshared:

SSL:

1m;

#ssl_session_timeout5m;

#ssl_ciphersHIGH:

!

aNULL:

!

MD5;

#ssl_prefer_server_cipherson;

#location/{

#roothtml;

#indexindex.htmlindex.htm;

#}

#}

}

完成以上配置后执行以下代码检测配置

opt/nginx/sbin/nginx-t

若检测通过这杀掉nginx进程重新启动nginx

1.5负载均衡测试

最简单的测试为:

修改tomcat1以及tomcat2的index.jsp的内容。

然后新建多个会话访问10.161.200.90若tomcat首页不同这表示负载均衡配置成功。

至此,本次配置结束

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2