https://downloads.jboss.org/keycloak/11.0.2/keycloak-11.0.2.zip
1.上传zip 并解压 uzip keycloak-11.0.2.zip
2.创建mysql数据库
CREATE SCHEMA `keycloak` DEFAULT CHARACTER SET utf8 ;
3.安装mysql的jdbc驱动
下载mysql的JDBC驱动(mysql-connector-java-8.0.21.jar)。在${KEYCLOAK_HOME}/modules/system/layers/base目录下创建目录com/mysql/main,复制JDBC驱动到此目录下,并创建文件module.xml,文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<module name="com.mysql" xmlns="urn:jboss:module:1.5">
<resources>
<resource-root path="mysql-connector-java-8.0.21.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
4.修改keycloak配置文件
编辑${KEYCLOAK_HOME}/standalone/configuration/standalone.xml文件,找到datasources节点,使用如下内容代替:
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/keycloak?useSSL=false&serverTimezone=GMT%2B8&characterEncoding=UTF-8</connection-url>
<driver>mysql</driver>
<security>
<user-name>xxx(改成你自己的)</user-name>
<password>xxxx(改成你自己的)</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
5.配置外网访问
-
默认配置只能使用localhost和127.0.0.1访问应用,也就是只能本机访问。网络访问需要修改配置文件。找到配置文件${KEYCLOAK_HOME}\standalone\configuration\standalone.xml ,查找interfaces节点,如下配置:
<interfaces>
<interface name="management">
<inet-address value="${jboss.bind.address.management:0.0.0.0}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:0.0.0.0}"/>
</interface>
</interfaces>
6.添加管理员用户
./add-user.sh -r master -u admin -p admin
7.启动keycloak
进入${KEYCLOAK_HOME}/bin目录, 后台启动
./standalone.sh&
运行成功的标志:
数据库新建了很多表
访问地址:http://x.x.x.x:9990/console/index.html