JBOSS共享安装

[color=red]本文内容适合于Jboss 4.x系列应用服务器。[/color]

在项目中,我们可能会碰到有多个开发人员共用一个服务器,每个人都需要有单独的开发环境来运行项目程序。如果每个人都安装一个自己的Jboss,这样会浪费很多磁盘空间。另外,还有可能需要在一个服务器上运行多个不同的Jboss项目,或者我们对远程机器上的Jboss目录没有写权限,因此就没有办法把我们的项目放到远程服务器上。为了解决这个问题,Jboss提供的共享安装机制。本文描述了这种机制。
[b]Why use a Shared JBoss Installation Directory?[/b]
Development teams typically have a development lab consisting of shared hardware for testing deployments in a more 'production-like' way. The shared hardware usually has multiple instances of the application deployed on it (a few instances per developer), and one installation of the application server software. For example, on a Linux system it would be common for applications such as JBoss to be installed in the /usr/local directory, and the individual developer instances of the application to be deployed in each user's home directory, or perhaps some other part of the filesystem set up explicitly for deployments. So, you may need a shared installation directory for a number of reasons.

[list=1]
[*]You want to have a directory for each instance of JBoss somewhere other than in the JBoss installation 'server' directory.
[*]There is a shared (Linux or Unix) deployment box where each user refers to the JBoss installation directory which is read only for their account. (Of course, you could have each user have their own copy of JBoss, but that isn't a very good use of disk space)
[*]The JBoss installation is on a network drive and read only.
[/list]

[b]Default directory setup[/b]
After installation, the JBoss home directory will have a server directory under it which will contain a directory for each 'configuration' or 'server name'. Each of these will have a 'deploy' directory underneath it. For example:

JBOSS_HOME
\- server
+- default
\- minimal

For a shared installation, it might not work to have the subdirectories of 'server' for each configuration, or user. So that leaves two problems that must be solved:
[list=1]
[*]How do we tell JBoss to use some directory other than $JBOSS_HOME/server for deployments / configurations?
[*]How do we run multiple instances of JBoss on the same server?
[/list]

[b]JBoss System Properties[/b]
Jboss共享安装的重点在于修改Jboss启动是的系统参数,下面列出了Jboss 4.x系列应用服务器的系统参数。关于Jboss系统参数的详细介绍,可以看下Jboss官方网站的Wiki。
[url]http://www.jboss.org/community/wiki/JBossProperties[/url]
Fortunately, it is quite simple to start JBoss so that it will use a shared installation. The key is to understand how to use the JBoss system properties. These properties depend on each other, care must be taken to set them properly.

[b]Where are the ports defined? [/b]
为了在一台机器上同时启动多个Jboss,每个Jboss的端口都不能重复,关于Jboss的端口及其修改请看本Blog的另外一篇文章:Jboss端口及其修改。

[b]Examples of setting jboss.server.home [/b]
Jboss共享安装的重点在于修改jboss.server.home.dir和jboss.server.home.url这两个启动时的系统参数。下面是Linux和Windows下的两个例子。

[color=green]Example 1 - Linux[/color]
Suppose JBoss is installed in /usr/local/jboss and there is an application deployment in /home/jdavis/myapp. Before starting up JBoss we will need to set some environment variables. We can make a shell script to do this:

#!/bin/bash
# start-env.sh - starts a new shell with instance variables set
export JBOSS_HOME=/usr/local/jboss
JAVA_HOME=/usr/java/jdk1.5.0_04
export PATH=$JAVA_HOME/bin:$JBOSS_HOME/bin:$PATH
echo "Runtime shell..."
$SHELL

~~Note that this script will start a new shell~~, so you can simply exit the shell at any time to go back to the environment variables you had before.

Now, we need to get a sample deployment. For this example, we can copy the 'default' configuration in the JBoss server directory.


$ ./start-env.sh
#$ cp -r $JBOSS_HOME/server/default /home/jdavis/myapp
#原文中是将default拷贝到/home/jdavis/myapp下,但个人觉得应该是拷贝到/home/jdavis目录下面。其实问题也不是很大
$ cp -r $JBOSS_HOME/server/default /home/jdavis


We can now start the 'myapp' server like this:

$ run.sh -Djboss.server.base.dir=/home/jdavis \
-Djboss.server.base.url=file:///home/jdavis -c myapp


除了修改jboss.server.base.dir和jboss.server.base.url这两个属性来启动Jboss之外,我们还可以修改jboss.server.home.dir和jboss.server.home.url这两个属性来启动Jboss,效果是一样的,启动脚本如下。

$ run.sh -Djboss.server.home.dir=/home/jdavis/default \
-Djboss.server.home.url=file:///home/jdavis/default
#使用jboss.server.home.dir和jboss.server.home.url系统属性时,需要将目录指向default
#目录,而不是default的上级目录。-c参数去掉,将你的项目直接放到default/deploy下面。

In this example we've set the server base directory to the directory above the application deployment and used the -c option to specify the sub-directory, which is the default behavior. Also note that the prefix for the URL form of the base directory is file://. The third forward slash is for the filesystem root directory.

[color=green]Example 2 - Windows Command Shell[/color]
This is the equivalent of the previous example.

1. Java is installed in D:/java/jdk1.5.0_09
2. JBoss in installed in D:/java/jboss-4.0.5.GA
3. The local deployment is in D:/jdavis/myapp

Here is the CMD script to start JBoss on the local deployment:

set JBOSS_HOME=D:/java/jboss-4.0.5.GA
set JAVA_HOME=D:/java/jdk1.5.0_09
call %JBOSS_HOME%/bin/run.bat -Djboss.server.base.dir=D:/jdavis \
-Djboss.server.base.url=file:/D:/jdavis -c myapp

In this example, we've set the server base directory to the directory above the application deployment and used the -c option to specify the sub-directory, which is the default behavior.

原文出处:[url]http://shrubbery.mynetgear.net/wiki/Shared_JBoss_Installation_Directory[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值