2022년 10월 15일 토요일

Elasticsearch 8.0의 변화 - 2nd

버전 8은 보안 기능이 필수다. 이때 스택 간 기능 연동을 위해 윈도우 버전은 관련 정보를 콘솔 실행 화면에 뿌려줌. 그런데 리눅스 RPM 버전은 (막연히 로그에 관련 정보가 찍힐 거라 생각했는데) 아니었다. 일단 yum 설치를 진행하면 관련 정보를 확인할 수 없다.

1. rpm 수동 설치
[root@Centos7 ~]# rpm -i elasticsearch-8.4.3-x86_64.rpm
warning: elasticsearch-8.4.3-x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Creating elasticsearch group... OK
Creating elasticsearch user... OK
--------------------------- Security autoconfiguration information ------------------------------

Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.

The generated password for the elastic built-in superuser is : UmGZpsdhuL+oB3+uX-tQ

If this node should join an existing cluster, you can reconfigure this with
'/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token <token-here>'
after creating an enrollment token on your existing cluster.

You can complete the following actions at any time:

Reset the password of the elastic built-in superuser with
'/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic'.

Generate an enrollment token for Kibana instances with
 '/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana'.

Generate an enrollment token for Elasticsearch nodes with
'/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node'.

2. 키바나 연동 토큰 생성
[root@Centos7 ~]# service elasticsearch start Redirecting to /bin/systemctl start elasticsearch.service
[root@Centos7 ~]#
[root@Centos7 ~]# /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana eyJ2ZXIiOiI4LjQuMyIsImFkciI6WyIxOTIuMTY4LjMxLjE4OTo5MjAwIl0sImZnciI6IjI4YjBkZDgwYWI5Y2ZjYjVlOWExOGU3MTUwOWYzZDljYzZlODNkMGFiYzk5ZDZmZGI0YTcyMTFlMmFhMDdmMTkiLCJrZXkiOiI3NmMyMTRNQjBHcF8wbGU2V3V1aTpxWjdzdnpaVVJES1BHWV9kZGdaMFV3In0=

3. 키바나 설치 후 실행

이때도 토큰 입력 링크는 로그에 없다. 서비스 상태 체크를 통해 확인하거나,
[root@Centos7 ~]# service kibana start
Redirecting to /bin/systemctl start kibana.service
[root@Centos7 ~]# 
[root@Centos7 ~]# service kibana status
Redirecting to /bin/systemctl status kibana.service
● kibana.service - Kibana
   Loaded: loaded (/usr/lib/systemd/system/kibana.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-10-15 00:56:09 KST; 46s ago
     Docs: https://www.elastic.co
 Main PID: 12453 (node)
   CGroup: /system.slice/kibana.service
           └─12453 /usr/share/kibana/bin/../node/bin/node /usr/share/kibana/bin/../src/cli/dist

Oct 15 20:56:09 Centos7 systemd[1]: Started Kibana.
Oct 15 20:56:09 Centos7 systemd[1]: Starting Kibana...
Oct 15 20:56:11 Centos7 kibana[12453]: [2022-10-15T00:56:11.376+09:00][INFO ][node] Kibana process configured ..., ui]
Oct 15 20:56:18 Centos7 kibana[12453]: [2022-10-15T00:56:18.883+09:00][INFO ][http.server.Preboot] http server...:5601
Oct 15 20:56:18 Centos7 kibana[12453]: [2022-10-15T00:56:18.932+09:00][INFO ][plugins-system.preboot] Setting ...etup]
Oct 15 20:56:18 Centos7 kibana[12453]: [2022-10-15T00:56:18.934+09:00][INFO ][preboot] "interactiveSetup" plug…ration…
Oct 15 20:56:18 Centos7 kibana[12453]: [2022-10-15T00:56:18.960+09:00][INFO ][root] Holding setup until preboo...eted.
Oct 15 20:56:18 Centos7 kibana[12453]: i Kibana has not been configured.
Oct 15 20:56:18 Centos7 kibana[12453]: Go to http://localhost:5601/?code=795620 to get started.

루트 권한 실행을 통해 확인해야 함.
[root@Centos7 ~]# /usr/share/kibana/bin/kibana --allow-root
[2022-10-15T21:08:21.374+09:00][INFO ][node] Kibana process configured with roles: [background_tasks, ui]
[2022-10-15T21:08:33.100+09:00][INFO ][http.server.Preboot] http server running at http://192.168.56.100:5601
[2022-10-15T21:08:33.155+09:00][INFO ][plugins-system.preboot] Setting up [1] plugins: [interactiveSetup]
[2022-10-15T21:08:33.158+09:00][INFO ][preboot] "interactiveSetup" plugin is holding setup: Validating Elasticsearch connection configuration…
[2022-10-15T21:08:33.186+09:00][INFO ][root] Holding setup until preboot stage is completed.

i Kibana has not been configured.

Go to http://localhost:5601/?code=399317 to get started.

이때 localhost 웹 접속을 할 수 없다면, 카바나의 서비스 IP를 웹 접속 가능한 IP로 바꿔야 한다. 키바나도 엘라스틱 노드처럼 localhost 포함 모든 시스템 IP와 바인딩 되는 걸로 착각하는 바람에 이때 많이 헤맴(..)

4. 로그스태시

다음은 리눅스 secure 로그 연동 파이프라인. 루트 권한을 이용한 콘솔 실행은 잘 된다.
input {
 file {
  path => "/var/log/secure"
 }
}

output {
 elasticsearch {
  hosts => "https://localhost"
  user => "elastic"
  password => "pass"
  cacert => "/etc/elasticsearch/certs/http_ca.crt"
 }
}

그러나 pipelines.yml에 파이프라인 경로를 지정한 후 서비스로 실행하면 문제 발생.
[2022-10-15T21:15:46,475][ERROR][logstash.outputs.elasticsearch] Invalid setting for elasticsearch output plugin:

  output {
    elasticsearch {
      # This setting must be a path
      # File does not exist or cannot be opened /etc/elasticsearch/certs/http_ca.crt
      cacert => "/etc/elasticsearch/certs/http_ca.crt"
      ...
    }
  }

로그스태시가 인증서에 접근하지 못한다. 방법은 인증서를 로그스태시 경로로 복사 후, 읽기 권한 부여. 이후 파이프라인의 인증서 경로를 바꿔주면 된다. 아니면 인증 기능을 disable 하거나. (ssl_certificate_verification => false)
[root@Centos7 ~]# cp /etc/elasticsearch/certs/http_ca.crt /etc/logstash/
[root@Centos7 ~]# chmod 644 /etc/logstash/http_ca.crt
[root@Centos7 ~]# ll /etc/logstash/http_ca.crt
-rw-r--r--. 1 root root 1915 Oct 15 17:48 /etc/logstash/http_ca.crt

엘라스틱을 6년쯤 쓰면서 웬만한 트러블은 대응할 수 있다는 자만심과 함께 코로나로 뜸해진 강의 환경으로 인해 내가 많이 해이해졌음을 느꼈다. 강의 중에 정말 쥐구멍 있으면 숨고 싶더라.

데이터 분석이 강의 주제이며 엘라스틱은 데이터 계산툴일 뿐임을 강조해놓고, 정작 툴 사용 미숙으로 데이터 분석 비중이 줄어드는 피해를 본 수강생들에게 다시 한 번 사과하는 마음으로 정리한다.
 
23.10.16
8.9 버전부터? yum 설치 과정에서도 보안 기능 가이드 확인 가능.

관련 글

댓글 없음:

댓글 쓰기

크리에이티브 커먼즈 라이선스