如何配置AWS / ElasticBeanstalk /泊坞运行的GlassFish实例? [英] How to configure a GlassFish instance running on AWS/ElasticBeanstalk/Docker?

查看:194
本文介绍了如何配置AWS / ElasticBeanstalk /泊坞运行的GlassFish实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的GlassFish来提供一个Java EE Web应用程序。事情正在罚款我的本地开发机器。我有

I'm using GlassFish to serve up a Java EE web app. Things are working fine on my local dev machine. I have

  • 复制的Postgres JDBC库到正确的地方
  • 在GlassFish管理控制台
  • 在配置了连接池和JDBC资源
  • 在部署一个网络应用程序,使用上述连接
  • 看到的结果,我的浏览器
  • copied postgres JDBC libraries into the right place
  • configured a connection pool and JDBC resource in the Glassfish admin console
  • deployed a web-app that uses said connection
  • seen the results in my browser

我试图部署相同的应用程序,以AWS弹性魔豆托管Glassfish的实例。 AWS-EB使用泊坞部署GlassFish实例。我能做的只有第三步以上(部署web应用程序),并且是完全处于亏损怎么办第2位。

I'm trying to deploy that same app to AWS Elastic Beanstalk hosted Glassfish instance. AWS-EB uses Docker to deploy the Glassfish instance. I can do only the third step above (deploy a web-app), and am completely at a loss how to do the first two.

我很想做的是有Web访问通过GlassFish管理控制台,但似乎并没有工作在任何级别。另一种方法是使用玻璃鱼的asadmin我的本地机器配置远程玻璃鱼,但我不能做到这一点无论是。

What I'd love to do is have web-access to the Glassfish admin console via, but that doesn't seem to work at any level. An alternative would be to use the glass fish "asadmin" on my local machine to configure the remote glass fish, but I can't make that happen either.

一个人如何配置托管在AWS EB中的GlassFish实例?它甚至有可能?

How does one configure a Glassfish instance hosted on AWS EB? Is it even possible?

我做了一些意见,但我AP preciate确认或以其他方式:

I've made some observations, but I'd appreciate confirmation or otherwise:

  • 在它看来,AWS在其命令行称为asadmin的',这是对自动缩放命令,并且具有相同的名称为asadmin的附带的GlassFish。除了由谷歌搜索硬盘,两人似乎没有什么可与对方
  • 如果我连接到包含泊坞窗和Glassfish例如,下面的事情发生在AWS EC2实例
    • 须藤泊坞窗PS 返回有端口4848 / TCP,8080 / TCP,8181 / TCP,并且没有被映射
    • wget的本地主机:8080 - 拒绝连接
    • 同样为8181和4848
    • wget的本地主机:80 返回Glassfish的主页的网页
    • it appears that AWS have a command in their CLI called 'asadmin' which is about autoscaling, and has the same name as 'asadmin' that ships with glassfish. Apart from making google searches hard, the two seem to have nothing to do with each other
    • if I connect to the AWS EC2 instance containing the Docker and Glassfish instance, the following things happen
      • sudo docker ps returns that there are ports 4848/tcp, 8080/tcp, 8181/tcp, and that none are mapped
      • wget localhost:8080 - connection refused
      • same for 8181 and 4848
      • wget localhost:80 returns the web page of the Glassfish home page
      • 的wget 1.2.3.4:8080 (与4848,8181),所有返回的HTML文件
      • 的wget 1.2.3.4:80 - 拒绝连接
      • wget 1.2.3.4:8080 (and 4848, 8181) all return html files
      • wget 1.2.3.4:80 - connection refused
      • wget的本地主机:8080 (与4848,8181)都返回中规中矩页
      • wget的本地主机:80 - 拒绝连接
      • wget localhost:8080 (and 4848, 8181) all return well formed pages
      • wget localhost:80 - connection refused

      所以,也许我需要告诉EC2实例从本地主机1.2.3.4转发,但我怎么能做到这一点,当EB负载均衡器扩展出来。

      So maybe I need to tell the EC2 instance to forward on from localhost to 1.2.3.4, but how can I make that happen when the EB load balancer scales it out.

      任何意见将是极大的AP preciated。

      Any advice would be greatly appreciated.

      推荐答案

      下面是一些对我的作品 - 但我有一种感觉,我失去了一些东西。任何编辑/意见将是最受欢迎的。

      What follows is something that works for me - but I have a feeling I'm missing something. Any edits/comments would be most welcome.

      有在EB /泊坞部署各种钩子允许在GlassFish实例运行执行后deployement挂钩,在泊坞窗容器,EB实例中。我用的部署后挂钩,建立一个连接池。下面是最后安装的样子,仅供参考:

      There are various hooks in the EB/Docker deployment that allow execution of post-deployement hooks to be run in a glassfish instance, within a docker container, within a EB instance. I used post-deployment hooks to set up a connection pool. Here's what the final install looks like, just for reference:

      |  | |  \_WAR_/  | | |
      |  | \_Glassfish_/ | |
      |  \____Docker____/  |
      \____EC2 Instance____/
      

      所需的总的结果是,应用程序部署后,泊坞窗实例中,在的asadmin 运行命令来创建一个JDBC连接池,并作出这样的连接池成JDBC资源。在我的本地机器上,该命令将

      The overall desired outcome is that, after the app is deployed, inside the Docker instance, the asadmin commands are run to create a JDBC connection pool, and to make that connection pool into a jdbc resource. On my local machine, the commands would be

      asadmin create-jdbc-connection-pool 
          --datasourceclassname org.postgresql.ds.PGConnectionPoolDataSource 
          --restype javax.sql.ConnectionPoolDataSource 
          --property user=USERNAME:password=PASSWORD:serverName=DBHOST:portNumber=5432:databaseName=DBNAME 
          poolName
      
      asadmin create-jdbc-resource --connectionpoolid poolName jdbc/dev
      

      在哪里JDBC的/ dev'是java的code需要知道得到以通常的方式连接的名称,即

      Where 'jdbc/dev' is the name that the java code needs to know to get a connection in the usual manner i.e.

      InitialContext ctx = new InitialContext();
      ds = (DataSource)ctx.lookup("jdbc/dev");
      

      我们想要的命令泊坞窗实例中运行,由于码头工人的实例可以访问您在AWS管理控制台声明的环境变量,这样我就可以通过配置信息,而不必在我的构建脚本。

      We want the commands to run inside the docker instance, because the docker instance has access to the environment variables that you declare in the AWS admin console, so I can pass configuration information without having it in my build scripts.

      要实现这一结果,我们需要一个文件,在安装过程中的EC2实例创建的,在我的情况下,所谓的 /opt/elasticbeanstalk/hooks/appdeploy/post/99_configure_jdbc.sh 。该文件将被执行的部署后,以root身份,在EC2实例。我将把它作为 EC2-后部署的钩

      To achieve this outcome, we require that a file is created in the EC2 instance during installation, in my case called /opt/elasticbeanstalk/hooks/appdeploy/post/99_configure_jdbc.sh. This file will be executed post-deployment, as root, in the EC2 instance. I'll refer to it as the ec2-post-deploy-hook.

      我们要创建使用.ebextensions / config文件的文件,记录在这里

      We're going to create that file using a .ebextensions/.config file, as documented here

      • http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html
      • http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

      我的config文件有以下内容:

      My .config file has the following contents:

      files:
        "/opt/elasticbeanstalk/hooks/appdeploy/post/99_configure_jdbc.sh":
          mode: "000755"
          owner: root
          group: root
          content: |
            #!/bin/bash
            date > /tmp/post 2>&1
            dockerid=`docker ps | grep latest | cut -d" " -f1`
            echo $dockerid >> /tmp/post 2>&1
            docker ps >> /tmp/post 2>&1
            docker exec $dockerid /var/app/WEB-INF/classes/setup_pool.sh >> tmp/post 2>&1
      

      一切都在内容之后:|。结束在 EC2-后部署钩

      我了解到这个想法从的http:// junkheap .NET /博客/ 2013/05/20 /弹性魔豆,部署后,脚本的。

      I learned this idea from http://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment-scripts.

      只有最后线和4号最后一行是必要的,但其他的线是用于调试。输出结束了在EC2实例的/ tmp /后。

      Only the last line and the 4th last line are needed, but the other lines are useful for debugging. Output ends up in /tmp/post on the EC2 instance.

      在该文件中的一个技巧是,我们总能得到泊坞窗容器的ID,由

      The one trick in that file is that we can always get the ID of the docker container by

      sudo docker ps | grep latest | cut -d" " -f1
      

      由于部署后,将只为一个泊坞容器中运行,它会在其名为最新的。

      because after deployment there will only be one Docker container running, and it will have "latest" in its name.

      EC2-后部署挂机最后一行使用泊坞窗运行,泊坞窗实例中,我本来想运行这些命令 - 也就是说,asadmin命令。我部署一个名为setup_pool.sh在我的.war文件的文件,所以它结束了在一个已知的位置,在部署过程中。我setup_pool.sh看起来像这样(我称之为泊坞窗岗位部署钩):

      The last line of the ec2-post-deploy-hook uses docker to run, inside the docker instance, those commands that I originally wanted run - that is, the asadmin commands. I deploy a file called setup_pool.sh inside my .war file, so it ends up in a known location during deployment. My setup_pool.sh looks like this (and I call it a docker-post-deploy-hook):

      dbuser=$PARAM1
      dbpass=$PARAM2
      dbhost=$PARAM3
      dbname=$PARAM4
      
      date > /tmp/setup_connections
      echo '*********' >> /tmp/setup_connections
      asadmin create-jdbc-connection-pool --datasourceclassname org.postgresql.ds.PGConnectionPoolDataSource --restype javax.sql.ConnectionPoolDataSource --property user=${dbuser}:password=${dbpass}:serverName=${dbhost}:portNumber=5432:databaseName=${dbname} ei-connection-pool >>   /tmp/setup_connections 2>&1
      echo '*********' >> /tmp/setup_connections
      asadmin create-jdbc-resource --connectionpoolid ei-connection-pool jdbc/dev >> /tmp/setup_connections 2>&1
      echo '*********' >> /tmp/setup_connections
      

      本文件内泊坞窗实例中运行。这两个的asadmin 命令都是肉,但同样,有一些调试进/泊坞窗实例中TMP / setup_connections

      This file is run within in docker instance. The two asadmin commands are the meat, but again, there's some debugging into /tmp/setup_connections within the docker instance

      密码等,从AWS环境中获得。

      Passwords, etc, are obtained from the AWS environment.

      我唯一不能做在这一点上是有可在首次部署AWS的环境变量。我不知道为什么,但我只似乎能够设置它们的实例后启动并运行。这意味着,我必须部署两次,虚设部署,其次是环境的编辑,随后通过实际部署。

      The only thing I cannot do at this point is have the AWS environment variables available on first deployment. I have no idea why, but I only seem to be able to set them after the instance is up and running. This means that I have to deploy twice, a dummy deploy, followed by an edit of the environment, followed by a real deploy.

      所以,总结起来,

      • 在部署
        • 在一个config文件生成一个EC2-后部署挂机文件,
        • 的AWS系统部署泊坞窗,后部署挂机作为被其部署到GlassFish将.war的一部分
        • at deployment
          • a .config file generates an ec2-post-deploy-hook file,
          • the AWS system deploys the docker-post-deploy-hook as a part of the .war that is deployed to glassfish
          • 弹性魔豆系统运行在EC2-后部署的钩
          • 的EC2-后部署挂机运行泊坞窗岗位部署钩
          • 泊坞窗岗位部署挂机运行的asadmin设置相应的连接池

          和它所有的作品。它是一种丑陋的外表,但是,你知道的,我也是。

          And it all works. It's kind of ugly to behold, but, you know, so am I.

          这篇关于如何配置AWS / ElasticBeanstalk /泊坞运行的GlassFish实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆