美文网首页
Day24 windows下nginx集群搭建

Day24 windows下nginx集群搭建

作者: 开发猛男 | 来源:发表于2019-05-29 17:15 被阅读0次

原理:

配置过程:

  1. 复制两个tomcat目录,命名为tomcat1和tomcat2

  2. 修改配置文件,将其所有端口分别在默认配置上+1、+2

  3. 创建test项目测试,只有一个index.jsp,用于获取sessionID

  4. 解压nginx,启动nginx,访问http://localhost,会出现welcome to nginx页面,表面安装成功。

    安装成功
  5. 配置nginx.conf,实现负载均衡。
    5.1 创建upstream serverlib{} 将服务器集群地址放入这里面。集群名,不要有下划线_
    5.2 在location中,篇日志proxy_pass http://serverlib

    负载均衡配置
    此时,访问http://localhost/test 则会自动分配服务器,每个用户会得到不同的session。
  6. 共享session,修改tomcat配置
    6.1 修改tomcat的server.xml 支持共享 Cluster标签下的
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>注释去掉
    6.2 修改项目的配置文件 web.xml中添加一个<distributable/>节点
    此时,多个用户访问服务器集群,即使实际访问到不同的服务器,也会得到相同的session

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>test</display-name>
  <distributable/> //添加这个
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    ...
  </welcome-file-list>
</web-app>

1. 问题:启动tomcat,点击startup.bat闪退

解决:1. 环境变量等配置问题。2. 移除项目不能直接删webapps目录下文件!

2. 安装nginx成功后,配置服务器集群,再次启动,404

关键字:The character [_] is never valid in a domain name
解决:nginx.conf文件中,upstream属性后面服务器集群名称 不能有下划线"_"字符
思路:如果nginx成功配置,会出现nginx自带的404等错误页面,可根据这个判断是服务器出错还是nginx配置问题。

3. 在nginx目录下,使用

nginx -s stop  //关闭nginx
nginx -s reload  //重载配置文件

相关文章

网友评论

      本文标题:Day24 windows下nginx集群搭建

      本文链接:https://www.haomeiwen.com/subject/wsoytctx.html