因此,我尝试使用mariadb容器为keycloak构建一个Docker容器,并将其用于数据库存储。(我真的不确定是否值得用keycloak替换内置的数据库,并使用mariadb作为我将要使用的服务器大小,但我想保持它的一致性)我的问题是,有人运气好吗?我能让集装箱启动(keycloak和mariadb都有)keycloak最初会工作,并在连接到mariadb服务器后创建所需的数据库和表。据我所知,这是keycloak和mariadb的编码/联盟问题,日志只会抛出很多错误,比如
[Failed SQL: (1194) ALTER TABLE keycloak.CLIENT_SESSION ADD REALM_ID VARCHAR(255) NULL]
而且容器卡在了重启循环中。现在如果我把它混在一起,用postgres容器配置它,它就能正常工作。
这是我试图让工作的组成设置。
keycloak_mariadb_production:
container_name: keycloak_mariadb_production
image: mariadb:10.7.7-focal
restart: unless-stopped
ports:
- 33306:3306
expose:
- 33306
environment:
MARIADB_ROOT_PASSWORD: "${KEYCLOAK_DATABASE_ROOT_PASSWORD}"
MYSQL_DATABASE: "${KEYCLOAK_DATABASE_PRODUCTION}"
MYSQL_USER: "${KEYCLOAK_DATABASE_SU_USERNAME}"
MYSQL_PASSWORD: "${KEYCLOAK_DATABASE_SU_PASSWORD}"
command: --init-file /data/application/init.sql
volumes:
- ./mysql-keycloak-data:/var/lib/mysql
- ./backend/app/init_keycloak.sql:/data/application/init.sql
healthcheck:
test: "mysql -u${KEYCLOAK_DATABASE_SU_USERNAME} -p${KEYCLOAK_DATABASE_SU_PASSWORD} -e 'SHOW DATABASES'"
interval: 5s
timeout: 5s
retries: 20
networks:
keycloak_mariadb_production_network:
aliases:
- keycloak_mariadb_production_network
keycloak_frontend_production:
container_name: keycloak_frontend_production
image: quay.io/keycloak/keycloak:20.0.3
restart: unless-stopped
ports:
- 8080:8080
expose:
- 8080
command: ["start-dev"]
environment:
PROXY_ADDRESS_FORWARDING: "true"
KC_DB: mariadb
KC_DB_URL: jdbc:mariadb://keycloak_mariadb_production:3306/su_keycloak_production
KC_DB_USERNAME: "root"
KC_DB_PASSWORD: "test"
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: Pa55w0rd
depends_on:
- keycloak_mariadb_production
networks:
- keycloak_mariadb_production_network
networks:
keycloak_mariadb_production_network:
driver: bridge
我只是真的试图保持它的一致性,并保持我可以在一个mariadb数据库。如果我必须去postgress的方式,由于一些限制,我可以。但我想挑选任何人的大脑比我更好,看看是否有一个可靠的解决方案,因为我一直在阅读它可能是一个问题的jdbc mariadb连接器不知何故。提前感谢任何建议。
编辑:
因此,我尝试了一种基本配置,该配置排除了卷下的本地卷:节,它启动良好。如果我猜得没错的话,它似乎没有很好地与本地文件系统一起运行。
mysql:
image: docker.io/mariadb:10
environment:
MARIADB_DATABASE: keycloak
MARIADB_ROOT_PASSWORD: rootpassword
MARIADB_PASSWORD: password
MARIADB_USER: keycloak
ports:
- 3306:3306
keycloak:
image: quay.io/keycloak/keycloak:20.0
environment:
KC_HOSTNAME: localhost
KC_HOSTNAME_PORT: 8080
KC_HOSTNAME_STRICT_BACKCHANNEL: "true"
KC_DB: mariadb
KC_DB_URL: jdbc:mariadb://mysql:3306/keycloak?characterEncoding=UTF-8
KC_DB_USERNAME: keycloak
KC_DB_PASSWORD: password
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: adminpassword
KC_HEALTH_ENABLED: "true"
KC_LOG_LEVEL: info
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:8080/health/ready" ]
interval: 15s
timeout: 2s
retries: 15
command: start-dev
ports:
- 8080:8080
编辑在试图更改mysql文件夹的权限后添加更多日志。
Updating the configuration and installing your custom providers, if any. Please wait. 2023-02-03 20:03:51,600 INFO [io.quarkus.deployment.QuarkusAugmentor] (main) Quarkus augmentation completed in 8475ms 2023-02-03 20:03:53,867 INFO [org.keycloak.quarkus.runtime.hostname.DefaultHostnameProvider] (main) Hostname settings: Base URL: , Hostname: localhost, Strict HTTPS: false, Path: , Strict BackChannel: true, Admin URL: , Admin: , Port: 8080, Proxied: false 2023-02-03 20:03:55,742 WARN [io.quarkus.agroal.runtime.DataSources] (main) Datasource enables XA but transaction recovery is not enabled. Please enable transaction recovery by setting quarkus.transaction-manager.enable-recovery=true, otherwise data may be lost if the application is terminated abruptly 2023-02-03 20:03:57,062 INFO [org.keycloak.broker.provider.AbstractIdentityProviderMapper] (main) Registering class org.keycloak.broker.provider.mappersync.ConfigSyncEventListener 2023-02-03 20:03:57,150 WARN [org.infinispan.CONFIG] (keycloak-cache-init) ISPN000569: Unable to persist Infinispan internal caches as no global state enabled 2023-02-03 20:03:57,174 WARN [org.infinispan.PERSISTENCE] (keycloak-cache-init) ISPN000554: jboss-marshalling is deprecated and planned for removal 2023-02-03 20:03:57,186 INFO [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000556: Starting user marshaller 'org.infinispan.jboss.marshalling.core.JBossUserMarshaller' 2023-02-03 20:03:57,426 INFO [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000128: Infinispan version: Infinispan 'Triskaidekaphobia' 13.0.10.Final 2023-02-03 20:03:57,948 INFO [org.keycloak.connections.infinispan.DefaultInfinispanConnectionProviderFactory] (main) Node name: node_251187, Site name: null 2023-02-03 20:03:57,966 WARN [org.mariadb.jdbc.message.server.ErrorPacket] (main) Error: 1146-42S02: Table 'keycloak.migration_model' doesn't exist 2023-02-03 20:03:58,756 WARN [org.mariadb.jdbc.message.server.ErrorPacket] (main) Error: 1146-42S02: Table 'keycloak.databasechangelog' doesn't exist 2023-02-03 20:03:59,371 WARN [org.mariadb.jdbc.message.server.ErrorPacket] (main) Error: 1146-42S02: Table 'keycloak.databasechangeloglock' doesn't exist 2023-02-03 20:03:59,442 WARN [org.mariadb.jdbc.message.server.ErrorPacket] (main) Error: 1146-42S02: Table 'keycloak.databasechangelog' doesn't exist 2023-02-03 20:03:59,443 INFO [org.keycloak.quarkus.runtime.storage.legacy.liquibase.QuarkusJpaUpdaterProvider] (main) Initializing database schema. Using changelog META-INF/jpa-changelog-master.xml 2023-02-03 20:04:02,225 WARN [org.mariadb.jdbc.message.server.ErrorPacket] (main) Error: 1194-HY000: Table 'client_session' is marked as crashed and should be repaired 2023-02-03 20:04:02,433 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to start server in (development) mode 2023-02-03 20:04:02,434 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to update database 2023-02-03 20:04:02,434 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: liquibase.exception.MigrationFailedException: Migration failed for change set META-INF/jpa-changelog-1.1.0.Beta1.xml::1.1.0.Beta1::sthorger@redhat.com: Reason: liquibase.exception.DatabaseException: (conn=5) Table 'client_session' is marked as crashed and should be repaired [Failed SQL: (1194) ALTER TABLE keycloak.CLIENT_SESSION ADD REALM_ID VARCHAR(255) NULL] 2023-02-03 20:04:02,434 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Migration failed for change set META-INF/jpa-changelog-1.1.0.Beta1.xml::1.1.0.Beta1::sthorger@redhat.com: Reason: liquibase.exception.DatabaseException: (conn=5) Table 'client_session' is marked as crashed and should be repaired [Failed SQL: (1194) ALTER TABLE keycloak.CLIENT_SESSION ADD REALM_ID VARCHAR(255) NULL] 2023-02-03 20:04:02,434 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: (conn=5) Table 'client_session' is marked as crashed and should be repaired [Failed SQL: (1194) ALTER TABLE keycloak.CLIENT_SESSION ADD REALM_ID VARCHAR(255) NULL] 2023-02-03 20:04:02,434 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: (conn=5) Table 'client_session' is marked as crashed and should be repaired 2023-02-03 20:04:02,434 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) For more details run the same command passing the '--verbose' option. Also you can use '--help' to see the details about the usage of the particular command. 2023-02-03 20:05:24,940 INFO [org.keycloak.quarkus.runtime.hostname.DefaultHostnameProvider] (main) Hostname settings: Base URL: , Hostname: localhost, Strict HTTPS: false, Path: , Strict BackChannel: true, Admin URL: , Admin: , Port: 8080, Proxied: false 2023-02-03 20:05:26,529 WARN [io.quarkus.agroal.runtime.DataSources] (main) Datasource enables XA but transaction recovery is not enabled. Please enable transaction recovery by setting quarkus.transaction-manager.enable-recovery=true, otherwise data may be lost if the application is terminated abruptly 2023-02-03 20:05:27,490 WARN [org.infinispan.PERSISTENCE] (keycloak-cache-init) ISPN000554: jboss-marshalling is deprecated and planned for removal 2023-02-03 20:05:27,555 INFO [org.keycloak.broker.provider.AbstractIdentityProviderMapper] (main) Registering class org.keycloak.broker.provider.mappersync.ConfigSyncEventListener 2023-02-03 20:05:27,622 WARN [org.infinispan.CONFIG] (keycloak-cache-init) ISPN000569: Unable to persist Infinispan internal caches as no global state enabled 2023-02-03 20:05:27,648 INFO [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000556: Starting user marshaller 'org.infinispan.jboss.marshalling.core.JBossUserMarshaller' 2023-02-03 20:05:27,872 INFO [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000128: Infinispan version: Infinispan 'Triskaidekaphobia' 13.0.10.Final 2023-02-03 20:05:28,399 INFO [org.keycloak.connections.infinispan.DefaultInfinispanConnectionProviderFactory] (main) Node name: node_228690, Site name: null 2023-02-03 20:05:28,413 WARN [org.mariadb.jdbc.message.server.ErrorPacket] (main) Error: 1146-42S02: Table 'keycloak.migration_model' doesn't exist 2023-02-03 20:05:29,787 INFO [org.keycloak.quarkus.runtime.storage.legacy.liquibase.QuarkusJpaUpdaterProvider] (main) Updating database. Using changelog META-INF/jpa-changelog-master.xml 2023-02-03 20:05:30,379 WARN [org.mariadb.jdbc.message.server.ErrorPacket] (main) Error: 1877-HY000: Table keycloak/client_session is corrupted. Please drop the table and recreate. 2023-02-03 20:05:30,596 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to start server in (development) mode 2023-02-03 20:05:30,597 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to update database 2023-02-03 20:05:30,597 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: liquibase.exception.MigrationFailedException: Migration failed for change set META-INF/jpa-changelog-1.1.0.Beta1.xml::1.1.0.Beta1::sthorger@redhat.com: Reason: liquibase.exception.DatabaseException: (conn=25) Table keycloak/client_session is corrupted. Please drop the table and recreate. [Failed SQL: (1877) DELETE FROM keycloak.CLIENT_SESSION] 2023-02-03 20:05:30,597 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Migration failed for change set META-INF/jpa-changelog-1.1.0.Beta1.xml::1.1.0.Beta1::sthorger@redhat.com: Reason: liquibase.exception.DatabaseException: (conn=25) Table keycloak/client_session is corrupted. Please drop the table and recreate. [Failed SQL: (1877) DELETE FROM keycloak.CLIENT_SESSION] 2023-02-03 20:05:30,597 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: (conn=25) Table keycloak/client_session is corrupted. Please drop the table and recreate. [Failed SQL: (1877) DELETE FROM keycloak.CLIENT_SESSION] 2023-02-03 20:05:30,597 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: (conn=25) Table keycloak/client_session is corrupted. Please drop the table and recreate. 2023-02-03 20:05:30,597 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) For more details run the same command passing the '--verbose' option. Also you can use '--
Mariadb集装箱日志2023-02-03 21:43:50 5 [错误] InnoDB:表keycloak/user_entity在InnoDB中包含2个索引,这与.frm文件中定义的索引数1不同。
2023-02-03 21:43:50 5 [错误]信息数据库:表keycloak/user_entity在InnoDB中包含2个索引,这与.frm文件中定义的索引数2不同。
2023-02-03 21:43:51 5 [错误]信息数据库:表keycloak/keycloak_role在InnoDB中包含2个索引,这与.frm文件中定义的索引数1不同。
2023-02-03 21:43:51 5 [错误]信息数据库:表keycloak/client在InnoDB中包含2个索引,这与.frm文件中定义的索引数1不同。
2023-02-03 21:43:51 5 [错误]信息数据库:表keycloak/realm在InnoDB中包含2个索引,这与.frm文件中定义的索引数1不同。
1条答案
按热度按时间vwoqyblh1#
您的卷可能存在权限问题。请尝试
chmod 777 ./mysql-keycloak-data
,如果有效,请对该文件夹使用最小权限。