Основы компьютерных сетей #18 — Как настроить Syslog сервер в Linux и Cisco IOS. Настраиваем Graylog

Представьте, что в вашей сети, больше 100 устройств — маршрутизаторов, коммутаторов и т.д. Как отследить проблемы на них? Зайти на сам девайс и посмотреть. Верно, но в огромной, корпоративной сети, абсолютно неудобно.

Лучше хранить логи в одном месте, с удобным интерфейсом, через который их можно отфильтровать и выбрать то, что интересует нас в данный момент.

В этом нам поможет Syslog

На сервере у нас стоит Ubuntu Server 22

Установим Syslog сервер в docker

sudo timedatectl set-timezone Europe/Moscow 
date
Sun Feb 4 04:22:48 PM MSK 2024
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

sudo apt  install docker-compose

sudo docker run hello-world

Теперь установим Graylog с помощью docker compose

sudo nano .env

# You MUST set a secret to secure/pepper the stored user passwords here. Use at least 64 characters.
# Generate one by using for example: pwgen -N 1 -s 96
# ATTENTION: This value must be the same on all Graylog nodes in the cluster.
# Changing this value after installation will render all user sessions and encrypted values in the database invalid. (e.g. encrypted access tokens)
GRAYLOG_PASSWORD_SECRET="n7czrJMbV7rhjzdCBopl8JutsWnRvooNhiisFGeV46mUOwixLyhCEL38bDxxYjDbDWHIZuG53osnjzU5xV6fW7o3CgdBIv5u"

# You MUST specify a hash password for the root user (which you only need to initially set up the
# system and in case you lose connectivity to your authentication backend)
# This password cannot be changed using the API or via the web interface. If you need to change it,
# modify it in this file.
# Create one by using for example: echo -n yourpassword | shasum -a 256
# and put the resulting hash value into the following line
# CHANGE THIS!
GRAYLOG_ROOT_PASSWORD_SHA2="ef67cef19063bfdd7049450d85625a7ce052867b4146b1787bbb98b74170e9fd"

processbuffer_processors = 8
outputbuffer_processors = 3
processor_wait_strategy = blocking
ring_size = 65536
inputbuffer_ring_size = 65536
inputbuffer_processors = 2
inputbuffer_wait_strategy = blocking
message_journal_max_age = 12h
elasticsearch_max_time_per_index = 3d
retention_strategy = delete

Сгенерируем пароль и добавим его в GRAYLOG_PASSWORD_SECRET

sudo apt install pwgen

pwgen -N 1 -s 96

Затем

echo -n n7czrJMbV7rhjzdCBopl8JutsWnRvooNhiisFGeV46mUOwixLyhCEL38bDxxYjDbDWHIZuG53osnjzU5xV6fW7o3CgdBIv5u | shasum -a 256

И добавляем, то что получилось в GRAYLOG_ROOT_PASSWORD_SHA2

Далее

sudo nano docker-compose.yaml

version: "3.8"

services:
  mongodb:
    image: "mongo:5.0"
    volumes:
      - "mongodb_data:/data/db"
    restart: "on-failure"

  opensearch:
    image: "opensearchproject/opensearch:2.4.0"
    environment:
      - "OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g"
      - "bootstrap.memory_lock=true"
      - "discovery.type=single-node"
      - "action.auto_create_index=false"
      - "plugins.security.ssl.http.enabled=false"
      - "plugins.security.disabled=true"
    ulimits:
      memlock:
        hard: -1
        soft: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - "os_data:/usr/share/opensearch/data"
    restart: "on-failure"

  graylog:
    hostname: "server"
    image: "${GRAYLOG_IMAGE:-graylog/graylog:5.1.5}"
    depends_on:
      opensearch:
        condition: "service_started"
      mongodb:
        condition: "service_started"
    entrypoint: "/usr/bin/tini -- wait-for-it opensearch:9200 --  /docker-entrypoint.sh"
    environment:
      GRAYLOG_NODE_ID_FILE: "/usr/share/graylog/data/config/node-id"
      GRAYLOG_PASSWORD_SECRET: "${GRAYLOG_PASSWORD_SECRET:?Please configure GRAYLOG_PASSWORD_SECRET in the .env file}"
      GRAYLOG_ROOT_PASSWORD_SHA2: "${GRAYLOG_ROOT_PASSWORD_SHA2:?Please configure GRAYLOG_ROOT_PASSWORD_SHA2 in the .env file}"
      GRAYLOG_HTTP_BIND_ADDRESS: "0.0.0.0:9000"
      GRAYLOG_HTTP_EXTERNAL_URI: "http://localhost:9000/"
      GRAYLOG_ELASTICSEARCH_HOSTS: "http://opensearch:9200"
      GRAYLOG_MONGODB_URI: "mongodb://mongodb:27017/graylog"
    ports:
    - "5044:5044/tcp"   # Beats
    - "5140:5140/udp"   # Syslog
    - "5140:5140/tcp"   # Syslog
    - "5555:5555/tcp"   # RAW TCP
    - "5555:5555/udp"   # RAW TCP
    - "9000:9000/tcp"   # Server API
    - "12201:12201/tcp" # GELF TCP
    - "12201:12201/udp" # GELF UDP
    #- "10000:10000/tcp" # Custom TCP port
    #- "10000:10000/udp" # Custom UDP port
    - "13301:13301/tcp" # Forwarder data
    - "13302:13302/tcp" # Forwarder config
    volumes:
      - "graylog_data:/usr/share/graylog/data/data"
      - "graylog_journal:/usr/share/graylog/data/journal"
    restart: "on-failure"

volumes:
  mongodb_data:
  os_data:
  graylog_data:
  graylog_journal:

Запускаем

sudo docker-compose up -d

Ждем пока все выполнится и проверяем

sudo docker-compose ps

Далее переходим http://ip_address:9000

Логинимся admin и ваш пароль (строка GRAYLOG_PASSWORD_SECRET)

Создадим input listener

System — Inputs — Syslog UDP — Launch new input

Задаем ему название, например cisco и задаем порт — 5140 (смотрите, чтобы порт был прокинут в docker). Внизу нажимаем — Launch Input

Проверяем, чтобы наш local input перешел в состояние RUNNING

Теперь настроим маршрутизатор

Для разнообразия в этой лабораторной мы получим ip адреса по dhcp. Представим, что где-то в LAN у нас стоит dhcp сервер.

R1

conf t
int e0/0
ip address dhcp
no shutdown
exit
exit
sh ip int brief
conf t
ntp server 194.190.168.1
clock timezone MSK 3
exit
sh clock
16:07:07.330 MSK Sun Feb 4 2024
sh ntp status
Clock is synchronized, stratum 2, reference is 194.190.168.1
conf t
logging host 192.168.6.234 transport udp port 5140 // вы можете встретить настройку просто через logging 192.168.10.10, но в нашем случае нам еще нужно указать другой порт
logging trap debugging
exit
wr mem

sh logging | include changed state to up

Далее посмотрим на Syslog сервере