Ubuntu 22.04 通过 Docker 启动 Graylog

安装 Docker 和 Docker-Compose

这里以 Ubuntu 22.04 举例,如果你和我的系统一样,那么可以照抄下面这个命令来快速安装 docker。如果不是,你也可以 点击这里 来跳转到 Docker 官网来实现安装。

bash 复制代码
#!/bin/bash
apt-get update
apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
echo | add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io

接下来需要安装 Docker-Compose

bash 复制代码
apt update
apt install docker-compose

将一些配置文件和数据文件映射到本地

bash 复制代码
mkdir -p /home/graylog/mongo_data && chmod -R +777 /home/graylog/mongo_data
mkdir -p /home/graylog/es_data && chmod -R +777 /home/graylog/es_data
mkdir -p /home/graylog/graylog_data && chmod -R +777 /home/graylog/graylog_data
mkdir -p /home/graylog/graylog_data/config
cd /home/graylog/graylog_data/config 
wget https://raw.githubusercontent.com/Graylog2/graylog-docker/4.2/config/graylog.conf
wget https://raw.githubusercontent.com/Graylog2/graylog-docker/4.2/config/log4j2.xml
chown -R 1100:1100 /home/graylog/graylog_data
cd /home/graylog

如果上面的文件下载(wget命令)不了,那么可以先通过别的手段下载下来,然后上传到服务器对应的位置即可。

修改 Graylog 配置文件

接下来执行 vim graylog.conf,内容改成下面这个

root_timezone = PRC
allow_highlighting = true

Graylog 密码生成

在 linux 系统下执行下面这个命令来生成 SHA-256 的密码

bash 复制代码
echo -n "my_password" | sha256sum

windows powershell 可以执行这个

powershell 复制代码
echo -n my_password | certutil -hashfile - SHA256

Docker Compose

修改下面配置中的 GRAYLOG_PASSWORD_SECRETGRAYLOG_ROOT_PASSWORD_SHA2

yml 复制代码
version: '3'
services:
  # MongoDB: https://hub.docker.com/_/mongo/
  mongodb:
    image: mongo:4.2
    volumes:
      - /home/graylog/mongo_data:/data/db
      - /etc/localtime:/etc/localtime:ro
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/timezone:ro
  # Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/7.10/docker.html
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2
    volumes:
      - /home/graylog/es_data:/usr/share/elasticsearch/data
      - /etc/localtime:/etc/localtime:ro
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/timezone:ro
    environment:
      - http.host=0.0.0.0
      - transport.host=localhost
      - network.host=0.0.0.0
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - TZ=Asia/Shanghai
    ulimits:
      memlock:
        soft: -1
        hard: -1
  # Graylog: https://hub.docker.com/r/graylog/graylog/
  graylog:
    image: graylog/graylog:4.2
    volumes:
      - /home/graylog/graylog_data:/usr/share/graylog/data
      - /etc/localtime:/etc/localtime:ro
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/timezone:ro
    environment:
      # 密码的盐,可以随机生成一个,至少需要 16 个字符
      - GRAYLOG_PASSWORD_SECRET=somepasswordpepper
      # 这里的 SHA-2 对应的密码原文为:admin,你需要修改它,命令就是上面的 SHA 密码生成部分
      - GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
      - GRAYLOG_HTTP_EXTERNAL_URI=http://127.0.0.1:9000/
      - TZ=Asia/Shanghai
    entrypoint: /usr/bin/tini -- wait-for-it elasticsearch:9200 --  /docker-entrypoint.sh
    links:
        - mongodb:mongo
        - elasticsearch
    restart: always
    depends_on:
      - mongodb
      - elasticsearch
    ports:
      # Graylog web interface and REST API
      - 9000:9000
      # Syslog TCP
      - 1514:1514
      # Syslog UDP
      - 1514:1514/udp
      # GELF TCP
      - 12201:12201
      # GELF UDP
      - 12201:12201/udp

执行下面这个命令就可以启动了,-d 代表后台启动,如果你想要在台前看一下启动的过程,那么你可以去掉这个参数。

bash 复制代码
docker-compose up -d

异常情况:

ubuntu 22.04 在执行 docker-compose up 的时候,可能会抛出如下错误,主要的原因是:
docker.errors.DockerException: Error while fetching server API version: HTTPConnection.request() got an unexpected keyword argument 'chunked'

完整报错如下:

root@graylog:/home/graylog# docker-compose up
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/docker/api/client.py", line 214, in _retrieve_server_version
    return self.version(api_version=False)["ApiVersion"]
  File "/usr/lib/python3/dist-packages/docker/api/daemon.py", line 181, in version
    return self._result(self._get(url), json=True)
  File "/usr/lib/python3/dist-packages/docker/utils/decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/docker/api/client.py", line 237, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
  File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
TypeError: HTTPConnection.request() got an unexpected keyword argument 'chunked'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/docker-compose", line 33, in <module>
    sys.exit(load_entry_point('docker-compose==1.29.2', 'console_scripts', 'docker-compose')())
  File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 81, in main
    command_func()
  File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 200, in perform_command
    project = project_from_options('.', options)
  File "/usr/lib/python3/dist-packages/compose/cli/command.py", line 60, in project_from_options
    return get_project(
  File "/usr/lib/python3/dist-packages/compose/cli/command.py", line 152, in get_project
    client = get_client(
  File "/usr/lib/python3/dist-packages/compose/cli/docker_client.py", line 41, in get_client
    client = docker_client(
  File "/usr/lib/python3/dist-packages/compose/cli/docker_client.py", line 170, in docker_client
    client = APIClient(use_ssh_client=not use_paramiko_ssh, **kwargs)
  File "/usr/lib/python3/dist-packages/docker/api/client.py", line 197, in __init__
    self._version = self._retrieve_server_version()
  File "/usr/lib/python3/dist-packages/docker/api/client.py", line 221, in _retrieve_server_version
    raise DockerException(
docker.errors.DockerException: Error while fetching server API version: HTTPConnection.request() got an unexpected keyword argument 'chunked'

这个错误是 python 的 request 包的版本不正确导致的,你可以执行下面这个命令来查看你本地的 request 包的版本

bash 复制代码
pip list |grep request
> requests 2.31.0

接下来只要安装一个合适的版本即可:

bash 复制代码
pip install requests==2.28.0
相关推荐
追风林4 小时前
mac 本地docker-mysql主从复制部署
mysql·macos·docker
城南vision6 小时前
Docker学习—Docker核心概念总结
java·学习·docker
wclass-zhengge6 小时前
Docker篇(Docker Compose)
运维·docker·容器
wowocpp8 小时前
ubuntu 22.04 server 安装 anaconda3
linux·运维·ubuntu
梦魇梦狸º10 小时前
腾讯轻量云服务器docker拉取不到镜像的问题:拉取超时
docker·容器·github
鬼才血脉10 小时前
docker+mysql配置
mysql·adb·docker
詹姆斯爱研究Java10 小时前
Docker 的基本概念和优势
docker
wowocpp10 小时前
ubuntu 22.04 防火墙 ufw
linux·运维·ubuntu
南猿北者12 小时前
docker镜像仓库常用命令
运维·docker·容器
杨浦老苏12 小时前
Docker可视化管理面板DPanel的安装
运维·docker·群晖