Skip to content

Instantly share code, notes, and snippets.

@nicdk
Last active November 19, 2018 08:18
Show Gist options
  • Save nicdk/10a7cf2a8011f52338b7879661cf61f4 to your computer and use it in GitHub Desktop.
Save nicdk/10a7cf2a8011f52338b7879661cf61f4 to your computer and use it in GitHub Desktop.
vagrant-box-keycloak_20181119

KeyCloak を vagrant で動かす

  • 初稿: 2018/11/19

材料

  • keycloak
  • java

手順メモ

vagrant_2

% vagrant init -m centos/7
% vagrant up
% vagrant ssh

java

[vagrant]% sudo rpm -iUvh ./jdk-11.0.1_linux-x64_bin.rpm

keycloak

qucikstart 参照。

[vagrant]% tar zxf ./keycloak-4.6.0.Final.tar.gz
[vagrant]% cd keycloak-4.6.0.Final/bin
[vagrant]% ./standalone.sh
:
:
06:54:32,906 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
06:54:32,907 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
06:54:32,907 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: Keycloak 4.6.0.Final (WildFly Core 6.0.2.Final) started in 57844ms - Started 577 of 834 services (557 services are lazy, passive or on-demand)

これで vagrant 内なら http://localhost:8080/auth にアクセスしたとき、初期ユーザ作成のページが表示される(はず)。 しかし、ゲスト側(vagrant 内 centos)から port forwarding したホスト側のブラウザでアクセスしたとき、

You need local access to create the initial admin user.

と表示される。 なので、コマンドラインから実行する。

add-user-keycloak script

java11 ではエラーがでる。

[vagrant@localhost bin]$ java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
[vagrant@localhost bin]$ ./add-user-keycloak.sh -u admin
org.jboss.modules.ModuleNotFoundException: java.se
	at org.jboss.modules.Module.addPaths(Module.java:1266)
	at org.jboss.modules.Module.link(Module.java:1622)
	at org.jboss.modules.Module.relinkIfNecessary(Module.java:1650)
	at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:296)
	at org.jboss.modules.Main.main(Main.java:437)

なので java8 を入れた。

[vagrant]% sudo rpm -iUvh ./jdk-8u191-linux-x64.rpm
[vagrant]% sudo alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jdk-11.0.1/bin/java
   2           /usr/java/jdk1.8.0_191-amd64/jre/bin/java

Enter to keep the current selection[+], or type selection number: 2

アカウント作成

[vagrant]% ./add-user-keycloak.sh -u admin
Press ctrl-d (Unix) or ctrl-z (Windows) to exit
Password:
Added 'admin' to '/vagrant/keycloak-4.6.0.Final/standalone/configuration/keycloak-add-user.json', restart server to load user

java11に戻して再起動。

[vagrant]% sudo alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jdk-11.0.1/bin/java
   2           /usr/java/jdk1.8.0_191-amd64/jre/bin/java

Enter to keep the current selection[+], or type selection number: 1
[vagrant]% ./standalone -b=0.0.0.0

ホスト側のブラウザで admin console http://localhost:8080/auth/admin にアクセスし、作成した ID/PW でログインする。

[EOF]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment