如何在一分钟内建立 IRIS Sharding 集群
在本文中,我将向你展示如何在笔记本电脑上快速建立一个分片 IRIS 节点集群。本文的目的既不是详细讨论分片,也不是定义生产就绪架构的部署,而是展示如何在自己的电脑上快速建立一个配置为分片节点的 IRIS 实例集群,并利用它来玩转和测试这一功能。如果你想了解更多有关 IRIS 分片的信息,请点击此处查看相关文档。
首先,我要说明的是,IRIS分片允许我们做两件事:
- 定义、加载和查询分片表(shard tables),数据将在集群节点之间透明分发
- 定义联合表(federated tables),提供属于不同表的数据的全局和组合视图,这些数据将物理存储在不同的分布式节点中
因此,正如我所说,我们可以在其他文章中讨论分片表或联合表,现在只需关注前一步,即设置分片节点集群。
在我们的示例中,我们将使用Docker Desktop(适用于 Windows 或 MacOS),并利用 IRIS 的一项功能:CPF Merge 允许我们使用纯文本文件,在其中包含我们想要应用的 IRIS 部分/配置属性,以更新 IRIS 实例的默认配置。基本上,该文件会覆盖 iris.cpf 文件中定义实例默认配置的部分内容。
当我们添加环境变量:ISC_CPF_MERGE_FILE,并将其设置为包含我们要更改的 cpf 文件部分的有效路径时,就会自动 "触发 "这种合并。当 IRIS 启动时,它会检查是否存在要应用的合并文件(基本上,如果存在该环境变量并指向一个有效文件)。如果有,则进行合并并启动。
我就不啰嗦了,下面是 docker-compose.yml 这个文件,它将发挥神奇的作用:
docker-compose.yml
services:
# iris container
irisnode1:
init: true
hostname: irishost1
image: shardnode:latest
container_name: irisnode1
build:
context: ./cluster
dockerfile: Dockerfile
ports:
- "9991:1972"
environment:
- ISC_DATA_DIRECTORY=/durable/irishost1
- ISC_CPF_MERGE_FILE=/iris-shared/merge_first_data-node.cpf
command:
--check-caps false --ISCAgent false --key /iris-shared/iris.key -a /iris-shared/configure_first_data-node.sh
volumes:
- ./cluster/iris-instance:/iris-shared:delegated
- ./DDBBs:/durable:delegated
irisnode2:
init: true
hostname: irishost2
image: shardnode:latest
container_name: irisnode2
build:
context: ./cluster
dockerfile: Dockerfile
ports:
- "9992:1972"
environment:
- ISC_DATA_DIRECTORY=/durable/irishost2
- ISC_CPF_MERGE_FILE=/iris-shared/merge_data-node.cpf
command:
--check-caps false --ISCAgent false --key /iris-shared/iris.key -a /iris-shared/configure_data-node.sh
volumes:
- ./cluster/iris-instance:/iris-shared
- ./DDBBs:/durable
depends_on:
irisnode1:
condition: service_healthy
# web gateway container
webgateway:
image: containers.intersystems.com/intersystems/webgateway:latest-em
init: true
container_name: webgateway
hostname: webgateway
ports:
- 7772:80
- 7773:443
environment:
- ISC_CSP_CONF_FILE=/webgateway-shared/CSP.conf
- ISC_CSP_INI_FILE=/webgateway-shared/CSP.ini
volumes:
- ./webgateway/CSP.conf:/webgateway-shared/CSP.conf
- ./webgateway/CSP.ini:/webgateway-shared/CSP.ini这里还有一个 CSP.conf 和 CSP.ini 文件的例子:
CSP.conf
# CSP config file
CSPModulePath "${ISC_PACKAGE_INSTALLDIR}/bin/"
CSPConfigPath "${ISC_PACKAGE_INSTALLDIR}/bin/"
# Serve everything via Web Gateway. Conveniently,
# we needn't worry about sharing this container with non-IRIS applications.
<Location />
CSP On
</Location>
<Directory />
Options MultiViews FollowSymLinks
AllowOverride None
Require all granted
<FilesMatch "\.(log|ini|pid|exe|so)$">
Require all denied
</FilesMatch>
</Directory>
# Redirect Help links
Redirect /csp/docbook/ http://docs.intersystems.com/irislatest/csp/docbook/CSP.ini
[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=IRISHOST1
[SYSTEM_INDEX]
IRISHOST1=Enabled
IRISHOST2=Enabled
[IRISHOST1]
Ip_Address=irishost1
TCP_Port=1972
Minimum_Server_Connections=3
Maximum_Session_Connections=6
Username=CSPSystem
Password=]]]U1lT
Connection_Security_Level=0
[IRISHOST2]
Ip_Address=irishost2
TCP_Port=1972
Minimum_Server_Connections=3
Maximum_Session_Connections=6
Username=CSPSystem
Password=]]]U1lT
Connection_Security_Level=0
[APP_PATH_INDEX]
/=Enabled
/csp=Enabled
/irishost1=Enabled
/irishost2=Enabled
/test=Enabled
[APP_PATH:/]
Default_Server=IRISHOST1
Alternative_Server_0=1~~~~~~IRISHOST1
[APP_PATH:/csp]
Default_Server=IRISHOST1
Alternative_Server_0=1~~~~~~IRISHOST1
[APP_PATH:/irishost1]
Default_Server=IRISHOST1
Alternative_Server_0=1~~~~~~IRISHOST1
[APP_PATH:/irishost2]
Default_Server=IRISHOST2
Alternative_Server_0=1~~~~~~IRISHOST2
[APP_PATH:/test]
Default_Server=IRISHOST2
Alternative_Server_0=1~~~~~~IRISHOST2在此示例中,我们实例化了 3 个服务:
- irisnode1- 集群的第一个节点,它有一个特殊的角色,因此我们将其命名为
node1 - irisnode2- 数据节点,集群的附加节点,其角色为
data(我们可以拥有任意数量的节点) - webgateway- 预先配置好的网络服务器,用于访问 IRIS 实例(Apache + Webgateway)
为了构建 shardnode:latest,我使用了下面的dockerfile :
Dockerfile
FROM containers.intersystems.com/intersystems/irishealth:2024.3
#FROM containers.intersystems.com/intersystems/iris-community:latest-em
#FROM containers.intersystems.com/intersystems/irishealth-arm64:2024.3
USER root
WORKDIR /opt/irisapp
RUN chown -R irisowner:irisowner /opt/irisapp
USER irisowner
WORKDIR /opt/irisapp
COPY --chown=irisowner:irisowner src src
COPY --chown=irisowner:irisowner iris.script iris.script
RUN iris start IRIS \
&& iris session IRIS < iris.script \
&& iris stop IRIS quietly在这个 dockerfile 中,我们调用了 iris.script,它可以让我们在构建的 IRIS 镜像中运行 ObjectScript 代码,设置、导入和编译代码等:
iris.script
// Unexpire passwords to simplify dev mode. Comment these two lines for Production use
zn "%SYS"
Do ##class(Security.Users).UnExpireUserPasswords("*")
zn "USER"
// Load the IRIS Classes
do $System.OBJ.LoadDir("/opt/irisapp/src","ck",,1)
// Register CSP applications can be done in the merge.cpf
halt用于合并 nodo1 和其他 IRIS 集群 data 节点的 CPF 文件有
merge_first_data-node.cpf
merge_data-node.cpf
# Nodo de dato adicional
# 2 GB 8k / 204 MB gmpheap / 64 nodos max
[config]
globals=0,0,2048,0,0,0
gmheap=204800
MaxServerConn=64
MaxServers=64
# Define un nodo de datos y lo añade al cluster. Crea un endpoint REST de prueba(opcional)
[Actions]
ConfigShardedCluster:ClusterURL=IRIS://irishost1:1972/IRISCLUSTER,Role=data
# CreateApplication:Name=/rest/testapp,MatchRoles=:%ALL,NameSpace=USER,DispatchClass=Test.RESTserver,AutheEnabled=64我们可以将更多
data类型的节点作为集群的一部分,只需添加与irisnode2相同定义的附加服务即可(当然要更改名称)。
还有一点,为了使网络服务器中的路由定义正常工作,从而能够访问每个实例的系统管理门户,我们必须更改每个实例中的参数CSPConfigName ,并通过文件中的脚本来实现:configure_first_data-node.sh y configure_data-node.sh;在本例中,这两个文件是相同的,但我将它们分开,因为在某些情况下,我们可能希望在启动时对每个 IRIS 实例执行不同的操作,这取决于它是 nodo1 类型的集群节点,还是 data 类型的集群节点。
configure_data-node.sh
基本上就是这样。
您可以使用
%SYSTEM.Cluster类中的可用 API 来定义节点,但事实上,利用CPF 合并功能引入操作的可能性大大简化了任务。我建议您阅读此处,尤其是[操作 Actions]部分。
要构建镜像并部署集群,我们可以构建镜像 sharnode:latest,然后从 VS 代码中启动我们的 docker-compose。或者,我们也可以从文件所在文件夹的命令行中执行:docker-compose.yml,执行以下命令:
docker compose build
docker compose up由于标记为 node1 的实例必须在集群中其他任何 data 节点启动之前启动,因此第一次启动需要一点时间。但一切都应该在 1 分钟或更短时间内准备就绪并开始工作。
如果一切顺利,就可以通过下面的 URL 访问每个实例的 SMP:
SMP 群集节点数据:http://localhost:7772/irishost2/csp/sys/UtilHome.csp
访问 WebGateway:http://localhost:7772/csp/bin/Systems/Module.cxw
然后,完成!从这里开始,有关 DDBB 存储和表大小的限制将由您的硬件决定。您需要启用分片功能的 IRIS 集群来定义分片和/或联合表。
希望对你有用!