LoginSignup
0
0

More than 5 years have passed since last update.

Wildfly+H2Databaseのアプリケーションサーバを冗長化

Posted at

H2DatabaseをEmbedded型で利用しているアプリケーションをWildflyにシングルトンデプロイさせて冗長化する。
GlusterFSでミラーリング領域を作成し、その領域をデータベースの保存先として使用する。

GlusterFSのインストールと領域の確保

想定するパラメータ
 Wildflyのベースディレクトリ(WILDFLY_HOME): /opt/wildfly
 H2Databaseの保存先: /opt/wildfly/h2database
 Wildflyの起動user/group: wildfly/wildfly
 GlusterFSに割り当てる領域: /var/glusterfs

[root@host1]# yum -y install centos-release-gluster
[root@host1]# yum -y install glusterfs-server
[root@host1]# systemctl stop firewalld
[root@host1]# systemctl disable firewalld
[root@host1]# systemctl start glusterd
[root@host1]# systemctl enable glusterd
[root@host1]# mkdir /var/glusterfs
[root@host1]# chown -R wildfly.wildfly /var/glusterfs
[root@host1]# mkdir /opt/wildfly/h2database
[root@host1]# chown -R wildfly.wildfly /opt/wildfly/h2database
[root@host2]# yum -y install centos-release-gluster
[root@host2]# yum -y install glusterfs-server
[root@host2]# systemctl stop firewalld
[root@host2]# systemctl disable firewalld
[root@host2]# systemctl start glusterd
[root@host2]# systemctl enable glusterd
[root@host2]# mkdir /var/glusterfs
[root@host2]# chown -R wildfly.wildfly /var/glusterfs
[root@host2]# mkdir /opt/wildfly/h2database
[root@host2]# chown -R wildfly.wildfly /opt/wildfly/h2database
Gluster Volumeの作成
[root@host1]# gluster peer probe host2
[root@host1]# gluster volume create h2database replica 2 host1:/var/glusterfs host2:/var/glusterfs force
[root@host1]# gluster volume start h2database
Gluster Volumeのマウント
/etc/fstab
localhost:/h2database /opt/wildfly/h2database glusterfs defaults,_netdev,nofail 0 0

ここでOSをリブートして、ミラーリング動作を確認してみる。
host1,host2それぞれの端末で

[root@host1]# touch /opt/wildfly/h2database/test.txt
[root@host2]# tail -f /opt/wildfly/h2database/test.txt

としておき

[root@host1]# echo "test" >> /opt/wildfly/h2database/test.txt

した時に、host2側に反映されればOK。
テストが完了したら、/opt/wildfly/h2database/test.txt は削除しておく。

H2Databaseの接続URL
jdbc:h2:file:~/h2database/(Database Name)
WebContent/META-INFにsingleton-deployment.xmlを配置
singleton-deployment.xml
<?xml version="1.0" encoding="UTF-8"?>
<singleton-deployment xmlns="urn:jboss:singleton-deployment:1.0"/>
動作テスト

上記のように作成したアプリケーションをhost1,host2の順で、両方のサーバにデプロイする。
(Wildflyのconfigはstandalone(-full)-ha.xmlで立ち上げ)

host1のサーバでのみ動作していること(host2側にアクセスした場合には404 Not Found)を確認の上、host1を停止させた時にhost2側でアプリケーションが立ち上がってくることを確認する。

[root@host2]# tail -f /var/log/wildfly/server.log
[root@host1]# systemctl stop wildfly

host2側でシングルトンアプリが立ち上がるとともに、H2Databaseのjdbcドライバがデプロイされてhost2側で動作を継続する。

/var/log/wildfly/server.log
2019-01-31 17:39:41,143 INFO  [org.wildfly.clustering.server] (DistributedSingletonService - 1) WFLYCLSV0003: host2 elected as the singleton provider of the jboss.deployment.unit."XXXXX.war".installer service
....
2019-01-31 17:39:43,575 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)

あとはkeepalivedでロードバランスするなり何なりしてやれば冗長化の完了♪

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0