- [Linux] Elasticsearch SSL/TLS(https) 외부에서 접속하기2024년 05월 20일 13시 11분 36초에 업로드 된 글입니다.작성자: 차나니
설치환경
- Linux : Ubuntu 22.04
- Eleasticsearch, logstash : 7.17.21
미리 준비하기
① 도메인 : 서버 IP를 DNS 정보로 등록하기
② SSL인증서 : 위 도메인 정보가 포함되어있는 인증서 발급하기
도메인의 경우는 유로로 구매할 수도 있고 무료로 사용할 수도 있습니다 !
저는 아래 포스팅과 같은 방법으로 진행하였으니 무료로 사용하실 분들은 참고해서 진행하셔도됩니다 !
인증서 변환하기
elasticsearch에서는 .pem 파일이 아닌 cert와 개인키가 포함되어있는 .p12 파일을 통해 인증서 처리를 진행합니다.
그래서 발급받은 .pem 파일을 .p12의 형식으로 변환해줘야합니다 !
① 파일의 위치
$ cd /etc/letsencrypt/archive/{MyDomain}
정상적으로 인증서를 발급 받았다면 위의 경로에 .pem 파일로 아래와 같이 인증서에 대한 정보들이 각각 분리되어있습니다.
cert1.pem chain1.pem fullchain1.pem privkey1.pem
② 파일 변환하기
$ openssl pkcs12 -export -inkey privkey1.pem -in cert1.pem -out cert_key.p12
인증서 패스워드 입력 : (keystore에 등록해줘야하기 때문에 잊어버리지 않도록 메모해놓기 !)
③ .p12 파일 복사하기($ES_PATH는 환경변수로 설정한 ES 경로)
$ cp cert_key.p12 $ES_PATH/config/cert_key.p12
④ cert_key.p12 파일에 권한 부여하기
chown elasticsearch:elasticsearch $ES_PATH/config/cert_key.p12 chmod 640 $ES_PATH/config/cert_key.p12
⑤ 인증서 비밀번호 변경
$ cd /usr/share/elasticsearch bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password bin/elasticsearch-keystore add xpack.security.http.ssl.truststore.secure_password bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
위에서 설정해줬던 비밀번호 입력 :
⑥ elasticsearch.yml 파일 수정
$ vim /etc/elasticsearch/elasticsearch.yml
xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: none xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/cert_key.p12 xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/cert_key.p12 xpack.security.enabled: true xpack.security.http.ssl.enabled: true xpack.security.http.ssl.verification_mode: none xpack.security.http.ssl.keystore.path: /etc/elasticsearch/cert_key.p12 xpack.security.http.ssl.truststore.path: /etc/elasticsearch/cert_key.p12 xpack.security.http.ssl.keystore.password: 'keypassword' xpack.security.http.ssl.truststore.password: 'keypassword'
⑦ elasticsearch 실행
$ sudo systemctl start elasticsearch
// 인증서 없이 호출하기 $ curl -XGET https://xxx.xxx.xxx.xxx:9200/_nodes?pretty -k -u "elastic:비밀번호"
이제 브라우저에서 접속할 경우 접속이 가능합니다 !
왜냐하면 우리가 인증서를 발급 받는 순간 인증서는 브라우저의 인증 정보를 제공하기 때문입니다 !
하지만 터미널 curl이나, 다른 클라이언트로 연결할 경우 인증 못하는 경우가 발생할 수 있습니다.
'개발공부 > Linux' 카테고리의 다른 글
[Linux] 쓸모있는 Linux 명령어 모음집 (0) 2024.05.21 [Linux] Eleasticsearch, Logstash 설치하기 (0) 2024.05.20 [Linux] Mac에서 기본 터미널로 외부 SSH 연결하기 (0) 2024.05.08 [Linux] nginx에 certbot으로 SSL(https) 보안 인증서 적용하기 (0) 2024.05.04 [Linux] nginx와 React 빌드 및 연동하기 (0) 2024.05.04 다음글이 없습니다.이전글이 없습니다.댓글