V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Newyorkcity
V2EX  ›  问与答

哎..tomcat7 的两个问题

  •  
  •   Newyorkcity · 2019-04-28 15:12:11 +08:00 · 1227 次点击
    这是一个创建于 1796 天前的主题,其中的信息可能已经有所发展或是发生改变。
    有两个项目 webapp1.war,webapp2.war
    要求 webapp1 只能直接通过 ip:port 访问到
    webapp2 只能通过 ip:port/webapp2/的方式访问到
    (后面的 index.jsp 省略了)
    该如何配置做到?
    网站没有开发完成,webapp1 和 webapp2 两个 war 包可能会更新,如何不关闭 tomcat 和服务器,做到一个 war 包被替换了,tomcat 能随时监察到并同步更新覆盖?

    谢谢!
    7 条回复    2019-04-28 16:53:11 +08:00
    HuasLeung
        1
    HuasLeung  
       2019-04-28 15:38:19 +08:00 via Android
    tomcat 配置 2 个虚拟主机分别对应 webapp1 和 webapp2(ip:port 中的端口是不是同一个?)

    传统的 war 包部署应该做不到同步更新覆盖。如果配置了.war 文件在 tomcat 运行就自解压,war 包的文件名是个问题——新上传的 war 包如果跟旧的 war 包同名解压后应该会冲突(没试过…),不同名则需重新修改 server.xml 中虚拟主机 appBase 对应的路径
    funky
        2
    funky  
       2019-04-28 15:39:56 +08:00
    war 应该实现不了热更新吧
    Newyorkcity
        3
    Newyorkcity  
    OP
       2019-04-28 16:11:45 +08:00
    @HuasLeung 是同一个..我是在 conf/server.xml 文件里这么写的
    <Context docBase="webapp1.war" path="" reloadable="true" debug="0"/>
    <Context docBase="webapp2.war" path="/webapp2" reloadable="true" debug="0"/>
    webapp1 会自动生成 webapp1 文件夹,但不能通过 ip:port 的方式访问,只能通过 ip:port/webapp1 的方式访问..我也很气..
    Newyorkcity
        4
    Newyorkcity  
    OP
       2019-04-28 16:12:23 +08:00
    @HuasLeung
    @funky
    实现不了热更新的话 tomcat 有什么办法达成这个效果么?我觉得这个要求对于还在开发的网站不应该是很寻常的么..
    funky
        5
    funky  
       2019-04-28 16:19:10 +08:00   ❤️ 1
    在前面有一个 nginx 后面两个 tomcat 实例,滚动重启
    funky
        6
    funky  
       2019-04-28 16:20:20 +08:00
    webapp1 换成 ROOT 可以 ip:port 直接访问
    LinJunzhu
        7
    LinJunzhu  
       2019-04-28 16:53:11 +08:00   ❤️ 1
    @Newyorkcity

    <Host name="xx.cn" appBase="webapps1"
    unpackWARs="true" autoDeploy="true">
    <Context path="" docBase="/home/ubuntu/projects/webapps1.war" reloadable="true"/>
    </Host>
    <Host name="xx.cn" appBase="webapps2"
    unpackWARs="true" autoDeploy="true">
    <Context path="/hello" docBase="/home/ubuntu/projects/webapps2.war" reloadable="true"/>
    </Host>

    如果想要每次 war 更新都自动热部署, 那么需要写脚本了:

    上传 war 包,并且将 webapps1 webapps2 文件夹下自动解压出的项目移除 ,tomcat 会自动去解压热更新的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3085 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:52 · PVG 20:52 · LAX 05:52 · JFK 08:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.