wso2~部署~apim4.2的docker-compose方案,硬件要求内存:建议4
分享于 点击 123 次 点评:159
wso2~部署~apim4.2的docker-compose方案,硬件要求内存:建议4
以下是使用Docker部署WSO2 API Manager(WSO2 APIM)的详细步骤,分为快速测试部署和生产级部署两种场景:
一、前提条件
- 安装Docker环境
- 确保已安装Docker Engine和Docker Compose。
- 硬件要求
- 内存:建议4GB以上(默认镜像包含Java进程,内存需求较高)。
- 磁盘空间:至少2GB可用空间。
二、快速启动(单容器测试)
适用于快速体验,数据保存在容器内(重启后丢失):
# 拉取官方镜像(以最新版本为例)
docker pull wso2/wso2am:4.2.0
# 运行容器(映射管理端口和网关端口)
* 9443:9443 # 管理控制台(Publisher/Dev Portal)
* 8243:8243 # API Gateway HTTPS端口
* 8280:8280 # API Gateway HTTP端口
docker run -d \
--name wso2-apim \
-p 9443:9443 \
-p 8243:8243 \
-p 8280:8280 \
harbor.pkulaw.cn:8443/library/wso2am/wso2am:4.2.0-alpine
docker run -it -d \
--name wso2-apim \
-p 9443:9443 \
-p 8243:8243 \
-p 8280:8280 \
--user root \
--privileged=true \
-v /root/carbon/carbon.xml:/home/wso2carbon/wso2am-4.2.0/repository/conf/carbon.xml \
harbor.pkulaw.cn:8443/library/wso2am/wso2am:4.2.0-alpine
# 访问管理界面
默认账号:admin/admin
地址:https://localhost:9443/devportal
三、生产级部署(Docker Compose多容器)
推荐使用Docker Compose部署,支持持久化数据和外部数据库(以MySQL为例):
-
创建
docker-compose.yml
文件version: '3.8' services: mysql-db: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: wso2am_db volumes: - mysql-data:/var/lib/mysql networks: - apim-network wso2-apim: image: wso2/wso2am:4.2.0 depends_on: - mysql-db ports: - "9443:9443" - "8243:8243" - "8280:8280" volumes: - apim-configs:/home/wso2carbon/wso2am-4.2.0/repository/conf - apim-logs:/home/wso2carbon/wso2am-4.2.0/repository/logs environment: # 配置MySQL连接(覆盖默认H2) - DB_HOST=mysql-db - DB_PORT=3306 - DB_USER=root - DB_PASSWORD=root networks: - apim-network volumes: mysql-data: apim-configs: apim-logs: networks: apim-network: driver: bridge
-
初始化MySQL数据库
下载官方SQL脚本并执行:# 下载APIM数据库脚本 wget https://raw.githubusercontent.com/wso2/docker-apim/master/docker-compose/apim-with-analytics/mysql/scripts/apimgt.sql # 进入MySQL容器执行初始化 docker exec -i mysql-db mysql -uroot -proot wso2am_db < apimgt.sql
-
启动服务
docker-compose up -d
四、关键配置说明
- 持久化数据
- 配置文件:挂载
/repository/conf
目录,避免容器重启后配置丢失。 - 日志文件:挂载
/repository/logs
目录,便于排查问题。
- 配置文件:挂载
- 更换数据库
修改repository/conf/deployment.toml
,配置MySQL连接:[database.apim_db] type = "mysql" url = "jdbc:mysql://mysql-db:3306/wso2am_db" username = "root" password = "root"
- 集群部署
若需横向扩展API Gateway节点,可复制wso2-apim
服务并配置共享数据库和注册表(参考官方集群指南)。
五、常见问题
- 启动超时
首次启动较慢(需等待Java初始化),查看日志:docker logs -f wso2-apim
- 端口冲突
确保本地9443
、8243
、8280
端口未被占用。 - 数据库连接失败
检查MySQL容器是否正常启动,以及deployment.toml
中的连接参数。
六、其他资源
- 官方Docker文档:WSO2 APIM Docker指南
- 自定义镜像构建:支持通过Dockerfile集成第三方库或修改主题。
k8s-helm部署
helm repo add wso2 https://helm.wso2.com && helm repo update
helm install wso2 wso2/am-single-node --version 4.2.0-alpine --namespace default
#查看helm仓库里有哪些景象
[root@cicd001 ~]# helm repo list
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/test-config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/test-config
NAME URL
apisix https://charts.apiseven.com
wso2 https://helm.wso2.com
graviteeio https://helm.gravitee.io
root@cicd001 ~]# helm search repo wso2
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/test-config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/test-config
NAME CHART VERSION APP VERSION DESCRIPTION
wso2/apim-apk-agent 1.3.0 1.3.0 A Helm chart for deploying apim-apk-agent
wso2/apk-helm 1.3.0 1.3.0 A Helm chart for APK components
wso2/kubernetes-pipeline 1.2.0 1.2.0 A Helm chart to deploy a CI/CD Pipeline in a Ku...
wso2/mysql 1.6.9 5.7.30 Fast, reliable, scalable, and easy to use open-...
wso2/nfs-server-provisioner 1.1.0 2.3.0 nfs-server-provisioner is an out-of-tree dynami...
wso2/spinnaker 2.2.6 1.16.2 Open source, multi-cloud continuous delivery pl...
# 由于docker景象国内云无法下载,需要我们修改景象地址,所以需要手动编辑values.yaml文件
helm pull wso2/am-single-node:4.2.0-alpine #可能没有这个景象,那么需要下载原代码来修改values.yaml
tar -xvf apim-4.7.2.tgz
helm upgrade wso2 ./am-single -f ./am-single/values.yaml -i -n default
/publisher出错,需要修改配置
Sign in to the Management Console (https://<hostname>:9443/carbon).
Navigate to service providers list.
SP list
Click on the Edit button of API Publisher service provider
SP list
Navigate to Inbound Authentication Configuration > OAuth/OpenID Connect Configuration and click on OAuth application edit button.
OAuth app edit
See the Callback Url regex value configured under Application Settings. You will observe that the callback URL value is having a different hostname(localhost or previous hostname which was configured before the hostname change).
regexp=(https://localhost:9443/publisher/services/auth/callback/login|https://localhost:9443/publisher/services/auth/callback/logout)
Then replace the callback URL hostname with the current hostname of the server. For example, if the current hostname of the server is apim.wso2.com, the callback URL regex has to be changes as follows.
regexp=(https://apim.wso2.com:9443/publisher/services/auth/callback/login|https://apim.wso2.com:9443/publisher/services/auth/callback/logout)
helm repo add wso2 https://helm.wso2.com && helm repo update
helm install wso2 wso2/am-single-node --version 4.2.0-alpine --namespace default
#查看helm仓库里有哪些景象
[root@cicd001 ~]# helm repo list
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/test-config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/test-config
NAME URL
apisix https://charts.apiseven.com
wso2 https://helm.wso2.com
graviteeio https://helm.gravitee.io
root@cicd001 ~]# helm search repo wso2
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/test-config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/test-config
NAME CHART VERSION APP VERSION DESCRIPTION
wso2/apim-apk-agent 1.3.0 1.3.0 A Helm chart for deploying apim-apk-agent
wso2/apk-helm 1.3.0 1.3.0 A Helm chart for APK components
wso2/kubernetes-pipeline 1.2.0 1.2.0 A Helm chart to deploy a CI/CD Pipeline in a Ku...
wso2/mysql 1.6.9 5.7.30 Fast, reliable, scalable, and easy to use open-...
wso2/nfs-server-provisioner 1.1.0 2.3.0 nfs-server-provisioner is an out-of-tree dynami...
wso2/spinnaker 2.2.6 1.16.2 Open source, multi-cloud continuous delivery pl...
# 由于docker景象国内云无法下载,需要我们修改景象地址,所以需要手动编辑values.yaml文件
helm pull wso2/am-single-node:4.2.0-alpine #可能没有这个景象,那么需要下载原代码来修改values.yaml
tar -xvf apim-4.7.2.tgz
helm upgrade wso2 ./am-single -f ./am-single/values.yaml -i -n default
Sign in to the Management Console (https://<hostname>:9443/carbon).
Navigate to service providers list.
SP list
Click on the Edit button of API Publisher service provider
SP list
Navigate to Inbound Authentication Configuration > OAuth/OpenID Connect Configuration and click on OAuth application edit button.
OAuth app edit
See the Callback Url regex value configured under Application Settings. You will observe that the callback URL value is having a different hostname(localhost or previous hostname which was configured before the hostname change).
regexp=(https://localhost:9443/publisher/services/auth/callback/login|https://localhost:9443/publisher/services/auth/callback/logout)
Then replace the callback URL hostname with the current hostname of the server. For example, if the current hostname of the server is apim.wso2.com, the callback URL regex has to be changes as follows.
regexp=(https://apim.wso2.com:9443/publisher/services/auth/callback/login|https://apim.wso2.com:9443/publisher/services/auth/callback/logout)
作者:仓储大叔,张占岭,
荣誉:微软MVP
QQ:853066980
支付宝扫一扫,为大叔打赏!
用户点评