服务器特定配置的自动部署
我有一些使用 Apache Commons Configuration 的 Java 项目,它们被部署到多个环境(开发/测试/生产)中的多个服务器。
所有代码都是相同的,但一些配置项发生了变化,例如 JMS URL(dev 应该指向 dev 等)以及服务器名称和环境(我使用这些配置项进行调试)。
示例:
<config>
<!-- environment can be dev|test|prod -->
<environment>dev</environment>
<serverName>myServer1</serverName>
<jmsUrl>http://my-jms-url-dev1,http://my-jms-url-dev2</jmsUrl>
</config>
目前,我手动部署、构建然后编辑文件以提供特定于服务器的配置。当我将其部署到单独的服务器时,我想要一种自动执行此操作的方法,但我考虑过的所有方法都需要同样的痛苦来设置。
ANT - 使用 SVN 检查项目并使用 ANT 在每台服务器上构建它。 ANT 从两个静态文件(.servername 和 .environment)读取服务器名称和环境,并将特定于服务器的配置复制到通用配置。这样做的问题是,我仍然必须为每台服务器创建一个配置文件(我有 24 台服务器,而且这可能会增加,因此可扩展性不好)。
SVN - 将我的每个项目分支到特定于服务器的发行版。在这里,可扩展性更差,并且维护起来成为一场噩梦。
有人可以给我一些建议吗?
I have some Java projects that use Apache Commons Configuration and they get deployed to multiple servers in multiple environments (dev/test/prod).
All code is the same, but some config items change, such as JMS URLs (dev should point to dev, etc) as well as the server name and environment (I use these config items for debugging).
Example:
<config>
<!-- environment can be dev|test|prod -->
<environment>dev</environment>
<serverName>myServer1</serverName>
<jmsUrl>http://my-jms-url-dev1,http://my-jms-url-dev2</jmsUrl>
</config>
Currently, I deploy, build, then edit the files manually to provide the server-specific configurations. I want a way to automate this when I deploy it to individual servers, but all the ways I've considered require an equal amount of pain to setup.
ANT - Check out the project with SVN and build it on each server with ANT. ANT reads the server name and the environment from two static files - .servername and .environment - and copies a server-specific config to the generic config. The problem with this is, I still have to create a config file for each server (I have 24 servers, and this may increase, so scalability is not good).
SVN - Branch each of my projects to a server-specific distribution. Here, scalability is worse and it becomes a nightmare to maintain.
Does anybody have any tips for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我明白了这一点。
步骤 1.
获取主机名:
步骤二,创建一个模板文件并用于复制该文件并对其进行查找/替换:
.servername.template 文件包含此字符串:
然后,我使用 Web 服务来获取JSON 字符串告诉我所处的环境。我使用该任务来处理 JSON 并获取环境。
对于如此简单的任务来说,相当繁重,但它确实有效!
I figured this out.
Step 1.
Get the host name:
Step two, create a template file and use to copy the file and do a find/replace on it:
The .servername.template file contains this string:
Then, I use a web service to get a JSON string to tell me what environment I'm in. And I use the task to process the JSON and get the environment.
Pretty heavy-duty for such a simple task, but it works!