Environment:
- CentOS based 7.4
$ cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
sudo yum -y install java-1.8.0-openjdk-devel.x86_64
sudo yum install -y maven
$ cd works
$ wget http://download.jboss.org/wildfly/8.2.0.Final/wildfly-8.2.0.Final.zip
$ sudo mkdir /opt/jboss/
$ sudo unzip wildfly-8.2.0.Final.zip -d /opt/jboss
ヒープサイズを変更する。
- Xms64m -> -Xms512m
- Xmx512m -> -Xmx1024m
- XX:MaxPermSize=256m -> -XX:MaxPermSize=1024m
$ cd /opt/jboss/wildfly-8.2.0.Final/bin/
$ cp -p standalone.conf standalone.conf.org
$ vim standalone.conf
# JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true"
JAVA_OPTS="-Xms512m -Xmx1024m -XX:MaxPermSize=1024m -Djava.net.preferIPv4Stack=true"
バインドアドレスを 127.0.0.1 → 0.0.0.0へ変更する。
$ cd /opt/jboss/wildfly-8.2.0.Final/standalone/configuration
$ sudo cp -p standalone.xml standalone.xml.org
$ sudo vim standalone.xml
JBossの管理コンソールへログインするためのユーザを作成する。
- ユーザ名 : admin
- パスワード : P@ssw0rd
cd /opt/jboss/wildfly-8.2.0.Final/bin/
sudo ./add-user.sh
What type of user do you wish to add?
a) Management User (mgmt-users.properties)
b) Application User (application-users.properties)
(a): a
Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
Username : admin
The username 'admin' is easy to guess
Are you sure you want to add user 'admin' yes/no? yes
Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
- The password should not be one of the following restricted values {root, admin, administrator}
- The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
- The password should be different from the username
Password :
Re-enter Password :
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[ ]:
About to add user 'admin' for realm 'ManagementRealm'
Is this correct yes/no? yes
Added user 'admin' to file '/opt/jboss/wildfly-8.2.0.Final/standalone/configuration/mgmt-users.properties'
Added user 'admin' to file '/opt/jboss/wildfly-8.2.0.Final/domain/configuration/mgmt-users.properties'
Added user 'admin' with groups to file '/opt/jboss/wildfly-8.2.0.Final/standalone/configuration/mgmt-groups.properties'
Added user 'admin' with groups to file '/opt/jboss/wildfly-8.2.0.Final/domain/configuration/mgmt-groups.properties'
Is this new user going to be used for one AS process to connect to another AS process?
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? no
Download app
sudo yum install git
cd works
git clone https://github.com/jboss-developer/ticket-monster.git
build app
$ mvn clean package
...
[INFO] Packaging webapp
[INFO] Assembling webapp [ticket-monster] in [/home/azureuser/works/ticket-monster/demo/target/ticket-monster]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/azureuser/works/ticket-monster/demo/src/main/webapp]
[INFO] Webapp assembled in [245 msecs]
[INFO] Building war: /home/azureuser/works/ticket-monster/demo/target/ticket-monster.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2:13.799s
[INFO] Finished at: Tue May 08 18:46:43 UTC 2018
[INFO] Final Memory: 28M/179M
[INFO] ------------------------------------------------------------------------
target/ticket-monster.warができていればOK
Start Jboss & Check
sudo /opt/jboss/wildfly-8.2.0.Final/bin/standalone.sh
Check if it's running
curl http://localhost:8080
Deploy application
sudo cp -p target/ticket-monster.war /opt/jboss/wildfly-8.2.0.Final/standalone/deployments/
Accesssing the application
curl http://localhost:8080/ticket-monster/
# from public IP
curl http://<Wildfly Server Public IP>:8080/ticket-monster/
import.sqlの修正. 下記import.sqlの内容をこちらに変更.
cd ticket-monster/demo/src/main/resources
mv import.sql import.sql.org
wget https://raw.githubusercontent.com/ikedaj/JBossExample/master/ticket-monster/demo/src/main/resources/import.sql
続いてjboss-deployment-structure.xml」に「resteasy-jackson-provider」を設定する。
# vim ./src/main/webapp/WEB-INF/jboss-deployment-structure.xml
<jboss-deployment-structure>
<deployment>
<exclusions>
</exclusions>
<!-- This allows you to define additional dependencies, it is the same
as using the Dependencies: manifest attribute -->
<dependencies>
<module name="org.jboss.resteasy.resteasy-jackson-provider" annotations="true" />
<module name="org.jboss.as.naming" />
<module name="org.jboss.as.server" />
<module name="org.jboss.msc" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Build and deploy again
mvn clean package
sudo cp -p target/ticket-monster.war /opt/jboss/wildfly-8.2.0.Final/standalone/deployments/
Accesssing the application
curl http://<Wildfly Server Public IP>:8080/ticket-monster/
Download JDBC driver
wget https://jdbc.postgresql.org/download/postgresql-9.4-1201.jdbc4.jar
Deploy JDBC driver
sudo mkdir -p /opt/jboss/wildfly-8.2.0.Final/modules/system/layers/base/org/postgresql/main
sudo cp -p /tmp/postgresql-9.4-1201.jdbc4.jar /opt/jboss/wildfly-8.2.0.Final/modules/system/layers/base/org/postgresql/main
Add configuration file to read the JDBC Driver
$ cd /opt/jboss/wildfly-8.2.0.Final/modules/system/layers/base/org/postgresql/main
$ vim module.xml
<module xmlns="urn:jboss:module:1.0" name="org.postgresql">
<resources>
<resource-root path="postgresql-9.4-1201.jdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Configure Datasource
$ cd /opt/jboss/wildfly-8.2.0.Final/standalone/configuration
$ sudo cp -p standalone.xml standalone.xml.tmp
sudo vim standalone.xml
# <datasources> - </datasources>に次の設定をいれる
<datasource jndi-name="java:jboss/datasources/TicketMonsterPostgreSQLDS" pool-name="PostgreSQLDS" enabled="true">
<connection-url>jdbc:postgresql://postgres:5432/ticketmonster</connection-url>
<driver>org.postgresql</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>***USER***</user-name>
<password>***PASSWORD***</password>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
<driver name="org.postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
DB Data Persisitence 設定
デフォルトの設定では、インスタンスの停止時にテーブルを削除する設定のため、テーブルを維持する設定へ変更する
cd ticket-monster/demo/src/main/resources-postgresql/META-INF
cp -p persistence.xml persistence.xml.org
vi persistence.xml
# <property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.hbm2ddl.auto" value="update" />
HOST追加
sudo vi /etc/hosts
# <PostgreSQL server IP> postgres
172.16.9.7 postgres
Build and deploy again in order to leverage PostgreSQL for persistent data store
$ cd ticket-monster/demo
$ mvn clean package -Ppostgresql
$ sudo cp -p target/ticket-monster.war /opt/jboss/wildfly-8.2.0.Final/standalone/deployments/
Start Script
HOSTNAME=`hostname --ip-address`
#HOSTNAME="dc2018app001"
LOG=/home/azureuser/wildfly/log/wildfly.log
sudo /opt/jboss/wildfly-8.2.0.Final/bin/standalone.sh -c standalone-ha.xml -b=$HOSTNAME -bmanagement=$HOSTNAME -u 230.0.0.4 -Djboss.node.name=$HOSTNAME 2>&1 | tee $LOG &
standalone-ha.xmlへの追加修正
- バインドアドレスを 127.0.0.1 → 0.0.0.0へ変更する。
- Datasourceの追加
sudo vi /opt/jboss/wildfly-8.2.0.Final/standalone/configuration/standalone-ha.xml
cd /
wget http://downloads.jboss.org/mod_cluster//1.2.6.Final/linux-x86_64/mod_cluster-1.2.6.Final-linux2-x64.tar.gz
sudo tar zxvf mod_cluster-1.2.6.Final-linux2-x64.tar.gz
# -> これで /opt/jboss/httpd/ 配下に展開される
sudo vi /opt/jboss/httpd/httpd/conf/httpd.conf
Listen <modcluster server IP>:8081
...
<IfModule manager_module>
Listen 80
ManagerBalancerName mycluster
<VirtualHost *:80>
<Location />
Order allow,deny
Deny from none
#Allow from 172.
Allow from all
</Location>
KeepAliveTimeout 300
MaxKeepAliveRequests 0
#ServerAdvertise on http://@IP@:80
AdvertiseFrequency 5
#AdvertiseSecurityKey secret
#AdvertiseGroup @ADVIP@:23364
EnableMCPMReceive
<Location /mcm>
SetHandler mod_cluster-manager
Order allow,deny
#Deny from all
Allow from all
</Location>
ProxyPass / balancer://mycluster/
</VirtualHost>
</IfModule>