ウェブサイト検索

Let's Encrypt を使用して Graylog サーバーを Debian 11|10 にインストールする |


このガイドでは、Let's Encrypt SSL を使用して Debian 11|10 に Graylog サーバーをインストールする方法を詳しく説明します。ただし、このツールの核心に入る前に、それが何であるかを理解しましょう。 Graylog は、収集されたログの保存、分析、アラートの送信に使用される、無料でオープンなオープンソースのログ管理および集計ツールです。構造化データと非構造化データの両方の分析に使用できます。 Graylog は次のコンポーネントに基づいています。

  • Java /OpenJDK – ElasticSearch のランタイム環境として使用されます。
  • ElasticSearch – これは、Graylog サーバーのログ分析ツールです。
  • MongoDB – データと構成を保存します。
  • Graylog サーバー – 組み込み Web インターフェイスを使用して視覚化するためにログを渡すサーバーです。

セットアップ要件。

  1. 4GB以上のメモリ。
  2. 20GBを超えるストレージ。
  3. 4つのCPUコア
  4. Debian 10/11 がインストールされ、更新されました。
  5. すべてのパッケージがアップグレードされました。

上記の要件をすべて満たしたら、インストール プロセスに移りましょう。

ステップ 1: Debian 11|10 に Java をインストールする

Graylog のインストールでは、推奨される Java バージョンは Java 8 より上の任意のバージョンです。このガイドでは、Java OpenJDK 11 を使用します。以下のコマンドを使用して、Debian 11/10 に Java OpenJDK 11 をインストールします。

sudo apt update
sudo apt install -y apt-transport-https openjdk-11-jre-headless uuid-runtime pwgen curl dirmngr

インストールされている Java のバージョンを確認します。

$ java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2)
OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2, mixed mode, sharing)

ステップ 2: Debian 11|10 に ElasticSearch をインストールします。

ここでは、Elasticsearch を使用してログを保存し、RESTful Web インターフェイスでリアルタイム分析を提供します。

Graylog サーバーから送信されたデータを保存し、Web インターフェイスでユーザーの要求に応じてメッセージを表示します。

まず Elasticsearch GPG キーを追加しましょう。

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

次に、Debian 11/10 に Elasticsearch リポジトリを追加します。

echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list

リポジトリを追加したら、以下のようにElasticseachをインストールします。

sudo apt update
sudo apt install -y elasticsearch-oss

次に、YAML ファイルの構成を実行し、以下のようにクラスター名をgraylog に設定します。

sudo apt install vim
sudo vim /etc/elasticsearch/elasticsearch.yml

クラスター名を検索して設定し、以下の行を追加します。

cluster.name: graylog
action.auto_create_index: false

以下のように Elasticsearch サービスをリロードして開始します。

sudo systemctl daemon-reload
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch

サービスのステータスを確認します。

$ systemctl status elasticsearch
 elasticsearch.service - Elasticsearch
     Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-08-26 20:41:39 UTC; 2s ago
       Docs: https://www.elastic.co
   Main PID: 16515 (java)
      Tasks: 50 (limit: 4678)
     Memory: 1.1G
        CPU: 22.106s
     CGroup: /system.slice/elasticsearch.service
             └─16515 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -X>

Aug 26 20:41:28 logs.techwizpro.com systemd[1]: Starting Elasticsearch...
Aug 26 20:41:39 logs.techwizpro.com systemd[1]: Started Elasticsearch.

Elasticsearch の起動に失敗した場合は、利用可能な RAM に合わせて etc/elasticsearch/jvm.options を編集する必要があります。

sudo vim /etc/elasticsearch/jvm.options

RAM が 4GB 未満の場合は、ファイル内で以下のオプションを見つけて置き換えます。

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

次に、Elasticsearchを起動し、以下のように進みます。

デフォルトでは、Elasticsearch はポート 9200 で実行されます。以下の cURL コマンドを使用してこれを確認します。

curl -X GET http://localhost:9200

サンプル出力:

{
  "name" : "logs.techwizpro.com",
  "cluster_name" : "graylog",
  "cluster_uuid" : "BGPuR_1OQaOF_YWgvXDxeQ",
  "version" : {
    "number" : "7.10.2",
    "build_flavor" : "oss",
    "build_type" : "deb",
    "build_hash" : "747e1cc71def077253878a59143c1f785afa92b9",
    "build_date" : "2021-01-13T00:42:12.435326Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

ステップ 3: Debian 11|10 に MongoDB をインストールする

以下のようにリポジトリを追加してMongoDBをインストールします。

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
sudo apt update

以下のようにMongoDBリポジトリを追加します。

echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

以下のように MongoDB を更新してインストールします。

sudo apt-get update
sudo apt-get install -y mongodb-org mongodb-org-database mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools

次に、MongoDB サービスを起動し、起動時に実行できるようにします。

sudo systemctl start mongod
sudo systemctl enable mongod

サービスが実行されていることを確認します。

$ systemctl status mongod
 mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-08-26 10:52:37 UTC; 10s ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 22633 (mongod)
     Memory: 66.9M
        CPU: 715ms
     CGroup: /system.slice/mongod.service
             └─22633 /usr/bin/mongod --config /etc/mongod.conf

Aug 26 10:52:37 techwizpro.com systemd[1]: logs.techwizpro.com systemd[1]: Started MongoDB Database Server.

ステップ 4: Debian 11|10 に Graylog サーバーをインストールする

Graylog サーバーはマシン ログを受け入れて処理し、要求に応じて Web インターフェイスに表示します。

Graylog リポジトリ パッケージを Debian にダウンロードしてインストールします。

wget https://packages.graylog2.org/repo/packages/graylog-4.2-repository_latest.deb
sudo dpkg -i graylog-4.2-repository_latest.deb

キャッシュ リポジトリを更新し、Graylog サーバーをインストールします。

sudo apt update
sudo apt install -y graylog-server

次に、 pwgen コマンドを使用して、以下のようにユーザー パスワードを保護するためのシークレットを生成します。

pwgen -N 1 -s 96

出力:

98KM6k7W6CtfQPc0EFKS3EMsb3bgYK1qPwDZcNezkqx4usSOMZE1rbKtuHuRwllkzm37cAp5U07jD9Hv6hCybkk3vJdVlC38

以下のシークレットコードをコピーして使用してください。

.conf ファイルを編集します

sudo vim /etc/graylog/server/server.conf

ファイルに、次のようにシークレットを貼り付けます。

password_secret = 98KM6k7W6CtfQPc0EFKS3EMsb3bgYK1qPwDZcNezkqx4usSOMZE1rbKtuHuRwllkzm37cAp5U07jD9Hv6hCybkk3vJdVlC38

.conf ファイルに、以下の行も追加します。

rest_listen_uri = http://127.0.0.1:9000/api/
web_listen_uri = http://127.0.0.1:9000/

保存して終了。次に、管理者用の sha256 パスワードを作成します。作成されたパスワードは、Web インターフェイスへのログインに使用されます。

echo -n Str0ngPassw0rd | sha256sum

上記のコマンドで、「Str0ngPassw0rd」を任意のパスワードに置き換えます。または、以下のコマンドを使用してパスワードを設定することもできます。

$ echo -n "Enter Password: " && head -1 </dev/stdin | tr -d '\n' | sha256sum | cut -d" " -f1
Enter Password: Str0ngPassw0rd

出力は以下のようになります。

ab38eadaeb746599f2c1ee90f8267f31f467347462764a24d71ac1843ee77fe3

この出力をコピーして、以下の手順で使用します。

/etc/graylog/server/server.conf ファイルを次のように編集します。

sudo vim /etc/graylog/server/server.conf

ファイルに、以下のように root_password_sha2=”上記の出力” を追加します。

root_password_sha2 = ab38eadaeb746599f2c1ee90f8267f31f467347462764a24d71ac1843ee77fe3

これが完了すると、Graylog サーバーを使用できるようになります。以下のようにサービスを起動して有効にします。

sudo systemctl daemon-reload
sudo systemctl restart graylog-server
sudo systemctl enable graylog-server

以下のようにログを確認してください。

sudo tail -f /var/log/graylog-server/server.log

サーバーが正常に実行されている場合は、次のような出力が表示されるはずです。

................
021-08-26T12:44:31.839Z INFO  [ServerBootstrap] Graylog server up and running.
2021-08-26T12:44:31.839Z INFO  [ServiceManagerListener] Services are healthy
....................

サーバー IP とポートを使用して Graylog Web インターフェイスにアクセスする場合は、以下のように http_bind_address をパブリック ホスト名またはパブリック IP アドレスに設定します。

sudo vim /etc/graylog/server/server.conf

次に、以下の行を追加します。

http_bind_address = 0.0.0.0:9000

行った変更を適用するには、サービスを再起動します。

sudo systemctl restart graylog-server

これを完了すると、URL http://server_IP:9000 または http://hostname:9000 を使用して Graylog サーバー Web UI にアクセスできるようになります。

ステップ 5: Let’s Encrypt 証明書を使用して Graylog サーバーをセットアップする

この手順はオプションであり、以下の要件を満たした場合にのみ続行してください。

  • 完全修飾ドメイン名(FQDN)
  • Nginx
  • Let’sEncrypt 証明書

ここでは、HTTPS を使用して Graylog Web インターフェイスにアクセスできるように SSL を設定します。まず、以下のようにNginxをインストールして設定します。

sudo apt install nginx

ufw run を使用している場合は、ファイアウォールを構成します。

sudo ufw allow 'Nginx Full'

次に、以下のようにドメイン名で VirtualHost を作成します。

sudo vim /etc/nginx/sites-available/graylog.domain.com.conf

ファイル内に、以下の内容を適宜置き換えて追加します。

server {
  listen 80;
  server_name           logs.example.com;

  return 301            https://$host$request_uri;
  access_log            /var/log/nginx/graylog_access.log combined;
  error_log             /var/log/nginx/graylog_error.log;
}

ファイル内の logs.example.com を独自の FQDN に置き換えます。

/etc/nginx/sites-available/graylog.yourdomain.com.conf/etc/nginx/sites-enabled の間にシンボリック リンクを作成します。以下のようなです。

sudo ln -s /etc/nginx/sites-available/graylog.domain.com.conf /etc/nginx/sites-enabled/

作成したファイルの構文を確認します。

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

それでは、Debian 11/10 に certbot を使用して Let’sEncrypt をインストールしてみましょう

sudo apt install certbot python3-certbot-nginx

次に、以下のように Nginx 用の Certbot を実行します。

sudo certbot --nginx

出力:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): Enter Your Email Address

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
Account registered.

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: logs.techwizpro.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Requesting a certificate for logs.techwizpro.com
Performing the following challenges:
http-01 challenge for logs.techwizpro.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/graylog.domain.com.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/graylog.domain.com.conf
...............

これが成功すると、以下のようにおめでとうございます。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://logs.techwizpro.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Subscribe to the EFF mailing list (email: [email ).

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/logs.techwizpro.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/logs.techwizpro.com/privkey.pem
   Your certificate will expire on 2021-11-24. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again with the "certonly" option. To non-interactively
   renew *all* of your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

次に、同じ 9000 ポートで実行されている Graylog を提供する Nginx 上にリバース プロキシを構成します。これを行うには、前に作成した .conf ファイルを以下のように編集します。

sudo vim /etc/nginx/sites-available/graylog.domain.com.conf

ファイルに次のように場所セグメントを追加します。

  ..................................
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

location /
    {
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Server $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Graylog-Server-URL https://$server_name/;
      proxy_pass       http://127.0.0.1:9000;
    }
}

設定ファイルが以下のようになっていることを確認します。

$ sudo vim /etc/nginx/sites-available/graylog.yourdomain.com.conf
server {
  server_name           logs.example.com;

  return 301            https://$host$request_uri;
  access_log            /var/log/nginx/graylog_access.log combined;
  error_log             /var/log/nginx/graylog_error.log;
}
server {
    listen 80;
    root /var/www/html;       
     index index.html index.htm index.nginx-debian.html;
     server_name    logs.example.com;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/logs.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/logs.example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

location /
    {
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Server $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Graylog-Server-URL https://$server_name/;
      proxy_pass       http://127.0.0.1:9000;
    }
}

ファイルの構文を確認してください。

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

次に、Nginx サービスを再起動します。

sudo systemctl restart nginx

ステップ 6: Graylog Web インターフェイスにアクセスする

これで、HTTPS を使用して Graylog Web インターフェイスにアクセスするように設定されました。 URL https://logs.example.com を使用して、logs.computingforgeeks.com を FQDN に置き換えます。

デフォルトのユーザー名は admin で、パスワードは手順 4 で設定したものです。この場合、パスワードは「Passw0rd 」です。

これで、Graylog Web ダッシュボードの使用を開始する準備が整いました。ここにはログが視覚的に表示されます。

結論

これでこのガイドは終わりです。Let's Encrypt SSL を使用して Debian 11|10 に Graylog サーバーをインストールする方法を説明しました。一元化された場所からログを収集、インデックス付け、分析できるようになりました。これにより、異常なアクティビティの監視やアプリケーションのデバッグが容易になります。このガイドが興味を持っていただければ幸いです。

詳細については、このページをご覧ください。

  • CentOS 8/RHEL 8 上の Elasticsearch 7.x を使用して Graylog 4 をインストールする
  • Let’s Encrypt SSL を使用して Graylog Nginx プロキシを構成する
  • Let’s Encrypt SSL を使用して Graylog サーバーを Ubuntu にインストールする

関連記事: