Tutorials & Tips/KeyCloak Server

Keycloak postgresql 연동

PHAROS IAM 2022. 12. 2. 10:55

keycloak은 기본적으로 내부 h2 데이터베이스를 사용한다.

하지만 관리를 위해 외부 DB를 사용하기 위해서 몇가지 수정해 주어야한다.

 

- 기본 환경 설정

./kc.sh show-config 입력하면 아래와 같은 문구가 나온다.

1. keycloak 외부 db driver 다운로드

bin/kc.sh build --db=postgres // 여기는 db driver 이름 입력하면 된다 (ex: maraidb, mysql 등등)

 

2. DB 설정

conf 아래 keycloak.conf 파일에 들어가 db 설정해주기

db = postgres

db-username=[db id]

db-password=[db password]

db-url=jdbc:posgresql:// [db 주소]

 

예시)

db = postgres

db-username=postgres

db-password=1111

db-url=jdbc:postgresql://localhost:5432/postgres

 

./kc.sh show-config 입력해서 환경설정을 보게되면

 

kc.db = postgres

kc.dp-password = ******** 설정된것을 볼 수 있다.

 


 

설정 후 postgresql 아래와 같은 에러

FATAL : Ident Authentication failed for user "postgres"  이 생길 수 있다.

에러화면 1
에러화면 2

 

cd /var/lib/pgsql/10/data로 이동후 vi pg_hba.com 파일을 들어가서 맨 마지막줄에

host all  all                     ident  -> md5

host all  all                     ident  -> md5 로 수정해준다.

수정 전
수정 후

 

 

서비스를 재시작하고 Dbaever 과 연결하면 테이블이 생성된다.

 

 

Deaver 연결 후 상태