[JAVA] Cluster for GlassFish

需要兩台服務器分別安裝glassfish。如果你只有一台服務器,那麼你可以利用Solaris的zone技術來虛擬兩台主機
下面以一個例子來說明如果建立Glassfish的Cluster
Server1(10.0.0.1);Server2(10.0.0.2)
1.分別在Server1和Server2上編輯/etc/hosts
#vi /etc/hosts
10.0.0.1 server1-hostname
10.0.0.2 server2-hostname
2.分別在兩台機器上安裝glassfish
(1)下載glassfish http://glassfish.dev.java.net/
(2)安裝glassfish
#java -Xmx256m -jar filename.jar
#cd glassfish
#ant -f setup-cluster.xml
3.在Server1上啟動glassfish domain1
#cd /glassfish/bin
#./asadmin
Use "exit" to exit and "help" for online help.
asadmin> start-domain

(然後你就可以在瀏覽器中輸入http://10.0.0.1:4848 可能到管理界面了)
asadmin> create-node-agent gf1
asadmin> start-node-agent gf1
Please enter the master password [Enter to accept the default]:>
Redirecting output to /glassfish/nodeagents/gf1/agent/logs/server.log
Redirecting application output to /glassfish/nodeagents/gf1/agent/logs/server.log
Command start-node-agent executed successfully.
4.在Server2上
#cd /glassfish/bin
#./asadmin
Use "exit" to exit and "help" for online help.
asadmin> start-node-agent --host 10.0.0.1 --port 4848 gf2
asadmin> start-node-agent gf2
5.在管理界面的左面欄裡你會在「node agents」下看到2個node:gf1和gf2.
6.在圖形界面上選擇「Clusters」,在右面欄選擇「new」。你需要為每個節點創建一個實例,然後選擇OK。等創建完成一個cluster後,選中clus ter前面的複選框,然後重新起動Clsuter,所有的服務應該能正常啟動了。

Glassfish的cluster機制,採用內存複製方法,把用戶的Session自動複製到另外一台機制上,既保證了高可用性,又降低了過多網絡複製帶來的負面 作用,提高了性能。

沒有留言:

張貼留言