티스토리 뷰

거의 1년만의 포스팅입니다.

지난 시간동안 수많은(?) 오픈시프트 PoC를 진행하면서 다양한 시행착오도 겪고

짧은 시간동안 자잘하게 또는 크게 변화가 생기면서 그런거.. 따라가기 바빴습니다.


이번 포스팅은 xPaaS JBoss 에서 외부 DB를 연계하는 방법에 대해 포스팅 합니다.


기본적으로 레드햇이 제공하는 JBoss EAP 이미지는 PostgreSQL과 MySQL에 대한 외부 DB 연계를 지원합니다.

여기에 Oracle DB를 붙일 수 있도록 약간의 이미지 커스터마이징이 필요합니다.


1. 이미지 출처


출처 : https://registry.access.redhat.com




docker pull 을 통해 받을 이미지의 tag 정보를 확인합니다. 


오픈시프트 용 JBoss EAP 는 현재 1.7 까지 릴리즈 된 상태입니다.


JBoss EAP 7.0


$ docker pull registry.access.redhat.com/jboss-eap-7/eap70-openshift:1.7


JBoss EAP 6.4


$ docker pull registry.access.redhat.com/jboss-eap-6/eap64-openshift:1.7




로컬 PC에서 내려받은 이미지를 확인합니다.






2. 외부 PostgreSQL/MySQL 연계 방법


출처 : https://access.redhat.com/documentation/en-us/red_hat_jboss_data_grid/6.5/html-single/data_grid_for_openshift/index#jdg-datasource-environment-variables-list


가장 중요한 설정은 DB_SERVICE_PREFIX_MAPPING이라는 변수이며, 이 변수가 JBoss에서 생성할 데이터소스의 기본 정보를 나타냅니다.


The most important variable is the DB_SERVICE_PREFIX_MAPPING which defines JNDI mappings for datasources. It must be set to a comma-separated list of <name><database_type>=<PREFIX> triplet, where *name is used as the pool-name in the datasource, database_typedetermines which database driver to use, and PREFIX is the prefix used in the names of environment variables, which are used to configure the datasource.


For each <name>-database_type>=PREFIX triplet in the DB_SERVICE_PREFIX_MAPPING environment variable, a separate datasource will be created by the launch script, which is executed when running the image.


NOTE

The first part (before the equal sign) of the DB_SERVICE_PREFIX_MAPPING should be lowercase.



설명하기 힘드니까 예를 들어 보겠습니다.



ex) testdb1-mysql=TEST_DB1,testdb2-postgresql=TEST_DB2



여러개의 데이터소스를 생성하려면 콤마(,)로 구분합니다. 각각은 아래와 같은 규칙을 보여줍니다.


<name>-<database_type>=<PREFIX>



위 예제는 두 개의 데이터소스를 생성하며, 첫번째는 MySQL을 연계하는 testdb1 이라는 데이터소스, 두번째는 PostgreSQL을 연계하는 testdb2라는 데이터소스입니다.

여기서 사용되는 <name>, <database_type>, <PREFIX> 아래 환경변수에서 조합되어 사용됩니다.



참고로 <database_type>은 mysql, postgresql 둘 중 하나만 사용 가능합니다. 나중에 Oracle DB 를 연계할 수 있도록 커스터마이징을 진행할 예정입니다.



해당 환경변수는 JBoss Data Grid 매뉴얼에만 있으나 그냥 JBoss EAP64, EAP70에도 적용이 됩니다.



Variable NameDescriptionExample Value

<NAME>_<DATABASE_TYPE>_SERVICE_HOST

Defines the database server’s hostname or IP to be used in the datasource’s connection_urlproperty.

Example: 192.168.1.3

<NAME>_<DATABASE_TYPE>_SERVICE_PORT

Defines the database server’s port for the datasource.

Example: 5432

<PREFIX>_BACKGROUND_VALIDATION

When set to truedatabase connections are validated periodically in a background thread prior to use. Defaults to false (<validate-on-match> method is enabled by default instead).

Example: true

<PREFIX>_BACKGROUND_VALIDATION_MILLIS

Specifies frequency of the validation (in miliseconds), when the <background-validation> database connection validation mechanism is enabled (<PREFIX>_BACKGROUND_VALIDATIONvariable is set to true). Defaults to 10000.

Example: 20000

<PREFIX>_CONNECTION_CHECKER

Specifies a connection checker class that is used to validate connections for the particular database in use.

Example: org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker

<PREFIX>_DATABASE

Defines the database name for the datasource.

Example: myDatabase

<PREFIX>_DRIVER

Defines Java database driver for the datasource.

Example: postgresql

<PREFIX>_EXCEPTION_SORTER

Specifies the exception sorter class that is used to properly detect and clean up after fatal database connection exceptions.

Example: org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter

<PREFIX>_JNDI

Defines the JNDI name for the datasource. Defaults to java:jboss/datasources/<name>_<database_type>, where nameand database_typeare taken from the triplet definition. This setting is useful if you want to override the default generated JNDI name.

Example: java:jboss/datasources/test-postgresql

<PREFIX>_JTA

Defines Java Transaction API (JTA) option for the non-XA datasource (XA datasource are already JTA capable by default). Defaults to true.

Example: false

<PREFIX>_MAX_POOL_SIZE

Defines the maximum pool size option for the datasource.

Example: 20

<PREFIX>_MIN_POOL_SIZE

Defines the minimum pool size option for the datasource.

Example: 1

<PREFIX>_NONXA

Defines the datasource as a non-XA datasource. Defaults to false.

Example: true

<PREFIX>_PASSWORD

Defines the password for the datasource.

Example: password

<PREFIX>_TX_ISOLATION

Defines the java.sql.Connection transaction isolation level for the database.

Example: TRANSACTION_READ_UNCOMMITTED

<PREFIX>_URL

Defines connection URL for the datasource.

Example: jdbc:postgresql://localhost:5432/postgresdb

<PREFIX>_USERNAME

Defines the username for the datasource.

Example: admin



3. Oracle DB 연계


Oracle DB를 연계하기 위해서 가장 기본적으로 필요한 작업은  Oracle JDBC 드라이버를 이미지에 추가하는 것입니다. JDBC드라이버는 과거 3.x 매뉴얼에는 git repository에 modules 디렉토리의 파일들이 S2I 빌드시 EAP_HOME/module로 복사된다고 되어 있는데, 현재 버전에서는 이게 안되는 것 같습니다. 실제 /usr/local/s2i/assemble 스크립트를 보면 $CUSTOM_INSTALL_DIRECTORIES라는 환경변수가 있고 이 값에 따라 module같은 추가 설치 라이브러리가 빌드 타임에 적용되는 것으로 보이는데 실제로 S2I 빌드를 해보면 권한 등의 문제로 정상 동작하지 않습니다.


따라서 그냥 JDBC 드라이버를 커스터마이징 하기로 합니다.


원본 이미지에서 수정해야 할 정보는 아래와 같습니다.


/opt/eap/standalone/configuration/standalone-openshift.xml 수정

/opt/eap/modules/system/layers/openshift/com/oracle/main 디렉토리 추가 후 jdbc.jar 파일 및 module.xml 추가

/opt/eap/bin/launch/tx-datasource.sh 수정

/opt/eap/bin/launch/datasource-common.sh 수정



Dockerfile


FROM registry.access.redhat.com/jboss-eap-7/eap70-openshift:1.7


MAINTAINER Yun In Su <ora01000@time-gate.com>


RUN mkdir -p /opt/eap/modules/system/layers/openshift/com/oracle/main

COPY module.xml /opt/eap/modules/system/layers/openshift/com/oracle/main

COPY ojdbc7.jar /opt/eap/modules/system/layers/openshift/com/oracle/main

COPY ./configuration/standalone-openshift.xml /opt/eap/standalone/configuration

#COPY openshift-launch.sh /opt/eap/bin

COPY tx-datasource.sh /opt/eap/bin/launch

COPY datasource-common.sh /opt/eap/bin/launch


매우 간단합니다. 로컬에서 standalone-openshift.xml, module.xml 등을 미리 만들어 놓고 COPY하는 구조입니다.


그리고 앞서 설명한 DB_SERVICE_PREFIX_MAPPING에서 <database_type> 값이 oracle일 경우 이를 처리하기 위해 tx-datasource.sh와 datasource-common.sh 를 수정해야 합니다.


수정하는 내용은,


...



gitlab에 접속하여 확인하시기 바랍니다.


빌드 된 이미지는 docker.io 에 역시 push 되어 있습니다.


JBoss EAP64-oracle


git : https://gitlab.com/ora01000/eap64-17-ojdbc.git

docker : docker pull ora01000/eap64-openshift:1.7-oracle


JBoss EAP70-oracle


git : https://gitlab.com/ora01000/eap70-17-ojdbc.git

docker : docker pull ora01000/eap70-openshift:1.7-oracle



4. Oracle DB 연계 샘플


이미지를 참고여 Deployment Configuration에 환경변수를 추가하면 됩니다.





결과 확인


  JDBC Driver 등록




  데이터소스 생성




공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함