上一篇文章使用人工配置的方法简单的配置了webgateway container. 接下来来介绍如何在docker-compose里做自动化部署。
先总结我们要做的事情:
- 配置到IRIS的连接。定义连接的iris的IP地址或者DNS, 以及连接的用户名密码 以及其他的对默认值的修改。
- 配置apache2的配置文件,保证到IRIS的HTTP请求能发送给CSP Webgateway。
- 很多时候,用户会希望使用HTTPS访问IRIS,因此需要在apache2上支持TLS。
这些是最基本的功能。除此之外, 用户还可能会要求建立WebGateway到IRIS的TLS连接,或者在Apache2部署自己的网页等等。后面的文章会一一介绍。
配置CSP.ini
上一篇文章中,我通过Webgateway管理页面定义了Webgateway到IRIS的连接,其实是定义了webgateway的配置文件CSP.ini
。 无论WebServer是什么类型,IIS,Apache, Nginx, CSP.ini的都是一样的。在Linux中, CSP.ini位于/opt/webgateway/bin
目录。
InterSystems提供了一个工具叫 CSP merge。 简单的说,就是可以定义一个被合并的文件
, webgateway运行时会不停的扫描这个文件,发现有内容的修改,就把修改后的配置项合并到工作中的CSP.ini中去。 具体的内容您可以参见在线文档-CSP.ini merge feature。
CSP merge的merge文件不需要定义所有的配置项,理论上,只定义需要修改的部分就可以。但注意在一个配置部分(section)内部, 配置项之间是有关系的,单独定义其中的一项配置是不会生效的。
比如, 这是原始的CSP.ini中的LOCAL服务器的配置部分:
因此,merge文件里正确的LOCAL部分是:
[LOCAL]
Ip_Address=127.0.0.1
TCP_Port=1972
Minimum_Server_Connections=3
Maximum_Session_Connections=6
Connection_Security_Level=0 ; 0:password, 1:kerberos...
Username=CSPSystem
Password=]]]U1lT
SSLCC_Protocol_Min=16
SSLCC_Protocol_Max=32
SSLCC_Key_Type=2
SSLCC_Cipher_Suites=ALL:!aNULL:!eNULL:!EXP:!SSLv2
SSLCC_Cipher_Suites_1_3=TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256
如果您只希望修改Ip_Address, 因此在被合并的文件中定义
[LOCAL]
Ip_Address=192.168.1.2
TCP_Port=1972
而这样的定义会 造成加载失败。也就是说,CSP merge需要合并完整的Section。上面的例子中定义了这个服务器的地址,但没有定义连接它的账户和密码,这是不能接受的。
我习惯用比较完整的配置文件做合并,下面是一个例子。文件名可以任意,这里我命名为CSP-merge.ini
:
[APP_PATH_INDEX]
/=Enabled
/csp=Enabled
[APP_PATH:/]
Default_Server=LOCAL
Alternative_Server_0=1~~~~~~LOCAL
[APP_PATH:/csp]
Default_Server=LOCAL
Alternative_Server_0=1~~~~~~LOCAL
[SYSTEM]
IRISCONNECT_LIBRARY_PATH=/opt/webgateway/bin
System_Manager=*.*.*.*
SM_Timeout=28800
Server_Response_Timeout=60
No_Activity_Timeout=86400
Queued_Request_Timeout=60
Default_Server=LOCAL
RELOAD=1 ; reload csp gateway setting in one minute
[SYSTEM_INDEX]
LOCAL=Enabled
[LOCAL]
Ip_Address=iris-a
TCP_Port=1972
Minimum_Server_Connections=3
Maximum_Session_Connections=6
Connection_Security_Level=0 ; 0:password, 1:kerberos...
Username=CSPSystem
Password=]]]U1lT
SSLCC_Protocol_Min=16
SSLCC_Protocol_Max=32
SSLCC_Key_Type=2
SSLCC_Cipher_Suites=ALL:!aNULL:!eNULL:!EXP:!SSLv2
SSLCC_Cipher_Suites_1_3=TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256
Tip1: [SYSTEM]中配置RELOAD=1, 可以让webgateway setting每分钟检查一次csp-merge.ini, 如果有修改,会实时的执行合并。
Tip2: 想了解更多的CSP.ini的配置项的内容,请访问在线文档- Define a Server Access Profile for Your InterSystems IRIS Instance。
Tip3: 在生产系统中,定义SYSTEM部分的:
System_Manager=*.*.*.*
是不安全的。
自动部署CSP合并文件
简单的说明: CSP-merge.ini文件位于host中的./webgateway
文件夹,通过volumes
映射到container的/external
文件夹。 通过定义环境变量ISC_CSP_INI_FILE
,docker启动时会执行CSP文件的合并。
webgateway-apache:
image: containers.intersystems.com/intersystems/webgateway-arm64:2024.1
container_name: wg-apache
hostname: wg-apache
ports:
- "8080:80"
volumes:
- ./webgateway:/external
environment:
- TZ=CST-8
- ISC_CSP_INI_FILE=/external/CSP-merge.ini
后面介绍如何配置apache2访问IRIS服务地址。
配置Apache2
配置apache2可以参考apache2的主页面,配置文件的结构如下:
apache2的主配置文件/etc/apache2/apache2.conf
包含(includes)了其他自子目录下的被enabled的配置文件,结构如下图:
root@wg-a:/etc/apache2# cat apache2.conf
...
# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
# /etc/apache2/
# |-- apache2.conf
# | `-- ports.conf
# |-- mods-enabled
# | |-- *.load
# | `-- *.conf
# |-- conf-enabled
# | `-- *.conf
# `-- sites-enabled
# `-- *.conf
CSP.conf是怎么工作的
InterSystems Webgateway是apache2的一个工作的module. 它的配置文件是/etc/apache2/mods-available/CSP.conf
。在webgateway container启动时,apache2会执行这个module的生效(enable), 这时会在/etc/apache2/mods-enabled
目录中创建一个链接到原始文件。
默认的CSP.conf
的内容如下:
root@wg-a:/etc/apache2# cat /etc/apache2/mods-available/CSP.conf
CSPModulePath "${ISC_PACKAGE_INSTALLDIR}/bin/"
CSPConfigPath "${ISC_PACKAGE_INSTALLDIR}/bin/"
<Location "/csp/bin/Systems/">
SetHandler csp-handler-sa
</Location>
<Location "/csp/bin/RunTime/">
SetHandler csp-handler-sa
</Location>
<Directory "${ISC_PACKAGE_INSTALLDIR}/bin/">
AllowOverride None
Options None
Require all granted
<FilesMatch "\.(log|ini|pid|exe)$">
Require all denied
</FilesMatch>
</Directory>
root@wg-a:/etc/apache2#
修改CSP.conf
以上的CSP.conf中只有使用CSP module的内容,而并没有访问IRIS的URL的部分。 , 需要一个个的添加要发送到webgateway模块的URL。必须的有这几个:/csp
, /api
,/isc
, 其他还包括您自己定义的URL, 也需要创建对应的<Location>
。
以下是要添加的内容:
# 添加要发送给IRIS的URL
<Location "/csp">CSP On</Location>
<Location "/api">CSP On</Location>
<Location "/isc">CSP On</Location>
<Location "/customerURL">CSP On</Location>
Tip1: 如果您确认此container只用于连接IRIS, 您可以定义
<Location />
将所有的请求发送给webgateway模块。但注意访问http://localhost:8080时会返回错误404,apache2原本会把请求发到/var/www/html/index.html
,修改后会把这个请求发给IRIS。
自动部署CSP.conf的修改
配置container是新的CSP.conf通过SC_CSP_CONF_FILE
加入,这个不是合并, 是整个覆盖替换原始的配置文件。以下是compose文件的示意,同样,CSP-apache.conf
文件位于host的./webgateway
文件夹,通过volumes
映射到container的/external
文件夹。
webgateway-apache:
image: containers.intersystems.com/intersystems/webgateway-arm64:2024.1
container_name: wg-apache
hostname: wg-apache
ports:
- "8080:80"
volumes:
- ./webgateway:/external
environment:
- TZ=CST-8
- ISC_CSP_INI_FILE=/external/CSP-merge.ini
- ISC_CSP_CONF_FILE=/external/CSP-apache.conf
要修改CSP.conf, 如果要在container外面修改,需要修改ISC_CONF-FILE的内容, 然后重启container. /dur里面的CSP.conf不能改, 改了保存后会自动改回来。
配置Apache2的TLS
方法1. 用命令开启
配置HTTPS访问apache2最简单的方式打开apache2内置的ssl
模块,并使default-ssl.conf
生效。如下面的脚本文件中的操作:
root@wg-a:/etc/apache2# a2enmod ssl
root@wg-a:/etc/apache2# ls -l mods-enabled/ssl*
lrwxrwxrwx 1 root root 26 Oct 9 09:00 mods-enabled/ssl.conf -> ../mods-available/ssl.conf
lrwxrwxrwx 1 root root 26 Oct 9 09:00 mods-enabled/ssl.load -> ../mods-available/ssl.load
root@wg-a:/etc/apache2# a2ensite default-ssl
Enabling site default-ssl.
To activate the new configuration, you need to run:
service apache2 reload
root@wg-a:/etc/apache2# service apache2 reload
* Reloading Apache httpd web server apache2 *
root@wg-a:/etc/apache2#
方法2. 设置自己的配置
因为已经Copy了一个CSP.conf进去,其实可以在这个文件里配置SSL的部分, 好处是不用单独写一个文件, 坏处是从维护的角度,把CSP module的配置和SSL的配置写在一个文件不是很合理。
# 加入下部分到CSP.conf, 其中使用了自己的TLS配置,而不是openssl的证书和key.
LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "/external/cert/sslwebcert.crt"
SSLCertificateKeyFile "/external/cert/sslwebkey.key"
</VirtualHost>
或者使用ssl mod的 conf
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>