Java rakendusserver WildFly

Allikas: Imre kasutab arvutit

Sissejuhatus

WildFly http://wildfly.org/ on JBoss AS vaba tarkvaralise Java rakendusserveri (st java protsess, mille kõhus aetakse ringi java rakendusi, tavaliselt veebirakendusi) uus suund. 2016 aastal on viimane stabiilne versioon 10.

Aadressil http://jbossas.jboss.org/downloads soovitatakse kasutada WildFly rakendusserverit.

Tööpõhimõte

  • standalone - kõige tavalise üksik WildFly eksemplar
  • domain - omavahel koostöös käivitatud WildFly arvutite klaster
  • jboss-cli.sh - utiliidiga saab ette nn WildFly prompti, millest saab serveri tööd juhtida

Operatsioonisüsteemi keskkonna ettevalmistamine

Kasutatakse Ubuntu v. 16.04 64 bit operatsioonisüsteemi. Tekitatakse kasutaja:grupp wildfly:wildfly

# useradd --system -m -d /opt/wildfly-home wildfly

Paigaldada Java v 8 keskkond (iseenesest pole teenuse pakkumise keskkonnas kompileerimise vahendeid vaja, aga nt SignServer juurutamiseks on need tarvilikud)

# apt-get install openjdk-8-jdk ant

Lokaat

# locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
# localectl
  System Locale: LANG=en_US.UTF-8
      VC Keymap: n/a
     X11 Layout: n/a
      X11 Model: SKIP

Arvuti kellaaeg sh ajavöönd peavad olema õige.

Tarkvara paigaldamine

Kopeerida tarkvara aadressilt http://wildfly.org/downloads/, nt

Java EE7 Full & Web Distribution
# mkdir /opt/wildfly-home/tarkvara
# cd /opt/wildfly-home/tarkvara
# wget http://download.jboss.org/wildfly/10.0.0.Final/wildfly-10.0.0.Final.tar.gz

Pakkida arhiiv lahti /opt kataloogi ja moodustada nö versioonitundetu symlink

# cd /opt
# tar zxf /opt/wildfly-home/tarkvara/wildfly-10.0.0.Final.tar.gz
# ln -s /opt/wildfly-10.0.0.Final wildfly
# chown -R wildfly:wildfly wildfly-10.0.0.Final

Seadistamine ja käivitamine

WildFly käivitamiseks sobib öelda (soovitavalt screen sessioonis)

# screen
# su - wildfly
$ cd /opt/wildfly
$ bin/standalone.sh

Vaikimisi kuulab WildFly aadressidel

http://127.0.0.1:8080/ - teenuse liides
http://127.0.0.1:9990/ - haldusliides (küsitakse adduser.sh abil seadistatud ligipääsu)

Haldusliidesele üle võrgu ligipääsemiseks vajaliku kasutaja lisamiseks sobib öelda

# su - wildfly
$ cd /opt/wildfly
$ bin/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 be different from the username
 - 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)
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/wildfly-10.0.0.Final/standalone/configuration/mgmt-users.properties'
Added user 'admin' to file '/opt/wildfly-10.0.0.Final/domain/configuration/mgmt-users.properties'
Added user 'admin' with groups  to file '/opt/wildfly-10.0.0.Final/standalone/configuration/mgmt-groups.properties'
Added user 'admin' with groups  to file '/opt/wildfly-10.0.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.
(y/n) y

Saab kasutada ka argumente

$ bin/add-user.sh imre parool
Added user 'imre' to file '/opt/wildfly-10.0.0.Final/standalone/configuration/mgmt-users.properties'
Added user 'imre' to file '/opt/wildfly-10.0.0.Final/domain/configuration/mgmt-users.properties'

Võrguühenduste kuulamise muudatus tuleks teha tõenäoliselt hiljem või varem, pigem siis kui java rakendused on paigaldatud. Selleks, et ajutiselt kuulataks kõigil arvuti võrguliidestel sobib server käivitada (üldiselt on õigem muuta seadistusfaili sisu vastavaks)

$ bin/standalone.sh -b=0.0.0.0 -bmanagement=0.0.0.0

Sobivam on püsiva tulemuse jaoks muuta seadistusfaile. Parasjagu kehtiva seadistuse esitamiseks

[standalone@localhost:9990 /] cd /interface=public
[standalone@localhost:9990 interface=public] :read-resource
{
   "outcome" => "success",
   "result" => {
       "any" => undefined,
       "any-address" => undefined,
       "inet-address" => expression "${jboss.bind.address:127.0.0.1}",
       "link-local-address" => undefined,
       "loopback" => undefined,
       "loopback-address" => undefined,
       "multicast" => undefined,
       "name" => "public",
       "nic" => undefined,
       "nic-match" => undefined,
       "not" => undefined,
       "point-to-point" => undefined,
       "public-address" => undefined,
       "site-local-address" => undefined,
       "subnet-match" => undefined,
       "up" => undefined,
       "virtual" => undefined
   }
}

Selleks, et teenuseid teenindataks kõigil arvuti võrguliidestel/ip-aadressidel sobib öelda

# su - wildfly
$ cd /opt/wildfly
$ bin/jboss-cli.sh -c
[standalone@localhost:9990 /] /interface=public:write-attribute(name=inet-address,value=0.0.0.0)
{
   "outcome" => "success",
   "response-headers" => {
       "operation-requires-reload" => true,
       "process-state" => "reload-required"
   }
}

[standalone@localhost:9990 /] :reload
{
   "outcome" => "success",
   "result" => undefined
}

taustal toimub selline seadistusfaili muudatus

$ diff /tmp/standalone.xml standalone/configuration/standalone.xml
427c427
<             <inet-address value="${jboss.bind.address:127.0.0.1}"/>
---
>             <inet-address value="0.0.0.0"/>

Sarnane muudatus haldusliidese töötamise jaoks

[standalone@localhost:9990 /] cd /interface=management
[standalone@localhost:9990 /] :read-resource
[standalone@localhost:9990 /] :write-attribute(name=inet-address,value=0.0.0.0)
[standalone@localhost:9990 /] cd /
[standalone@localhost:9990 /] :reload

Tulemusena saab teenuseid ja haldusliidest kaustada üle võrgu

Käivitusskript

TODO

Andmebaasi kasutamine

Andmebaasi kasutamiseks on üldiselt vaja teha kaks tegevust

  • juurutada vastava baasi (MySQL, PostgreSQL, MariaDB jne) java draiver
  • kirjeldada data source

Andmebaasi kasutamise korraldamiseks on mitmeid võimalusi

  • kasutada Web GUI liidest - mugav, kui on teada, mis teha
  • redigeerida otse xml seadistusfaile - kohmakas
  • kasutada CLI käsurea liidest - hea viis täpselt korratava tegevusjuhise andmiseks

Käesolevas tekstiks kirjeldatakse mõnda erinevat andmbaasi ja keskendutakse CLI liidesele.

Tööpõhimõte

  • Non-XA - TODO
  • XA - TODO

PostgreSQL

PostgreSQL kasutamiseks tuleb leida Java ja PostgreSQL versioonile sobiv JDBC draiver aadressilt https://jdbc.postgresql.org/download.html ja kopeerida kuhugi failisüsteemi, nt /tmp kataloogi

Draiveri paigaldamine CLI abil

Draiveri paigaldamiseks sobib öelda

[standalone@localhost:9990 /] module add --name=org.postgresql --resources=/tmp/postgresql-9.4.1208.jar --dependencies=javax.api,javax.transaction.api

tulemusena tekib failisüsteemi

/opt/wildfly/modules/org/postgresql/main/postgresql-9.4.1208.jar
/opt/wildfly/modules/org/postgresql/main/module.xml

Seejärel öelda

[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=postgresql:add(driver-name="postgresql",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)

ja lõpuks registreerida data source

[standalone@localhost:9990 /] data-source add --name=SignServerDS --driver-name="postgresql" --connection-url="jdbc:postgresql://127.0.0.1/signserver" --jndi-name="java:/SignServerDS" --use-ccm=true --user-name="signserver" --password="signserver" --validate-on-match=true --background-validation=false --prepared-statements-cache-size=50 --share-prepared-statements=true --min-pool-size=5 --max-pool-size=150 --pool-prefill=true --transaction-isolation=TRANSACTION_READ_COMMITTED --check-valid-connection-sql="select 1"

kus

  • tundub, et name väärtuses on oluline jälgida tõstutundlikkust (signserverds vs SignServerDS)

Testimiseks

[standalone@localhost:9990 /] /subsystem=datasources/data-source=SignServerDS:test-connection-in-pool
{
    "outcome" => "success",
    "result" => [true]
}
Alternatiiv - draiveri paigaldamine deploy abil

Draiveri paigaldamiseks tehakse tavaline deploy, seejärel on draiver näha ka 'deployment-info' väljundis

[standalone@localhost:9990 /] deploy /var/tmp/postgresql-9.3-1103.jdbc3.jar
[standalone@localhost:9990 /] /subsystem=datasources:installed-drivers-list
{
   "outcome" => "success",
   "result" => [
       {
           "driver-name" => "postgresql-9.3-1103.jdbc3.jar",
           "deployment-name" => "postgresql-9.3-1103.jdbc3.jar",
           "driver-module-name" => undefined,
           "module-slot" => undefined,
           "driver-datasource-class-name" => undefined,
           "driver-xa-datasource-class-name" => undefined,
           "driver-class-name" => "org.postgresql.Driver",
           "driver-major-version" => 9,
           "driver-minor-version" => 3,
           "jdbc-compliant" => false
       },
...

Data-Source kirjeldamine

[standalone@localhost:9990 /] data-source add --jndi-name=java:/PgSqlDS --name=PgSQLPool --connection-url=jdbc:postgresql://localhost:3306/signserver \
  --driver-name=postgresql-9.3-1103.jdbc3.jar --user-name=signserver --password=signserver --max-pool-size=30

Samaväärne on seda teha ka WebGUI kaudu, kusjuures WebGUI sisaldab head baasiühenduse testimise võimalust

Wildfly-1.gif

WildFly käivitamisel öeldakse

..
01:29:58,607 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "postgresql-9.3-1103.jdbc3.jar" (runtime-name: "postgresql-9.3-1103.jdbc3.jar")
01:29:59,124 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0005: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.3)
01:29:59,157 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0018: Started Driver service with driver-name = postgresql-9.3-1103.jdbc3.jar
01:29:59,167 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0001: Bound data source [java:/PgSqlDS]
01:29:59,383 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0010: Deployed "postgresql-9.3-1103.jdbc3.jar" (runtime-name : "postgresql-9.3-1103.jdbc3.jar")
Misc
  • data source eemaldamine
[standalone@localhost:9990 /] data-source remove --name=SignServerDS
operation-requires-reload: true            
process-state:             reload-required 
[standalone@localhost:9990 /] :reload
  • draiveri xxx eemaldamine
[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=SignServerDS:remove
{"outcome" => "success"}
[standalone@localhost:9990 /] module remove --name=org.postgresql
Kasulikud lisamaterjalid

MySQL

MySQL draiver asub aadressil https://dev.mysql.com/downloads/connector/j/

TODO

MariaDB

MariaDB draiver asub aadressil https://mariadb.com/my_portal/download/java-client, draiveri juurutamiseks üks võimalus on kopeerida ta deployments kataloogi

$ cp mariadb-java-client-1.4.6.jar /opt/wildfly/standalone/deployments/mariadb-java-client.jar

ja tulemusena töötav WildFly deploib ta automaatselt ära. Seejärel tekitada data source

[standalone@localhost:9990 /] data-source add --name=ejbcads --driver-name="mariadb-java-client.jar" \
  --connection-url="jdbc:mysql://127.0.0.1:3306/ejbca" --jndi-name="java:/EjbcaDS" --use-ccm=true \ 
  --driver-class="org.mariadb.jdbc.Driver" --user-name="ejbca" --password="ejbca" --validate-on-match=true \
  --background-validation=false --prepared-statements-cache-size=50 --share-prepared-statements=true --min-pool-size=5 \
  --max-pool-size=150 --pool-prefill=true --transaction-isolation=TRANSACTION_READ_COMMITTED --check-valid-connection-sql="select 1;"

ning öelda reload rakendusserverile

[standalone@localhost:9990 /] :reload
{    "outcome" => "success",    "result" => undefined
}

https seadistamine

Esmalt tuleb tekitada https teenusele vastav võtmepaar, keystore

$ cd /opt/wildfly/standalone/configuration
$ keytool -genkeypair -keystore wildfly.keystore -storepass mypassword -keypass mypassword \
  -keyalg RSA -validity 180 -alias wildfly -dname "cn=wildfly.moraal.ee,o=Moraal,c=EE"

seejärel

[standalone@localhost:9990 /] /core-service=management/security-realm=imretestrealm:add()
[standalone@localhost:9990 /] /core-service=management/security-realm=imretestrealm/server-identity=ssl:add(keystore-path=wildfly.keystore, keystore-relative-to=jboss.server.config.dir, keystore-password=mypassword)
[standalone@localhost:9990 /] /subsystem=undertow/server=default-server/https-listener=https:add(socket-binding=https, security-realm=imretestrealm)
[standalone@localhost:9990 /] :reload

Tulemusena on teenuse liiklus aadressil https://192.168.10.46:8443/.

Märkused

  • restart
[standalone@localhost:9990 /] :shutdown(restart=true)
{"outcome" => "success"}
  • reload
[standalone@localhost:9990 /] :reload
{
    "outcome" => "success",
    "result" => undefined
}
  • atribuudi väärtuse muutmine
[standalone@localhost:9990 interface=public] cd /subsystem=deployment-scanner/scanner=default
[standalone@localhost:9990 scanner=default] :write-attribute(name=scan-interval,value=2500)
{"outcome" => "success"}
  • paigaldatud andmebaasi draiverite nimekiri
[standalone@localhost:9990 /] /subsystem=datasources:installed-drivers-list
  • kirjeldatud data sourceide nimekiri
[standalone@localhost:9990 /] /subsystem=datasources:read-resource
  • paigaldatud rakenduste nimekiri
[standalone@localhost:9990 /] deployment-info           
NAME                          RUNTIME-NAME                  PERSISTENT ENABLED STATUS 
postgresql-9.3-1103.jdbc3.jar postgresql-9.3-1103.jdbc3.jar true       true    OK     
signserver.ear                signserver.ear                false      true    OK     
wildfly-helloworld.war        wildfly-helloworld.war        true       true    OK
  • rakenduse undeploy
[standalone@localhost:9990 /] undeploy signserver.ear
  • baasi draiveri lisamine ilma deploimiseta
[standalone@localhost:9990 /] module add --name=org.postgresql --slot=main --resources=/tmp/postgresql-9.4.1208.jar --dependencies=javax.api,javax.transaction.api
[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
{"outcome" => "success"}

Rakenduse deploy Maven abil

$ export WILDFLY_HOME=/opt/wildfly
$ cd quickstart-10.x/helloworld
$ mvn clean install wildfly:deploy
$ mvn wildfly:undeploy

Wildfly uuendamine

Wildfly versiooni saab uuendada, nt 10.0.0 -> 10.1.0 kahel viisil

  • täielise v. 10.1.0 paigaldamine olemasoleva kõrval asuvasse kataloogi (ja ilmselt rakenduste uuesti deploy sinna keskkonda)
  • spetsiaalse v. 10.1.0 patch arhiivi kasutamine (mis peab sobima nö alusversiooniga)

Patch arhiive jagatakse wildfly.org veebikohast, nad esinevad .zip failina, mis sisaldab kahte faili

$ unzip -t wildfly-10.1.0.Final-update.zip 
Archive:  wildfly-10.1.0.Final-update.zip
    testing: README.txt               OK
    testing: wildfly-10.1.0.Final.patch   OK

README õpetab mitmel viisil uuendamist, nt 'Offline Installation'

  • arhiiv on lahti pakitud, nt /var/tmp kataloogi
  • liikuda wildfly kasutajana /opt/wildfly kataloogi
  • sulgeda WildFly protsessid ja veenduda, et nad ei tööta
  • käivitada cli utiliit:
$ ./bin/jboss-cli.sh
  • paigaldada paik
[disconnected /] patch apply /var/tmp/wildfly-10.1.0.Final.patch
{
    "outcome" : "success",
    "result" : {}
} 
  • väljuda utiliidist
[disconnected /] quit
  • käivitada WildFly server tavalisel viisil
$ ./bin/standalone.sh

Kasulikud lisamaterjalid