ubuntu下部署keycloak

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 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章