2019独角兽企业重金招聘Python工程师标准>>>

1.软件准备

下载Nginx和Tomcat

Nginx:http://nginx.org/en/download.html 这里需要下载稳定版:Stable version 
Tomcat:下载就不说了,这里使用apache-tomcat-6.0.14版本

解压到一个目录

2.修改Tomcat的端口

Tomcat1:修改Server.xml

D:\nginx_cluster\apache-tomcat-6.0.14_1\conf\server.xml 
共修改3处内容:将以下端口都加1

 
  1. <!--第1处-->
  2. <Server port="18005" shutdown="SHUTDOWN">
  3. <!--第2处-->
  4. <Connector port="18080" protocol="HTTP/1.1"
  5. connectionTimeout="20000"
  6. redirectPort="8443" />
  7. <!--第3处-->
  8. <Connector port="18009" protocol="AJP/1.3" redirectPort="8443" />

Tomcat2:修改Server.xml

D:\nginx_cluster\apache-tomcat-6.0.14_2\conf\server.xml 
共修改3处内容:将以下端口都加2

 
  1. <!--第1处-->
  2. <Server port="28005" shutdown="SHUTDOWN">
  3. <!--第2处-->
  4. <Connector port="28080" protocol="HTTP/1.1"
  5. connectionTimeout="20000"
  6. redirectPort="8443" />
  7. <!--第3处-->
  8. <Connector port="28009" protocol="AJP/1.3" redirectPort="8443" />

3.测试Tomcat是否正常运行

分别访问两个Tomcat

http://localhost:18080/ 
http://localhost:28080/ 
都出现猫的页面说明正常,为了区分不同的Tomcat,这里修改${Tmocat_home}\webapps\ROOT\ index.html文件内容,加入内容以便区分

 
  1. <h1>This Tomcat1</h1>

之后再次访问两个Tomcat 
 
 
至此,两个Tomcat运行正常。

4.配置Nginx

修改Nginx的主配置文件: 
D:\nginx_cluster\nginx-1.10.2\conf\ nginx.conf

 
  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. #监听localhost的80端口
  23. server {
  24. listen 80;
  25. server_name localhost;
  26. location / {
  27. proxy_connect_timeout 3;
  28. proxy_send_timeout 30;
  29. proxy_read_timeout 30;
  30. proxy_pass http://localhost;
  31. }
  32. }
  33. # another virtual host using mix of IP-, name-, and port-based configuration
  34. #
  35. #server {
  36. # listen 8000;
  37. # listen somename:8080;
  38. # server_name somename alias another.alias;
  39. # location / {
  40. # root html;
  41. # index index.html index.htm;
  42. # }
  43. #}
  44. #集群配置:服务器列表
  45. upstream localhost {
  46. server localhost:18080 weight=2;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
  47. server localhost:28080 weight=1;
  48. }
  49. # HTTPS server
  50. #
  51. #server {
  52. # listen 443 ssl;
  53. # server_name localhost;
  54. # ssl_certificate cert.pem;
  55. # ssl_certificate_key cert.key;
  56. # ssl_session_cache shared:SSL:1m;
  57. # ssl_session_timeout 5m;
  58. # ssl_ciphers HIGH:!aNULL:!MD5;
  59. # ssl_prefer_server_ciphers on;
  60. # location / {
  61. # root html;
  62. # index index.html index.htm;
  63. # }
  64. #}
  65. }

主要配置

 
 
至此,Nginx的简单配置就完成了。下面开始测试

5.测试集群访问

启动Nginx

进入到Nginx目录 
启动命令为:start nginx 
停止命令为:nginx –s stop 

访问测试

访问:http://localhost/ 
Nginx内部配置了监听80端口,默认进行服务器的分发。 
 
 
随便刷新测试了10次,共访问了Tomcat1共8次,Tomcat2共2次。可以看到权重越大,访问到的概率越大。

6.配置文件

Tomcat1 的Server.xml配置文件

 
  1. <!-- Note: A "Server" is not itself a "Container", so you may not
  2. define subcomponents such as "Valves" at this level.
  3. Documentation at /docs/config/server.html
  4. -->
  5. <Server port="18005" shutdown="SHUTDOWN">
  6. <!--APR library loader. Documentation at /docs/apr.html -->
  7. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  8. <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  9. <Listener className="org.apache.catalina.core.JasperListener" />
  10. <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
  11. <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  12. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  13. <!-- Global JNDI resources
  14. Documentation at /docs/jndi-resources-howto.html
  15. -->
  16. <GlobalNamingResources>
  17. <!-- Editable user database that can also be used by
  18. UserDatabaseRealm to authenticate users
  19. -->
  20. <Resource name="UserDatabase" auth="Container"
  21. type="org.apache.catalina.UserDatabase"
  22. description="User database that can be updated and saved"
  23. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  24. pathname="conf/tomcat-users.xml" />
  25. </GlobalNamingResources>
  26. <!-- A "Service" is a collection of one or more "Connectors" that share
  27. a single "Container" Note: A "Service" is not itself a "Container",
  28. so you may not define subcomponents such as "Valves" at this level.
  29. Documentation at /docs/config/service.html
  30. -->
  31. <Service name="Catalina">
  32. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  33. <!--
  34. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  35. maxThreads="150" minSpareThreads="4"/>
  36. -->
  37. <!-- A "Connector" represents an endpoint by which requests are received
  38. and responses are returned. Documentation at :
  39. Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
  40. Java AJP Connector: /docs/config/ajp.html
  41. APR (HTTP/AJP) Connector: /docs/apr.html
  42. Define a non-SSL HTTP/1.1 Connector on port 8080
  43. -->
  44. <Connector port="18080" protocol="HTTP/1.1"
  45. connectionTimeout="20000"
  46. redirectPort="8443" />
  47. <!-- A "Connector" using the shared thread pool-->
  48. <!--
  49. <Connector executor="tomcatThreadPool"
  50. port="8080" protocol="HTTP/1.1"
  51. connectionTimeout="20000"
  52. redirectPort="8443" />
  53. -->
  54. <!-- Define a SSL HTTP/1.1 Connector on port 8443
  55. This connector uses the JSSE configuration, when using APR, the
  56. connector should be using the OpenSSL style configuration
  57. described in the APR documentation -->
  58. <!--
  59. <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
  60. maxThreads="150" scheme="https" secure="true"
  61. clientAuth="false" sslProtocol="TLS" />
  62. -->
  63. <!-- Define an AJP 1.3 Connector on port 8009 -->
  64. <Connector port="18009" protocol="AJP/1.3" redirectPort="8443" />
  65. <!-- An Engine represents the entry point (within Catalina) that processes
  66. every request. The Engine implementation for Tomcat stand alone
  67. analyzes the HTTP headers included with the request, and passes them
  68. on to the appropriate Host (virtual host).
  69. Documentation at /docs/config/engine.html -->
  70. <!-- You should set jvmRoute to support load-balancing via AJP ie :
  71. <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
  72. -->
  73. <Engine name="Catalina" defaultHost="localhost">
  74. <!--For clustering, please take a look at documentation at:
  75. /docs/cluster-howto.html (simple how to)
  76. /docs/config/cluster.html (reference documentation) -->
  77. <!--
  78. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  79. -->
  80. <!-- The request dumper valve dumps useful debugging information about
  81. the request and response data received and sent by Tomcat.
  82. Documentation at: /docs/config/valve.html -->
  83. <!--
  84. <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
  85. -->
  86. <!-- This Realm uses the UserDatabase configured in the global JNDI
  87. resources under the key "UserDatabase". Any edits
  88. that are performed against this UserDatabase are immediately
  89. available for use by the Realm. -->
  90. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  91. resourceName="UserDatabase"/>
  92. <!-- Define the default virtual host
  93. Note: XML Schema validation will not work with Xerces 2.2.
  94. -->
  95. <Host name="localhost" appBase="webapps"
  96. unpackWARs="true" autoDeploy="true"
  97. xmlValidation="false" xmlNamespaceAware="false">
  98. <!-- SingleSignOn valve, share authentication between web applications
  99. Documentation at: /docs/config/valve.html -->
  100. <!--
  101. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  102. -->
  103. <!-- Access log processes all example.
  104. Documentation at: /docs/config/valve.html -->
  105. <!--
  106. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  107. prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
  108. -->
  109. </Host>
  110. </Engine>
  111. </Service>
  112. </Server>

Tomcat2 的Server.xml配置文件

 
  1. <!-- Note: A "Server" is not itself a "Container", so you may not
  2. define subcomponents such as "Valves" at this level.
  3. Documentation at /docs/config/server.html
  4. -->
  5. <Server port="28005" shutdown="SHUTDOWN">
  6. <!--APR library loader. Documentation at /docs/apr.html -->
  7. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  8. <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  9. <Listener className="org.apache.catalina.core.JasperListener" />
  10. <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
  11. <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  12. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  13. <!-- Global JNDI resources
  14. Documentation at /docs/jndi-resources-howto.html
  15. -->
  16. <GlobalNamingResources>
  17. <!-- Editable user database that can also be used by
  18. UserDatabaseRealm to authenticate users
  19. -->
  20. <Resource name="UserDatabase" auth="Container"
  21. type="org.apache.catalina.UserDatabase"
  22. description="User database that can be updated and saved"
  23. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  24. pathname="conf/tomcat-users.xml" />
  25. </GlobalNamingResources>
  26. <!-- A "Service" is a collection of one or more "Connectors" that share
  27. a single "Container" Note: A "Service" is not itself a "Container",
  28. so you may not define subcomponents such as "Valves" at this level.
  29. Documentation at /docs/config/service.html
  30. -->
  31. <Service name="Catalina">
  32. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  33. <!--
  34. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  35. maxThreads="150" minSpareThreads="4"/>
  36. -->
  37. <!-- A "Connector" represents an endpoint by which requests are received
  38. and responses are returned. Documentation at :
  39. Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
  40. Java AJP Connector: /docs/config/ajp.html
  41. APR (HTTP/AJP) Connector: /docs/apr.html
  42. Define a non-SSL HTTP/1.1 Connector on port 8080
  43. -->
  44. <Connector port="28080" protocol="HTTP/1.1"
  45. connectionTimeout="20000"
  46. redirectPort="8443" />
  47. <!-- A "Connector" using the shared thread pool-->
  48. <!--
  49. <Connector executor="tomcatThreadPool"
  50. port="8080" protocol="HTTP/1.1"
  51. connectionTimeout="20000"
  52. redirectPort="8443" />
  53. -->
  54. <!-- Define a SSL HTTP/1.1 Connector on port 8443
  55. This connector uses the JSSE configuration, when using APR, the
  56. connector should be using the OpenSSL style configuration
  57. described in the APR documentation -->
  58. <!--
  59. <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
  60. maxThreads="150" scheme="https" secure="true"
  61. clientAuth="false" sslProtocol="TLS" />
  62. -->
  63. <!-- Define an AJP 1.3 Connector on port 8009 -->
  64. <Connector port="28009" protocol="AJP/1.3" redirectPort="8443" />
  65. <!-- An Engine represents the entry point (within Catalina) that processes
  66. every request. The Engine implementation for Tomcat stand alone
  67. analyzes the HTTP headers included with the request, and passes them
  68. on to the appropriate Host (virtual host).
  69. Documentation at /docs/config/engine.html -->
  70. <!-- You should set jvmRoute to support load-balancing via AJP ie :
  71. <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
  72. -->
  73. <Engine name="Catalina" defaultHost="localhost">
  74. <!--For clustering, please take a look at documentation at:
  75. /docs/cluster-howto.html (simple how to)
  76. /docs/config/cluster.html (reference documentation) -->
  77. <!--
  78. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  79. -->
  80. <!-- The request dumper valve dumps useful debugging information about
  81. the request and response data received and sent by Tomcat.
  82. Documentation at: /docs/config/valve.html -->
  83. <!--
  84. <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
  85. -->
  86. <!-- This Realm uses the UserDatabase configured in the global JNDI
  87. resources under the key "UserDatabase". Any edits
  88. that are performed against this UserDatabase are immediately
  89. available for use by the Realm. -->
  90. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  91. resourceName="UserDatabase"/>
  92. <!-- Define the default virtual host
  93. Note: XML Schema validation will not work with Xerces 2.2.
  94. -->
  95. <Host name="localhost" appBase="webapps"
  96. unpackWARs="true" autoDeploy="true"
  97. xmlValidation="false" xmlNamespaceAware="false">
  98. <!-- SingleSignOn valve, share authentication between web applications
  99. Documentation at: /docs/config/valve.html -->
  100. <!--
  101. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  102. -->
  103. <!-- Access log processes all example.
  104. Documentation at: /docs/config/valve.html -->
  105. <!--
  106. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  107. prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
  108. -->
  109. </Host>
  110. </Engine>
  111. </Service>
  112. </Server>

Nginx配置文件

 
  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. #监听localhost的80端口
  23. server {
  24. listen 80;
  25. server_name localhost;
  26. location / {
  27. proxy_connect_timeout 3;
  28. proxy_send_timeout 30;
  29. proxy_read_timeout 30;
  30. proxy_pass http://localhost;
  31. }
  32. }
  33. # another virtual host using mix of IP-, name-, and port-based configuration
  34. #
  35. #server {
  36. # listen 8000;
  37. # listen somename:8080;
  38. # server_name somename alias another.alias;
  39. # location / {
  40. # root html;
  41. # index index.html index.htm;
  42. # }
  43. #}
  44. #集群配置:服务器列表
  45. upstream localhost {
  46. server localhost:18080 weight=2;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
  47. server localhost:28080 weight=1;
  48. }
  49. # HTTPS server
  50. #
  51. #server {
  52. # listen 443 ssl;
  53. # server_name localhost;
  54. # ssl_certificate cert.pem;
  55. # ssl_certificate_key cert.key;
  56. # ssl_session_cache shared:SSL:1m;
  57. # ssl_session_timeout 5m;
  58. # ssl_ciphers HIGH:!aNULL:!MD5;
  59. # ssl_prefer_server_ciphers on;
  60. # location / {
  61. # root html;
  62. # index index.html index.htm;
  63. # }
  64. #}
  65. }

转载于:https://my.oschina.net/maliang9527/blog/909306

Nginx+Tomcat简单集群配置相关推荐

  1. Nginx+Tomcat+Memcached集群 【测试成功】

    Nginx+Tomcat+Memcached集群 Tomcat集群session同步方案有以下几种方式: 使用tomcat自带的cluster方式,多个tomcat间自动实时复制session信息,配 ...

  2. Nginx+Tomcat搭建集群环境

    Nginx+Tomcat搭建集群环境 ZeroOne01关注0人评论33534人阅读2018-05-05 14:15:39 集群概述与架构介绍 Tomcat集群能带来什么: 提高服务的性能,例如计算处 ...

  3. 架构系列三:使用Keepalived+Nginx+tomcat实现集群部署

    架构系列三:使用Keepalived+Nginx+tomcat实现集群部署 介绍了通过Nginx配置Tomct集群,当其中一个Tomcat服务停止后,Nginx可自动识别并选择另一个服务器响应用户请求 ...

  4. 架构系列二:使用Nginx+tomcat实现集群部署

    架构系列二:使用Nginx+tomcat实现集群部署 一.环境介绍  VM1:Ubuntu-S100 IP:192.168.130.128 部署Tomcat应用及Nginx  VM2:Ubuntu-S ...

  5. nginx+tomcat实现集群负载均衡(实现session复制)

    架构描述 前端一台nginx服务器做负载均衡器,后端放N台tomcat组成集群处理服务,通过nginx转发到后面(注:没做动静分离,静态动态全部都转给tomcat) 优点:实现了可弹性化的架构,在压力 ...

  6. centos下搭建nginx+tomcat实现集群负载与session复制

    第一章 测试环境说明 1.1 系统说明 系统均选用最小化安装的centos 5.7 1.2 软件说明 nginx-0.8.55 pcre-8.13 apache-tomcat-6.0.35  jdk- ...

  7. Tomcat集群快速入门:Nginx+Tomcat搭建集群

    参数的一些扩展点,那刚刚讲的一些负载均衡策略,都是实际企业当中常用的,负载均衡策略,领着大家分析了优缺点,希望大家好好体会,百分之一百的吸收,那我们现在把这些参数和扩展的点呢,放到一个配置里,一起来给 ...

  8. windows+nginx+tomcat实现集群负载均衡(生产环境必读)

    概念理解(原文链接) 集群:多个tomcat服务器运行同一个web服务就能称之为集群 负载均衡:apache按照一定方式将不同的客户端访问分配到不同的tomcat服务器 简单负载均衡实现: 网上参考了 ...

  9. Linux下nginx+tomcat+memcached集群

    为什么80%的码农都做不了架构师?>>>    集群分为横向集群和纵向集群(纵向意思就是在一台服务器上 横向就是多台服务器 就这么个意思) 一.软件版本 nginx-0.7.65 a ...

最新文章

  1. Nature Methods:基于人工重组菌群数据的宏基因组的软件评估金标准
  2. 第二阶段冲刺10天 第五天
  3. matlab fft函数说明_【V2.0更新】基于FFT算法的MTALAB傅里叶级数3D可视化
  4. linux富文本软件,CherryTree For Linux
  5. 大数据在金融领域的应用及问题时
  6. linux下日志晒选打包,Linux 文件日志筛选操作
  7. Python入门(六)序列之中,序列之间
  8. Swagger注解-@ApiImplicitParams 和 @ApiImplicitParam
  9. php如何架构设计,PHP – 架构设计帮助 – OOP固体原则
  10. macos ntfs插件_NTFS for Mac 助手 - Mac读写NTFS磁盘工具
  11. 我的毕业生涯至从零开始从事编程开发
  12. 土方回填施工方案范本_联投土方回填施工方案样本
  13. pdf工具类 (pd4ml)
  14. 引用 康奈尔大学剪影
  15. 【目标跟踪 SOT】SiamFC -用于对象跟踪的全卷积孪生网络
  16. 计算机科学期刊催稿,SOFT COMPUTING
  17. linux编译怎么选择cpu,使用cpuminer在Linux系统中用CPU挖矿
  18. 计算机中多媒体数据如何表示,多媒体数据的表示方法说明.ppt
  19. 奇葩年年有,每年都很多,临近年关那些奇葩的年终奖
  20. 关于uni-app手机nfc开启、读取、写入功能

热门文章

  1. 微软职位内部推荐-SDE II
  2. jdk1.4容器类关系图
  3. 【转】三天学好ADO
  4. Linux服务配置:Vsftp的基本配置[转]
  5. php中int()强制转换,php下intval()和int强制转换使用的区别是什么
  6. ajax async:false不管用_js 网络请求框架 ajax和axios、fetch的区别
  7. Xamarin.FormsShell基础教程(9)Shell相关类体系
  8. linux怎么修改grub引导顺序,我如何更改GRUB引导顺序?
  9. android phone驱动_[基础知识] 将 OneDrive 同步到 SD 卡等外部驱动器
  10. ubuntu20输入法qiehuan_ubuntu20.04中文输入法安装步骤