简单的负载均衡Nginx+Tomcat
来源:互联网 发布:怎样让淘宝商品靠前 编辑:程序博客网 时间:2024/05/16 15:06
实验: 一个 Nginx 反向代理服务器+ 多个Tomcat 实例
目的: 实现简单的负载均衡
Nginx: http://nginx.org/download/nginx-1.7.6.tar.gz
Tomcat: http://tomcat.apache.org/download-70.cgi#7.0.56
Install Nginx and Tomcat:
Extract the tar.gz under the use directory
hostip: 192.168.0.30
nginx_port:7777
tomcat_instance_1_name: server1
tomcat_instance_1_name: server2
tomcat_instance_1_name: server3
tomcat_instance_1_port:8080
tomcat_instance_2_port:8081
tomcat_instance_3_port:8082
Create two user on the host: user_1 : proxy and user_2 : web
Configure the Nginx : /home/proxy/nginx/conf/nginx.conf
http{
upstream server1_pool {
server 192.168.0.30:8080;
}
upstream server2_pool {
server 192.168.0.30:8081;
}
upstream server3_pool {
server 192.168.0.30:8082;
}
server {
listen 7777;
location /SERVER2 {
#rewrite "^/cs/(.*)$" "/$1" break;
proxy_pass http://server2_pool/SERVER2;
#proxy_redirect off;
proxy_set_header Host $host:8081;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /SERVER1 {
#rewrite "^/yy/(.*)$" "/$1" break;
proxy_pass http://server1_pool/SERVER1;
#proxy_redirect off;
proxy_set_header Host $host:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /SERVER3 {
#rewrite "^/cs/(.*)$" "/$1" break;
proxy_pass http://server3_pool/SERVER3;
#proxy_redirect off;
proxy_set_header Host $host:8802;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
Start Nginx Server:
cd /home/proxy/nginx/bin
sh start.sh
Configure the Tomcat_instance_1: server.xml
<?xml version='1.0' encoding='utf-8'?>
<Connector executor="webcontainerThreadPool" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" enableLookups="false" backlog="2000" acceptCount="4096" server="crm-web" useBodyEncodingForURI="true" maxHttpHeaderSize="16384" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context docBase="/home/web/tomcat1/webapps" path="/SERVER1" reloadable="false" workDir="/veris/crm/aiweb/servers/crm/work" />
</Host>
</Engine>
</Service>
</Server>
Configure the Tomcat_instance_2: server.xml
<?xml version='1.0' encoding='utf-8'?>
<Connector executor="webcontainerThreadPool" port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" enableLookups="false" backlog="2000" acceptCount="4096" server="crm-web" useBodyEncodingForURI="true" maxHttpHeaderSize="16384" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context docBase="/home/web/tomcat2/webapps" path="/SERVER2" reloadable="false" workDir="/veris/crm/aiweb/servers/crm/work" />
</Host>
</Engine>
</Service>
</Server>
Configure the Tomcat_instance_3: server.xml
<?xml version='1.0' encoding='utf-8'?>
<Connector executor="webcontainerThreadPool" port="8082" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" enableLookups="false" backlog="2000" acceptCount="4096" server="crm-web" useBodyEncodingForURI="true" maxHttpHeaderSize="16384" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context docBase="/home/web/tomcat3/webapps" path="/SERVER2" reloadable="false" workDir="/veris/crm/aiweb/servers/crm/work" />
</Host>
</Engine>
</Service>
</Server>
Start the Tomcat Server:
cd /home/web/tomcat1/bin
sh start-web-server.sh
TEST:
http://192.168.0.30:7777/ ----- If works, it proves nginx server works
http://192.168.0.30:7777/SERVER1----- If works, this page will jump to http://192.168.0.30:8080/SERVER1
http://192.168.0.30:7777/SERVER2----- If works, this page will jump to http://192.168.0.30:8081/SERVER2
http://192.168.0.30:7777/SERVER3----- If works, this page will jump to http://192.168.0.30:8082/SERVER3
- 简单的负载均衡Nginx+Tomcat
- Nginx+Tomcat实现简单的负载均衡
- 基于nginx的tomcat负载均衡和集群(超简单)
- 基于nginx的tomcat负载均衡和集群(超简单)
- 基于nginx的tomcat负载均衡和集群(超简单)
- 基于nginx的tomcat负载均衡和集群(超简单)
- 基于nginx的tomcat负载均衡和集群(超简单)
- 使用nginx+tomcat 搭建简单的负载均衡
- 基于nginx的tomcat负载均衡和集群(超简单)
- windows下tomcat和nginx负载均衡的简单配置!
- 基于nginx的tomcat负载均衡和集群(超简单)
- 简单的Nginx负载均衡
- 简单搭建Nginx+Tomcat负载均衡
- nginx+tomcat简单负载均衡配置
- 简单东西-Nginx实现Tomcat负载均衡
- nginx+tomcat负载均衡
- Nginx+tomcat 负载均衡
- nginx+tomcat负载均衡
- 初步接触Ajax(持续修改中)
- Linux 备忘
- RGB颜色转灰度的算法公式
- 隐私策略
- LeetCode 题解(54): Validate Number
- 简单的负载均衡Nginx+Tomcat
- LeetCode 题目总结/分类
- latex 备忘
- WPF对象级资源的定义与查找
- [Leetcode] N-Queens
- 复合肥和人特锐太热uytuytyu
- 使用 trie tree 实现 auto-completion
- nginx配置解析原理(二)
- CSS中怎么让DIV居中