主机 | ip | 角色 | 备注 |
---|---|---|---|
主 | 192.168.88.161 | master | |
主 | loadblance | ||
从 | slave |
在mysql创建keycloak数据库,创建时选择编码utf-8,注意不支持utfmb4,创建完应用启动会自动创建数据表。
2台以上的服务器。
系统空间:512m内存,1g磁盘空间
需要安装JRE 1.8以上版本,并配置环境变量。
安装nginx作分发代理(部署完成之后,把IP端口配置分发,不用ng 写本机ip也能用)。
最好没有防火墙,服务器与服务器之间的UDP端口55200,45688必须互通。
集群内部数据共享需要开启IP多播,在root 权限下 master ,slave 机执行:
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
注:如果服务器不支持IP多播(阿里云ECS***服务器不支持)或网络环境不允许使用UDP,请参照配置TCP**点对点共享方式。
进入DEP/keycloak-4.0.0.Beta3/bin目录,编辑domain.sh文件,找到JBOSS_LOG_DIR参数,并修改为JBOSS_LOG_DIR="/cy/logs/keycloak/log",具体按实际路径修改。
DEP/keycloak-4.0.0.Beta3/domain/configuration目录,编辑default-server-logging.properties文件,找到
handler.FILE.fileName=${org.jboss.boot.log.file:server.log}
修改为 handler.FILE.fileName=/cy/logs/keycloak/server-one/server.log
注: server-one 代表主机,从机请修改为server-two,server-three...
### 创建目录 (只要目录对了即可)
[root@node1 main]# mkdir /home/admin/keycloak-15.0.2/modules/system/layers/base/com/mysql/main
[root@node1 main]# vim module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-8.0.26.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
--------
mysql-connector-java-8.0.26.jar是jar包名称 需要将jar包上传到该文件的同级目录
进入DEP/keycloak-4.0.0.Beta3/domain/configuration目录,打开domain.xml文件,找到KeycloakDS。注:有两处都要修改。
<connection-url>jdbc:mysql://192.168.3.206:3306/keycloak?characterEncoding=UTF-8</connection-url>
.....
<security>
<user-name>root</user-name> --数据库用户名
<password>govnet123</password>--数据库密码
</security>
.......
### 进入目录
[root@node1 main]# cd /home/admin/keycloak-15.0.2/domain/configuration/
### 编辑集群模式的域配置文件
[root@node1 configuration]# vim domain.xml
.....
<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>
......
链接:https://pan.baidu.com/s/1r8c0QErk64v98QGl4gwrog
提取码:gx12
### 进入目录
[root@node1 main]# cd /home/admin/keycloak-15.0.2/domain/configuration/
### 编辑集群模式的域配置文件
[root@node1 configuration]# vim domain.xml
...
<interface name="private">
<inet-address value="${jboss.bind.address.private:127.0.0.1}"/> --修改为服务器IP
</interface>
......
<socket-binding-groups>
<socket-binding-group name="standard-sockets" default-interface="public">
<socket-binding name="ajp" port="${jboss.ajp.port:8009}"/>
<socket-binding name="http" port="${jboss.http.port:8080}"/> --修改为服务器可用端口
......
<socket-binding-group name="ha-sockets" default-interface="public">
<socket-binding name="ajp" port="${jboss.ajp.port:8009}"/>
<socket-binding name="http" port="${jboss.http.port:8080}"/>--修改为服务器可用端口(与上面端口一样)
.......
进入DEP/keycloak-4.0.0.Beta3/domain/configuration目录,打开host-master.xml文件,
......
<management-interfaces>
<native-interface security-realm="ManagementRealm">
<socket interface="management" port="${jboss.management.native.port:9999}"/>
--9999是从机连接主机端口号(如未占用不做修改)
</native-interface>
<http-interface security-realm="ManagementRealm">
<http-upgrade enabled="true"/>
<socket interface="management" port="${jboss.management.http.port:9990}"/>
--9990主机控制器管理客户端访问端口(如未占用不做修改) </http-interface>
......
<interfaces>
<interface name="management">
<inet-address value="${jboss.bind.address.management127.0.0.1}"/> --修改为服务器IP
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:127.0.0.1}"/> --修改为服务器IP
</interface>
</interfaces>
......
<server name="server-one" group="auth-server-group" auto-start="true">
<!--
~ Remote JPDA debugging for a specific server
~ <jvm name="default">
~ <jvm-options>
~ <option value="-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"/>
~ </jvm-options>
~ </jvm>
~
-->
<!--
~ server-two avoids port conflicts by incrementing the ports in
~ the default socket-group declared in the server-group
-->
<socket-bindings port-offset="150"/> --端口偏移量,主机的集群节点端口根据这个偏移量产生,比如主机端口配置8080,主机节点端口为8080+150=8230。
</server>
......
此用户是主机控制台管理用户,也是从机连接主机认证用户,非系统用户,admin已经创建,会提示已经存在,选择a 重置密码。
进入DEP/keycloak-4.0.0.Beta3/bin目录,添加add-user.sh文件执行权限,执行这个文件。
$ add-user.sh
What type of user do you wish to add?
a) Management User (mgmt-users.properties)
b) Application User (application-users.properties)
(a): a
Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
Username : admin
Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
- The password should not be one of the following restricted values {root, admin, administrator}
- The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
- The password should be different from the username
Password :
Re-enter Password :
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[ ]:
About to add user 'admin' for realm 'ManagementRealm'
Is this correct yes/no? yes
Added user 'admin' to file '/.../standalone/configuration/mgmt-users.properties'
Added user 'admin' to file '/.../domain/configuration/mgmt-users.properties'
Added user 'admin' with groups to file '/.../standalone/configuration/mgmt-groups.properties'
Added user 'admin' with groups to file '/.../domain/configuration/mgmt-groups.properties'
Is this new user going to be used for one AS process to connect to another AS process?
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? yes
To represent the user add the following to the server-identities definition <secret value="bWdtdDEyMyE=" />
admin / bWdtdDEyMyE= 是从机连接主机的用户名、密钥,请保存。
链接:https://pan.baidu.com/s/1Ky_mQlpVYwNG1ytucuMDZg
提取码:gx12
添加domain.sh文件执行权限
./domain.sh --host-config=host-master.xml
这里输入的就是自己当时增加admin用户设置的密码
Runtime
会显示master节点上的服务 (这里应该还有一个负载均衡 虚拟机配置不高 所以把这里注释掉了)tail -f /home/admin/keycloak-15.0.2/domain/servers/server-one/log/server.log
1. 执行 ps -ef | grep keycloak 查看进程号
2. 再执行 kill -9 进程号
注:默认2个进程,可能会有多个进程,一般结束掉第一个后面进程都会结束掉,不排除特殊情况,请多次执行ps -ef | grep keycloak 查看是否有可执行进程。
注:此步骤是配置TCP共享数据方式,默认不需要配置(集群默认采用UDP共享),服务器不支持IP多播或网络环境不允许使用UDP必须配置此项,如果不想采用UDP多播共享数据也可以配置。阿里云ECS不支持IP多播部署需要配置此项。
......
<subsystem xmlns="urn:jboss:domain:jgroups:5.0">
<channels default="ee">
<channel name="ee" stack="tcp" cluster="ejb"/> --配置TCP连接方式
</channels>
......
<stacks>
<stack name="tcp">
<transport type="TCP" socket-binding="jgroups-tcp"/>
<!-- <socket-protocol type="MPING" socket-binding="jgroups-mping"/> -->
<protocol type="TCPPING">
<property name="initial_hosts">127.0.0.1[7700],127.0.0.2[7700]</property>--配置集群IP, 127.0.0.1为集群服务器IP,7700端口是根据7600+端口偏移量产生
<property name="port_range">0</property> -- 你要搜寻机器可以Ping到port 的范围
</protocol>
<protocol type="MERGE3"/>
<protocol type="FD_SOCK"/>
<protocol type="FD_ALL"/>
<protocol type="VERIFY_SUSPECT"/>
<protocol type="pbcast.NAKACK2"/>
<protocol type="UNICAST3"/>
<protocol type="pbcast.STABLE"/>
<protocol type="pbcast.GMS"/>
<protocol type="MFC"/>
<protocol type="FRAG2"/>
</stack>
</stacks>
</subsystem>
......
进入DEP/keycloak-4.0.0.Beta3/domain/configuration目录,打开host-slave.xml文件,
<host xmlns="urn:jboss:domain:5.0" name="slave">
--slave节点名,配置2个或2个以上从机请修改
......
<server-identities>
<!-- Replace this with either a base64 password of your own, or use a vault with a vault expression -->
<secret value="bWdtdDEyMyE="/> --连接主机密钥
</server-identities>
......
<domain-controller>
<remote username="admin" security-realm="ManagementRealm"> --admin连接主机用户名
<discovery-options>
<static-discovery name="primary" protocol="${jboss.domain.master.protocol:remote}" host="${jboss.domain.master.address:127.0.0.1}" port="${jboss.domain.master.port:9999}"/>
--127.0.0.1主机IP,9999主机连接端口
</discovery-options>
</remote>
</domain-controller>
<interfaces>
<interface name="management">
<inet-address value="${jboss.bind.address.management127.0.0.1}"/>
--127.0.0.1服务器IP
</interface>
<interface name="public">
--127.0.0.1服务器IP
</interface>
<interface name="private">
<inet-address value="${jboss.bind.address.private:127.0.0.1}"/>
--127.0.0.1服务器IP
</interface>
</interfaces>
......
<servers>
<server name="server-two" group="auth-server-group" auto-start="true">
--server-two从机服务器名,配置2个或2个以上从机请修改第三个从机为server-three,第四个从机为server-four.....
<!--
~ server-two avoids port conflicts by incrementing the ports in
~ the default socket-group declared in the server-group
-->
<socket-bindings port-offset="250"/> --端口偏移量,从机的集群节点端口根据这个偏移量产生,比如主机端口配置8080,从机节点端口为8080+250=8330。
</server>
</servers>
......
./bin/domain.sh --host-config=host-slave.xml
从机节点:访问 http://127.0.0.1:8330
说明 :127.0.0.1:服务器IP 8330:8080(主机配置端口)+250(主机端口偏移量)
同上
./add-user-keycloak.sh --sc ../domain/servers/server-one/configuration -u admin -p admin