ウェブサイト検索

Let's Encrypt を使用して Graylog 4 を Ubuntu 22.04|20.04 にインストールする |


Graylog は、収集されたログの保存、分析、アラートの送信に使用できるオープンソースのログ集約および管理ツールです。 Graylog は、ElasticSearch と MongoDB を使用して構造化ログと非構造化ログの両方を分析するために使用できます。これには、Windows システム、Linux システム、さまざまなアプリケーションやマイクロサービスなど、さまざまなシステムが含まれます。

Graylog を使用すると、これらのシステムとアプリケーションを単一のホストから簡単に分析および監視できるようになります。

Graylog には次のコンポーネントがあります。

  • グレイログサーバー
  • モンゴDB
  • 弾性検索

早速、Ubuntu 22.04|20.04 ホストへの Graylog サーバーのインストールに移りましょう。次に、Let’sEncrypt を使用して SSL を設定します。

これを実現するには、システム上でリバース プロキシとして機能する Nginx をインストールする必要があります。

類似の記事: Promtail を使用してログを Grafana Loki に転送する方法

セットアップの前提条件

ボックスにインストールする前に、ホストが以下の最小要件を満たしていることを確認してください。

  • 4 CPU コア
  • 8 GB RAM
  • Elasticsearch ログ ストレージ向けの高 IOPS を備えた SSD ハードディスク容量
  • Ubuntu 22.04|20.04 LTS がインストールされ、更新されました。
  • すべてのパッケージがアップグレードされました

上記の条件が満たされたら、インストールプロセスを開始しましょう。

ステップ 1 – Ubuntu 22.04|20.04 に Java をインストールする

Java をインストールする前に、システムを更新してアップグレードしましょう。

sudo apt update && sudo apt -y full-upgrade

アップグレード後にシステムを再起動することを強くお勧めします。

[ -f /var/run/reboot-required ] && sudo reboot -f

Graylog のインストールには Java バージョン 8 以降が必要です。この投稿では、オープン JDK 11 を使用します。

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

java -version コマンドを使用して、インストールしたばかりの Java バージョンを確認できます。

$ java -version
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1, mixed mode, sharing)

ステップ 2 – Ubuntu 22.04|20.04 に Elasticsearch をインストールする

エラスティック検索は、外部ソースから受信したログを保存および分析するために使用されるツールです。 Web ベースの RESTful API を使用します。

Elasticsearch GPG 署名キーをダウンロードしてインストールします。

curl  -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/elastic.gpg

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

Elasticsearch をインストールします。

sudo apt update
sudo apt install elasticsearch-oss -y

Graylog のクラスター名を構成します。

sudo vim /etc/elasticsearch/elasticsearch.yml

クラスター名を graylog に編集します。

cluster.name: graylog

同じファイルに次の情報を追加します

action.auto_create_index: false

開始 Elasticsearch サービスのデーモンをリロードします。

sudo systemctl daemon-reload
sudo systemctl restart 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 Sun 2020-11-08 12:36:10 UTC; 14s ago
       Docs: http://www.elastic.co
   Main PID: 1352139 (java)
      Tasks: 15 (limit: 4582)
     Memory: 1.1G
     CGroup: /system.slice/elasticsearch.service
             └─1352139 /bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.>

Nov 08 12:36:10 graylog.computingforgeeks.com systemd[1]: Started Elasticsearch.

Elasticsearch はポート 9200 で実行され、これは curl コマンドで確認できます。

curl -X GET http://localhost:9200

出力にクラスター名が表示されるはずです。

$ curl -X GET http://localhost:9200
{
  "name" : "ubuntu",
  "cluster_name" : "graylog",
  "cluster_uuid" : "RsPmdLmDQUmNGKC-E4JPmQ",
  "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 – MongoDB を Ubuntu 22.04|20.04 にインストールする

まず、MongoDB 6.0 GPG キーをシステムにインポートします。

curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mongodb-6.gpg

MongoDB 6.0 リポジトリをシステムに追加します。

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

Ubuntu のベース リポジトリから mongoDB をダウンロードしてインストールします。

sudo apt update && sudo apt install mongodb-org -y

MongoDBを起動する

sudo systemctl start mongod
sudo systemctl enable mongod
$ systemctl status mongod
 mongodb.service - An object/document-oriented database
     Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-11-08 12:45:21 UTC; 1s ago
       Docs: man:mongod(1)
   Main PID: 1352931 (mongod)
      Tasks: 3 (limit: 4582)
     Memory: 27.9M
     CGroup: /system.slice/mongodb.service
             └─1352931 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf

Nov 08 12:45:21 graylog.computingforgeeks.com systemd[1]: Started An object/document-oriented database.

ステップ 4 – Ubuntu 22.04|20.04 に Graylog サーバーをインストールする

Graylog リポジトリをダウンロードして構成します。

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

Graylog サーバーをインストールします。

sudo apt update
sudo apt install graylog-server

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

pwgen -N 1 -s 96

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

FFP3LhcsuSTMgfRvOx0JPcpDomJtrxovlSrbfMBG19owc13T8PZbYnH0nxyIfrTb0ANwCfH98uC8LPKFb6ZEAi55CvuZ2Aum

Graylog 構成ファイルを編集して、作成したばかりのシークレットを追加します。

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

password_secret = 行を見つけて、その後ろに上記で作成したシークレットを追加します。

password_secret = FFP3LhcsuSTMgfRvOx0JPcpDomJtrxovlSrbfMBG19owc13T8PZbYnH0nxyIfrTb0ANwCfH98uC8LPKFb6ZEAi55CvuZ2Aum

サーバー IP アドレスとポートを使用して Graylog インターフェースを使用する場合は、http_bind_address を、接続できるマシンのパブリック ホスト名またはパブリック IP アドレスに設定します。

$ sudo vim /etc/graylog/server/server.conf
http_bind_address = 0.0.0.0:9000

次のステップでは、管理者用のハッシュ sha256 パスワードを作成します。これは、Web インターフェイスにログインするために必要なパスワードです。

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

次のような出力が得られます。

e3c652f0ba0b4801205814f8b6bc49672c4c74e25b497770bb89b22cdeb4e951

/etc/graylog/server/server.conf ファイルを編集し、ハッシュ パスワードを root_password_sha2 = に配置します。

$ sudo vim /etc/graylog/server/server.conf
root_password_sha2 = e3c652f0ba0b4801205814f8b6bc49672c4c74e25b497770bb89b22cdeb4e951

Graylog が設定され、使用できるようになりました。

Graylog サービスを開始します:

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

サービスが正常に開始されたかどうかは、ログから確認できます。

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

出力:

2020-11-08T13:37:55.067Z INFO  [ServerBootstrap] Graylog server up and running.

これで、次の場所で Graylog Web ダッシュボードにアクセスできるようになります。

http://<serverip_hostname>:9000

ステップ 5 – GrayLog 用に Let's Encrypt を使用して Nginx を構成する

次のステップは、HTTPS 経由で Graylog Web インターフェイスにアクセスできるように SSL を設定することです。

これを達成するには、次のものが必要です。

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

以下のガイドの手順に従ってください。

  • Let's Encrypt SSL を使用して Graylog Nginx プロキシを構成する

簡単に参照できるように、手順を以下に示します。

  1. システムを更新してnginxをインストールする
sudo apt update
sudo apt install nginx

2. ファイアウォールを構成する

sudo ufw allow 'Nginx Full'

3. ドメイン名を使用して仮想ホストを作成します

/etc/nginx/sites-available/ にファイルを作成します。例:

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

ファイルに次の内容を追加します。

server {
  listen 80;
  server_name           graylog.yourdomain.com;

  return 301            https://$host$request_uri;
  access_log            /var/log/nginx/graylog.yourdomain.com.access.log combined;
  error_log             /var/log/nginx/graylog.yourdomain.com.error.log;
}

graylog.yourdomain.com を FQDN に置き換えてください。

4. /etc/nginx/sites-available に作成したファイルのシンボリックリンクを /etc/nginx/sites-enabled に作成します。

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

5. nginx -t コマンドを実行して、nginx の設定が正しいかどうかを確認します。

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

6. certbot を使用して Let’sEncrypt をインストールします。

sudo apt install certbot python3-certbot-nginx

7. 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): [email 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing 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: N
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: graylog.computingforgeeks.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
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for graylog.computingforgeeks.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/graylog.computingforgeeks.com.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/graylog.computingforgeeks.com.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled
https://graylog.computingforgeeks.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=graylog.computingforgeeks.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/graylog.computingforgeeks.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/graylog.computingforgeeks.com/privkey.pem
   Your cert will expire on 2021-02-06. 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"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

弊社ドメインのSSLを正常に取得しました。

次のステップは、同じホストのポート 9000 で実行されている Graylog を提供するために使用されるリバース プロキシを Nginx 上に構成することです。

/etc/nginx/sites-available/graylog.conf ファイルを編集します。

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

そして、Location セクションに次の設定を追加します。

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;
    }

最終的な構成ファイルは次のようになります。

server {
  listen 80;
  server_name           graylog.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 {

        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;
        server_name graylog.example.com;


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/graylog.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/graylog.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;
    }
}

nginx -t を使用して nginx 構成を検証し、nginx 構成が適切であることを確認します。

ここでnginxサービスを再起動します。

sudo systemctl restart nginx

上記を実行すると、https://graylog.yourdomain.com と入力して、graylog ダッシュボードにアクセスできるようになります。

graylog.yourdomain.com を FQDN に忘れずに置き換えてください。

Graylog のデフォルトのユーザー名は admin で、パスワードは上記の手順 4 (Graylog サーバーのインストール) で設定したものです。私の場合、これは「Str0ngPassw0rd」になります。

これで、SSL が設定された Graylog Web ダッシュボードの使用を開始できるようになります。

結論

Graylog サーバーを正常にインストールし、Nginx を介してリバース プロキシとして SSL を構成し、Web インターフェイスにログインすることができました。

Graylog サーバーで SSL を構成することは、システムを保護するために重要です。

セットアップ プロセス中に問題に直面した場合は、お気軽にコメント欄にコメントしたり、質問したりしてください。

  • Letsencrypt SSL を使用して Graylog Nginx リバース プロキシを構成する

関連記事: