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]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章