새소식

Data Engineering/Distributed System

EFK(ELK) 구축 해보기!! (서버 로그 수집) - 4. OpenSearch와 Open Dashboard 설치하기

  • -

우선 Fluentd를 진행 중이선 서버1은 놔두고 서버2로 들어간다.

Fluentd에서 OpenSearch로 로그를 보내려면

서버 2에 OpenSearch가 설치되어있어야 하기 때문에

서버2에 OpenSearch 설치와 함께 Dashboard까지 설치하려고 한다.

 

우선 두 번째 EC2 서버에 접속한다.

설치전 아래 사항을 확인해둔다.

sudo apt update
sudo apt install build-essential -y

아래에서 환경에 맞는 OpenSearch 파일을 다운받는다.

https://opensearch.org/downloads.html

 

Opensearch 2.11.1

 

opensearch.org

 

wget으로 tar.gx파일을 다운받고 tar -xvf 로 해제하였다.

opsearch-2.4.0 폴더가 생긴것을 확인하고 이동한다.

편의를 위해 OPENSEARCH_HOME 변수를 선언한다.

cd opensearch-2.4.0
export OPENSEARCH_HOME=$(pwd)

이동하면 각 디렉토리가 보인다.

  • bin 폴더는 실행파일들의 위치
  • config 폴더는 설정 파일의 위치
  • data파일은 opensearch가 데이터를 저장하는 위치
  • jdk폴더는 내장 JDK
  • logs 폴더는 log 디렉토리
  • plugins는 plugin의 위치

 

OpenSearch가 사용하는 기본 포트

OpenSearch가 사용하는 포트들이 정해져있다.

  • 443 : OpenSearch Dashboards in AWS OpenSearch Service with encryption in transit (TLS)
  • 5601 : OpenSearch Dashboards
  • 9200 : OpenSearch REST API
  • 9250 : Cross-cluster search
  • 9300 : Node communication and transport
  • 9600 : Performance Analyzer

 

다음은 시스템 세팅이다.

이 과정들은 공식문서에도 적혀있다.

sudo swapoff -a

# Edit the sysctl config file
sudo vi /etc/sysctl.conf

# Add a line to define the desired value
# or change the value if the key exists,
# and then save your changes.
vm.max_map_count=262144

# Reload the kernel parameters using sysctl
sudo sysctl -p

# Verify that the change was applied by checking the value
cat /proc/sys/vm/max_map_count

 

vi $OPENSEARCH_HOME/config/opensearch.yml

위의 파일에서 아래 줄을 추가한다.

# Bind OpenSearch to the correct network interface. Use 0.0.0.0
# to include all available interfaces or specify an IP address
# assigned to a specific interface.
network.host: 0.0.0.0

# Unless you have already configured a cluster, you should set
# discovery.type to single-node, or the bootstrap checks will
# fail when you try to start the service.
discovery.type: single-node

# If you previously disabled the security plugin in opensearch.yml,
# be sure to re-enable it. Otherwise you can skip this setting.
# plugins.security.disabled: true

이제 JVM 설정단계이다.

vi $OPENSEARCH_HOME/config/jvm.options

위의 파일에서 아래처럼 JVM heap 사이즈를 변경한다.
내 서버는 ec2 micro로 열었기 때문에 128m로 작게 설정했다.
Xms와 Xmx로 최소사이즈와 최대 사이즈를 설정할 수 있는데 같게 설정하여 일정하게 유지하도록해 관리를 쉽게 할 수 있다.

-Xms128m
-Xmx128m

다시 편의를 위해 jdk위치 변수선언을 진행한다.

export OPENSEARCH_JAVA_HOME=$OPENSEARCH_HOME/jdk

 

Plugin

bin폴더 안에서 opensearch 플러그인을 설치 및 삭제할 수 있다.

# 리스트 출력
bin/opensearch-plugin list

# 설치
bin/opensearch-plugin install $plugin-name

# 삭제
bin/opensearch-plugin remove $plugin-name

 

실제로는 하면 안되지만 빠르게 진행하기 위해 security 관련 플러그인을 제거해 보안 과정을 건너뛰었다.

bin/opensearch-plugin remove opensearch-security
bin/opensearch-plugin remove opensearch-security-analytics

 

실행~~

실행은 아래 명령어로 한다.

./bin/opensearch

서버가 아닌 내 컴퓨터의 터미널에서 curl 명령어를 보내 openSearch가 제대로 작동중인지 확인할 수 있다.

curl -X GET http://$IP:9200
{
  "name" : $YOUR_HOSTNAME,
  "cluster_name" : "opensearch",
  "cluster_uuid" : "pS8BqBFcTiyQBr62148MxA",
  "version" : {
    "distribution" : "opensearch",
    "number" : "2.4.0",
    "build_type" : "tar",
    "build_hash" : "744ca260b892d119be8164f48d92b8810bd7801c",
    "build_date" : "2022-11-15T04:42:29.671309257Z",
    "build_snapshot" : false,
    "lucene_version" : "9.4.1",
    "minimum_wire_compatibility_version" : "7.10.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "The OpenSearch Project: https://opensearch.org/"
}

이런 메세지를 받게된다.

OpenSearch 마지막으로 
Systemctl로 system service로 등록해준다.

sudo vi /etc/systemd/system/opensearch.service

설정파일에 들어가 아래 내용을 넣어준다.
이때 $YOUR_OPENSEARCH_HOME 은 자기의 디렉토리로 변경해준다.

[Unit]
Description=OpenSearch
Wants=network-online.target
After=network-online.target

[Service]
Type=forking
RuntimeDirectory=data

WorkingDirectory=$YOUR_OPENSEARCH_HOME
ExecStart=$YOUR_OPENSEARCH_HOME/bin/opensearch -d

User=ubuntu
Group=ubuntu
StandardOutput=journal
StandardError=inherit
LimitNOFILE=65535
LimitNPROC=4096
LimitAS=infinity
LimitFSIZE=infinity
TimeoutStopSec=0
KillSignal=SIGTERM
KillMode=process
SendSIGKILL=no
SuccessExitStatus=143
TimeoutStartSec=75

[Install]
WantedBy=multi-user.target

수정 후 등록한다.

sudo systemctl daemon-reload

sudo systemctl enable opensearch.service

systemctl로 opensearch 시작한다.

sudo systemctl start opensearch.service

아래로 확인해볼 수 있다.

# 프로세스 확인
ps -ef | grep opensearch

# 로그 확인
tail -f $OPENSEARCH_HOME/logs/opensearch.log

Open Dashboard(Kibana) 설치

OpenSearch와 마찬가지로 
아래 링크에서 자신의 환경과 맞는 파일을 다운받고 압축해제한다.

https://opensearch.org/downloads.html

 

Opensearch 2.11.1

 

opensearch.org

동일하게 opensearch-dashboard 폴더로 이동 후 변수 선언한다.

cd opensearch-dashboards-2.4.0
export OPENSEARCH_DASHBOARDS_HOME=$(pwd)

이번에도 설정변경을 진행한다.

아래 파일로 들어가
내용을 변경해준다.

vi config/opensearch_dashboards.yml
server.host: $your_ec2_public_dnsname
server.port: 5601
opensearch.hosts: [http://localhost:9200]
opensearch.ssl.verificationMode: none
opensearch.username: kibanaserver
opensearch.password: kibanaserver
  # opensearch.requestHeadersWhitelist: [authorization, securitytenant]

  # opensearch_security.multitenancy.enabled: false
  # opensearch_security.multitenancy.tenants.preferred: [Private, Global]
  # opensearch_security.readonly_mode.roles: [kibana_read_only]
# Use this setting if you are running opensearch-dashboards without https
# opensearch_security.cookie.secure: false

* server.host에 꼭 aws 에서 확인한 자신의 public dns주소를 넣는다.

빠른 진행을 위해 이번에도 security 관련 설정을 지운다.

./bin/opensearch-dashboards-plugin remove securityAnalyticsDashboards
./bin/opensearch-dashboards-plugin remove securitytDashboards

실행!!

./bin/opensearch-dashboards

웹에서 내 public dns 주소 뒤에 5601포트로 접속한다. (~:5601)

이런 화면이 나오면 성공이다~~

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.