1.首先先保证linux服务器上安装的有jdk和mysql
我这里安装的版本是
jdk:11.04
mysql:8.0.17
然后创建一个名为keycloak的数据库(名称随便起,但是建议起这个名字)
2.然后去Keyclock官网下载linux下载server版本的keycloak的包
https://www.keycloak.org/downloads.html (我下载时的版本是keycloak-7.0.1.tar.gz)
3.然后在usr/local下(路径随意,看自己习惯,建议usr/local下) 创建一个文件夹命名为keycloak(名称随便起)
4.然后将通过xshell或者其他工具将包复制到usr/local/keycloak
然后使用命令进行解压
tar -zxvf keycloak-7.0.1.tar.gz
5.解压完成后,删除多余的tar.gz文件(删不删都行,看你们自己),然后修改module.xml
修改module.xml之前先使用命令将下载好的mysql-connect的jar包复制到该文件夹下
移动mysql-connect的jar包到改该目录
mv mysql-connector-java-8.0.17.jar modules/system/layers/base/com/mysql/main/
然后修改相应的module/xml内容
vim module.xml
module.xml内容为
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2010, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<module name="com.mysql"
xmlns="urn:jboss:module:1.5">
<resources>
<resource-root path="mysql-connector-java-8.0.17.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
修改standalone.xml
修改其中的部分内容
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
<!-- database keycloak 需要事先创建好 -->
<connection-url>jdbc:mysql://127.0.0.1:3306/keycloak?useSSL=false</connection-url>
<driver>mysql</driver>
<pool>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>root</user-name>
<password>admin</password>
</security>
</datasource
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<!-- 配置driver名称,指定引用的module名称 -->
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
设置所有IP可以访问
<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.然后设置默认的登录用户,如果不设置外部访问无法登录会提示使用localhost
①进bin文件夹
②然后执行命令
sh add-user-keycloak.sh -r master -u admin -p admin
其中第一个admin是用户名,第二个admin是密码 用户名和密码随意设置,自己记住就行
7.然后进入bin文件夹 运行命令
sh bin/standalone.sh -Djboss.socket.binding.port-offset=100
// 如果直接sh bin/standalone.sh 则使用默认端口8080,如果运行上面的端口就是8180以此类推
8.然后在浏览器进行访问 ip:port/auth
如 192.168.XX.128:8080/auth