상세 컨텐츠

본문 제목

대용량 로그수십을 위한 Graylog 서버 설치방법 (무료버전)

카테고리 없음

by Keunwoo.LEE 2022. 10. 12. 14:40

본문

반응형

배경

어느 날 갑자기 일 200GB 이상의 로그를 수집해야 할 일이 생겼다.

ELK 스택을 테스트 용도로 사용하고 있었지만, 실제 로그를 검색해야 할 사용자에게 그 복잡한 Kibana를 설명해줄 시간적 여유도 없었고, 그 당시에는 Kibana가 계정권한 관리가 잘 안 되어 있어 아래와 같은 이유로 Graylog를 선택하게 되었다.

  • 사용하기 쉽다 : UI가 매우 쉽게 되어 있고 검색언어도 쉬움
  • 설치가 쉽다
  • 관리가 쉽다 : Sidecar를 이용하여 Filebeat 설정 배포가 매우 편리함

설치환경

OS : Centos 7.9 (Esxi VM)

CPU :16 Core

Memory : 32 GB

Disk : 1.5TB

Graylog 구성 요소

  • Graylog 4.0.7 : Open Source 무료 버전
  • Elasticsearch 7.10.2 : 검색엔진
  • MongoDB 4.2.14 : 환경 정보 및 메타정보 저장

Graylog 5 버전 설치는 아래 링크 참조

2023.04.05 - [분류 전체보기] - Graylog 5 설치 (with Opensearch 2.x)

 

Graylog 5 설치 (with Opensearch 2.x)

Graylog 5.0 Install (with Opensearch 2.x) Graylog 5.0 에서 달라진점 Opensearch 2.x를 지원함 > Elasticsearch가 7.10.2 이후 버전부터 License 정책을 변경하여 더이상 Elasticsearch를 이용한 유료 상품을 판매하기가 어렵

comarts.tistory.com

 

사전 요구 사항

  • openjdk 1.8 필요 -> Centos 7.9 기본 설치되어 있어 PASS!!
  • pwgen -> 관리자 password 암호시 필요
> yum install epel-release
> yum install pwgen

Default File Location

기본 파일 위치는 이렇게 기록해 두는게 나중에 유지보수 시 용이함

Configuration : /etc/graylog/server/server.conf
Logging : configuration /etc/graylog/server/log4j2.xml
Plugins : /usr/share/graylog-server/plugin
Binaries : /usr/share/graylog-server/bin
Scripts : /usr/share/graylog-server/scripts
JVM settings : /etc/sysconfig/graylog-server
Message journal files : /var/lib/graylog-server/journal
Log Files : /var/log/graylog-server/

MongoDB 설치

yum repo 파일 생성

> vi /etc/yum.repos.d/mongodb-org.repo

[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

MongoDB 설치

> yum install mongodb-org

서비스 등록

> systemctl daemon-reload
> systemctl enable mongod.service
> systemctl start mongod.service
> systemctl status mongod.service

Elasticsearch 설치

yum repo 설정

> rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

> vi /etc/yum.repos.d/elasticsearch.repo

[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

Elasticsearch 설치

> yum install elasticsearch-oss

설정파일 수정

> vi /etc/elasticsearch/elasticsearch.yml

# 파일 끝에 추가
cluster.name: graylog
action.auto_create_index: false

서비스 설정

> systemctl daemon-reload
> systemctl enable elasticsearch.service
> systemctl start elasticsearch.service
> systemctl status elasticsearch.service

Graylog 설치

yum repo 설정

> rpm -Uvh https://packages.graylog2.org/repo/packages/graylog-4.0-repository_latest.rpm

Graylog 설치

> yum install graylog-server

server.conf 설정

아래 명령어를 이용하여 server.conf의 패스워드 설정

> pwgen -N 1 -s 96 (password_secret)
> echo -n yourpassword | shasum -a 256 (root_password_sha2)

root_timezone 변경

root_timezone = Asia/Seoul

bind address 수정

http_bind_address = 0.0.0.0:9000

서비스 설정

> systemctl daemon-reload
> systemctl enable graylog-server.service
> systemctl start graylog-server.service
> systemctl status graylog-server.service

SELinux disable

> sestatus -v           # selinux 상태확인
> setenforce 0          # selinux disable
> sestatus -v           # selinux 상태확인

> vi /etc/selinux/config 
SELINUX=disabled        # 다음 부팅시에도 적용되도록 설정파일 수정

Firewalld 설정

  • 9000번 포트는 Graylog UI 접속을 위한 포트
  • 5044번 포트는 Filebeat를 통한 로그 수신용 포트
  • 514번 포트는 표준 syslog 수신을 위한 포트
    아래 설정에서는 514를 1514로 변경해주는 port forward 설정인데
    Graylog 계정이 일반 유저 계정이기 때문에 1024번 이하 포트는 설정할 수 없어 필요함
firewall-cmd --permanent --zone=public --add-port=9000/tcp
firewall-cmd --permanent --zone=public --add-port=5044/tcp
firewall-cmd --permanent --add-forward-port=port=514:proto=udp:toport=1514
systemctl reload firewalld.service

Graylog Input 설정

Filebeat

System -> Input -> Beats 선택 -> Launch new input 클릭

Title : Filebeat
Port : 5044

Syslog_UDP

System → Input → Syslog UDP → Launch new input 클릭

  • 위에서 514를 1514로 변경했기때문에 1514로 설정

Title : Syslog_UDP
Port : 1514

Sidecar 및 filebeat 설정 (Client)

Sidecar 설치

yum repo 설정 및 install

> rpm -Uvh https://packages.graylog2.org/repo/packages/graylog-sidecar-repository-1-2.noarch.rpm
> yum install graylog-sidecar

sidecar.yml 수정

token은 System -> Sidecars -> Overview 화면에서 생성

> vi /etc/graylog/sidecar/sidecar.yml
server_url: "http://10.10.10.47:9000/api/"
server_api_token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

서비스 등록 및 실행

> graylog-sidecar -service install
> systemctl start graylog-sidecar

Filebeat 설치

elasticsearch 사이트에서 filebeat.rpm download 후 설치

> yum install filebeat-7.11.1-x86_64.rpm

Graylog Sidecars 메뉴를 통한 log 수신 설정 

Create Configuration

System -> Sidecars -> Configuration -> Create Configuration 클릭

  • Name : filebeat-conf-xxx-xxx
  • Collector : filebeat on Linux
  • Configuration :

# Needed for Graylog
fields_under_root: true
fields.collector_node_id: ${sidecar.nodeName}
fields.gl2_source_collector: ${sidecar.nodeId}

filebeat.inputs:
- type: log
  enable: true
  paths:
    - /var/log/messages
    - /원하는/로그파일/등록

#- type: log
#  enable: true
#  paths:
#    - /xxx/xxx/xxxx
#  tail_files: true
#  ingnore_older: 10m

output.logstash:
   hosts: ["10.10.10.47:5044"]

path:
  data: /var/lib/graylog-sidecar/collectors/filebeat/data
  logs: /var/lib/graylog-sidecar/collectors/filebeat/log

Config 적용

  • System → Sidecars → Manage sidecar → filebeat 선택 -> configure 클릭 -> filebeat-conf 선택
  • System -> Input -> Filebeat -> Show received messages

성능 튜닝

위와 같이 기본 구성으로 설치할 경우 Heap Size는 아래와 같다

  • Elasticsearch Heap Size : 4GB
  • Graylog Heap Size : 1GB

기본 설정 상태로 사용하면 로그 수집량이 일 100GB 이상 수준이 되면 서버가 엄청 느려지게 된다.

필자는 시스템 메모리를 32GB로 늘리고 Heap Size는 아래와 같이 시스템 메모리의 50%를 할당했다.

나머지 50%는 Java에서 Cache로 사용해야 하기 때문에...

 Elasticsearch Heap Size 변경

> vi /etc/elasticsearch/jvm.options

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms12g
-Xmx12g

Graylog Heap Size 변경

> vi /etc/sysconfig/graylog-server

# Default Java options for heap and garbage collection.
GRAYLOG_SERVER_JAVA_OPTS="-Xms4g -Xmx4g -XX:NewRatio=1 -server -XX:+ResizeTLAB -XX:-OmitStackTraceInFastThrow"

 

참고 : Graylog 5 버전 설치 방법은 아래 포스팅을 참고하시기 바랍니다.

2023.04.05 - [분류 전체보기] - Graylog 5 설치 (with Opensearch 2.x)


 

 

반응형

댓글 영역