关于iam-service数据库表数据初始化问题

根据官方文档http://choerodon.io/zh/docs/development-guide/backend/intergration/init/初始化数据库的时候很多表的初始化数据都是没有的,这些表的数据怎么初始化呢?特别是iam_permission这个表,如果这个表没数据都没权限的吧?希望知道的大佬们解答下我的问题

你好,并不是所有的表都需要初始化数据的

那iam_permission表的会有吗?

iam_permission这张表的数据,是当服务启动时,manager-service接收到启动事件,然后向对应服务拉取权限数据,并发送saga到asgard-service。iam-service会消费这个saga事务,完成permission数据的初始化。
所以你需要确认正确启动了 注册中心、iam-service、manager-service、asgard-service,如果还没有数据 ,可以重启manager-service,触发权限的重新初始化。

我按照开发手册使用dockercompose文件启动项目,也加上了asgard的服务一起启动,为什么没有数据呢?是我操作不对吗?详细配置如下:
version: “2”
services:

mysql:
container_name: mysql
hostname: mysql
image: registry.cn-hangzhou.aliyuncs.com/choerodon-tools/mysql:5.7.17
ports:
- “3306:3306”
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- ./mysql/mysql_data:/var/lib/mysql
- ./mysql/mysql_db.cnf:/etc/mysql/conf.d/mysql_db.cnf
- ./mysql/init_user.sql:/docker-entrypoint-initdb.d/init_user.sql
expose:
- “3306”
networks:
- “c7nNetwork”
redis:
container_name: redis
hostname: redis
image: redis:4.0.11
ports:
- “6379:6379”
expose:
- “6379”
networks:
- “c7nNetwork”
eureka-server:
container_name: eureka-server
hostname: eureka-server
image: registry.choerodon.com.cn/choerodon-framework/eureka-server:0.9.0
ports:
- “8000:8000”
environment:
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8000/eureka/
- EUREKA_CLIENT_REGISTER_WITH_EUREKA=false
- EUREKA_CLIENT_FETCH_REGISTRY=false
- JAVA_OPTS=-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Xms256M -Xmx512M
expose:
- “8000”
networks:
- “c7nNetwork”

api-gateway:
container_name: api-gateway
hostname: api-gateway
image: registry.cn-shanghai.aliyuncs.com/choerodon/api-gateway:0.17.1
links:
- eureka-server
depends_on:
- eureka-server
ports:
- “8080:8080”
environment:
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/iam_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
- SPRING_DATASOURCE_USERNAME=root
- SPRING_DATASOURCE_PASSWORD=root
- SPRING_CLOUD_CONFIG_ENABLED=false
- HYSTRIX_STREAM_QUEUE_ENABLED=false
- SPRING_CLOUD_BUS_ENABLED=false
- SPRING_SLEUTH_STREAM_ENABLED=false
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8000/eureka/
- ZUUL_ADDHOSTHEADER=true
- SPRING_APPLICATION_JSON={“zuul”:{“routes”:{“oauth”:{“path”:"/oauth/**", “serviceId”:“oauth-server”}}}}
- JAVA_OPTS=-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Xms512M -Xmx768M
expose:
- “8080”
networks:
- “c7nNetwork”
iam-service:
container_name: iam-service
image: registry.cn-shanghai.aliyuncs.com/choerodon/iam-service:0.17.1
depends_on:
- eureka-server
links:
- eureka-server
ports:
- “8030:8030”
environment:
- SPRING_CLOUD_CONFIG_ENABLED=false
- HYSTRIX_STREAM_QUEUE_ENABLED=false
- SPRING_CLOUD_BUS_ENABLED=false
- SPRING_SLEUTH_STREAM_ENABLED=false
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8000/eureka/
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/iam_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
- SPRING_DATASOURCE_USERNAME=root
- SPRING_DATASOURCE_PASSWORD=root
- CHOERODON_SAGA_CONSUMER_ENABLED=false
- CHOERODON_SCHEDULE_CONSUMER_ENABLED=false
- JAVA_OPTS=-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Xms512M -Xmx768M
networks:
- “c7nNetwork”
manager-service:
container_name: manager-service
image: registry.cn-shanghai.aliyuncs.com/choerodon/manager-service:0.17.1
depends_on:
- eureka-server
links:
- eureka-server
ports:
- “8963:8963”
environment:
- SPRING_CLOUD_CONFIG_ENABLED=false
- HYSTRIX_STREAM_QUEUE_ENABLED=false
- SPRING_CLOUD_BUS_ENABLED=false
- SPRING_SLEUTH_STREAM_ENABLED=false
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8000/eureka/
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/manager_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
- SPRING_DATASOURCE_USERNAME=root
- SPRING_DATASOURCE_PASSWORD=root
- CHOERODON_SWAGGER_CLIENT=client
- CHOERODON_SWAGGER_OAUTH_URL=http://api-gateway:8080/oauth/oauth/authorize
- CHOERODON_GATEWAY_DOMAIN=api-gateway:8080
- JAVA_OPTS=-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Xms512M -Xmx768M
networks:
- “c7nNetwork”
asgard-service:
container_name: asgard-service
image: registry.cn-shanghai.aliyuncs.com/choerodon/asgard-service:0.17.1
depends_on:
- eureka-server
- redis
- mysql
links:
- eureka-server
- redis
- mysql
ports:
- “18080:18080”
environment:
- SPRING_CLOUD_CONFIG_ENABLED=false
- HYSTRIX_STREAM_QUEUE_ENABLED=false
- SPRING_CLOUD_BUS_ENABLED=false
- SPRING_SLEUTH_STREAM_ENABLED=false
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8000/eureka/
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/asgard_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
- SPRING_DATASOURCE_USERNAME=root
- SPRING_DATASOURCE_PASSWORD=root
- SPRING_REDIS_HOST=redis
- SPRING_REDIS_PORT=6379
- SPRING_REDIS_DATABASE=7
- JAVA_OPTS=-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Xms512M -Xmx768M
networks:
- “c7nNetwork”
oauth-server:
container_name: oauth-server
image: registry.cn-shanghai.aliyuncs.com/choerodon/oauth-server:0.17.1
depends_on:
- eureka-server
- redis
- mysql
links:
- eureka-server
- redis
- mysql
ports:
- “8020:8020”
environment:
- SPRING_CLOUD_CONFIG_ENABLED=false
- HYSTRIX_STREAM_QUEUE_ENABLED=false
- SPRING_CLOUD_BUS_ENABLED=false
- SPRING_SLEUTH_STREAM_ENABLED=false
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8000/eureka/
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/iam_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
- SPRING_DATASOURCE_USERNAME=root
- SPRING_DATASOURCE_PASSWORD=root
- SPRING_REDIS_HOST=redis
- SPRING_REDIS_PORT=6379
- SPRING_REDIS_DATABASE=4
- CHOERODON_OAUTH_LOGIN_SSL=false
- CHOERODON_OAUTH_LOGIN_PATH=/login
- JAVA_OPTS=-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Xms512M -Xmx768M
networks:
- “c7nNetwork”
networks:
c7nNetwork:
driver: bridge

你好。manager-service需要在asgard-service之后启动,这样才能发送saga到asgard,你可以重启下manager-service,看是否会重新触发服务的数据初始化。

重启了manager-service,asgard-service的控制台打印了这段日志


但是表还是没数据

查看asgard-service数据库

  1. 首先看是否已经注册初始化权限的sagaTask,打开asgard_orch_saga_task表,


    执行sql
    SELECT * FROM asgard_orch_saga_task WHEREsaga_codeLIKE '%mgmt-actuator-refresh%'
    看是否有结果:

  2. 然后查看该sagaTask是否有执行的实例,以及执行成功了没。 查看asgard_saga_task_instance表,
    image
    执行sql:
    SELECT * FROM asgard_saga_task_instance WHEREsaga_codeLIKE '%mgmt-actuator-refresh%'
    看结果是否有刷新权限的执行实例,执行成功状态:

已经找到原因了,首先感谢这位大佬的帮助,刚刚我查了下asgard_saga_task_instance 表,发现都是等待状态,再打开配置文件发现iam-service的saga配置默认没打开,改了文件后重启就有数据了

您好,想请教一下您启动了哪些服务,启动顺序是怎样的?前端有改什么配置吗?
我现在也是遇到了数据不能成功初始化的问题

启动注册中心、iam-service、manager-service、asgard-service这几个OK了,manager-service要在asgard-service后启动,注意iam-service配置文件的CHOERODON_SAGA_CONSUMER_ENABLED=true,这样才能接受saga来初始化出数据

你好,我这默认就是这样启用的,但是并没有成功初始化数据

那你要看你的asgard_saga_task_instance表上有没有任务了,如果没有任务(也就是没有数据)那你要看你manager和asgard的启动有没有报错,如果有数据,而STATUS这个字段不是COMPLETED的话,你要看你启动iam-service的日志有没有报错,前提你要确定你的iam-service和asgard的数据库是存在的