banner
LegalGeek

LegalGeek

搞产品的法律人

M1チップのMacBook ProにELKをインストールする

要約:M1 チップに適した elasticsearch、kibana、logstash をインストールし、メモリ使用量を最適化し、アクセスパスワードを設定します。

elasticsearch のインストール#

brew を使用して M1 チップに適した elasticsearch をインストールします。

# brew tap elastic/tap

brew install elastic/tap/elasticsearch-full

インストール成功後、使用ヘルプが表示されます:

# インストールログ
==> Installing elasticsearch-full from elastic/tap
Warning: Tried to install empty array to /opt/homebrew/etc/elasticsearch/jvm.options.d
==> codesign -f -s - /opt/homebrew/Cellar/elasticsearch-full/7.17.1/libexec/modules/x-pack
==> find /opt/homebrew/Cellar/elasticsearch-full/7.17.1/libexec/jdk.app/Contents/Home/bin
==> Caveats

# 関連インストールファイルの位置
Data:    /opt/homebrew/var/lib/elasticsearch/elasticsearch_zhangminglei/
Logs:    /opt/homebrew/var/log/elasticsearch/elasticsearch_zhangminglei.log
Plugins: /opt/homebrew/var/elasticsearch/plugins/
Config:  /opt/homebrew/etc/elasticsearch/

# バックグラウンドで実行し、起動時に自動的に開始
  brew services start elastic/tap/elasticsearch-full

# 現在のコマンドラインで実行し、ターミナルを閉じるとサービスが停止
  elasticsearch

バックグラウンドサービスを起動します:

brew services start elastic/tap/elasticsearch-full

実行後、ブラウザでhttp://localhost:9200 / にアクセスし、以下の応答内容が表示されます:

// 20220315232052
// http://localhost:9200/

{
  "name": "LegalgesMacBook.lan",
  "cluster_name": "elasticsearch_zhangminglei",
  "cluster_uuid": "fB4xhSO1TrO0yh1I4h7qaw",
  "version": {
    "number": "7.17.1",
    "build_flavor": "default",
    "build_type": "tar",
    "build_hash": "e5acb99f822233d62d6444ce45a4543dc1c8059a",
    "build_date": "2022-02-23T22:20:54.153567231Z",
    "build_snapshot": false,
    "lucene_version": "8.11.1",
    "minimum_wire_compatibility_version": "6.8.0",
    "minimum_index_compatibility_version": "6.0.0-beta1"
  },
  "tagline": "You Know, for Search"
}

kibana のインストール#

brew を使用して M1 チップに適した kibana をインストールします。

# brew tap elastic/tap

brew install elastic/tap/kibana-full

インストール成功後のメッセージ:

# インストールプロセスログ
==> Installing kibana-full from elastic/tap
==> Caveats
Config: /opt/homebrew/etc/kibana/
アップグレード時にプラグインを保持したい場合は、アップグレード前に
/opt/homebrew/opt/kibana-full/pluginsのコピーを作成し、アップグレード後に新しいケグの場所にコピーしてください。

# バックグラウンドで実行し、起動時に自動的に開始
今すぐelastic/tap/kibana-fullを開始し、ログイン時に再起動するには:
  brew services start elastic/tap/kibana-full

# 現在のコマンドラインで実行し、ターミナルを閉じるとサービスが停止
または、バックグラウンドサービスが不要な場合は、次のように実行できます:
  kibana

# インストール結果の要約
==> Summary
🍺  /opt/homebrew/Cellar/kibana-full/7.17.1: 51,438 files, 720MB, built in 30 seconds
==> Running `brew cleanup kibana-full`...
この動作を無効にするにはHOMEBREW_NO_INSTALL_CLEANUPを設定します。
これらのヒントを非表示にするにはHOMEBREW_NO_ENV_HINTSを設定します(`man brew`を参照)。

バックグラウンドサービスを起動します:

brew services start elastic/tap/kibana-full

ブラウザでhttp://localhost:5601 / にアクセスし、実行インターフェースの状況を確認し、システムインターフェースを日本語に変更します:

# 設定ファイルディレクトリに移動
cd /opt/homebrew/etc/kibana/

# 設定ファイルを編集
nano kibana.yml

# 最後の行を次のように変更:
i18n.locale: "ja-JP"

brew サービスを再起動します:

brew services restart elastic/tap/kibana-full

システムメモリ使用量の調整#

ES サービスはデフォルトでシステムの半分以上のメモリを使用します。設定ファイルを変更することで制限できます:

必要な変更ファイルはサービス設定パスにあります:/opt/homebrew/etc/elasticsearch/

必要な変更ファイル:jvm.options

変更前:

## jvm.options.dディレクトリに含まれるこれらの行:
##
## -Xms4g
## -Xmx4g
##

変更後:

## jvm.options.dディレクトリに含まれるこれらの行:
##
-Xms4g
-Xmx4g
##

ES サービスを再起動すると、システムの【アクティビティモニター】で java メモリ使用量が制限されているのが確認できます:

brew services restart elastic/tap/elasticsearch-full

パスワード保護の設定#

注:公式ドキュメントを参照できます:https://www.elastic.co/guide/en/elasticsearch/reference/7.17/security-minimal-setup.html

  • ステップ 1:実行中の elasticsearch、kibana の 2 つのサービスを停止します。

  • ステップ 2:elasticsearch.yml ファイルを変更し、パスワード保護を有効にし、単一ノードに設定します。

# 設定ファイルフォルダに入る
/opt/homebrew/etc/elasticsearch/

# 設定ファイルを編集
elasticsearch.yml

# ファイルの末尾に次の2行を追加:
xpack.security.enabled: true
discovery.type: single-node

  • ステップ 3: elasticsearch の組み込みツールを使用してアカウントとパスワードを自動生成します。
#1 elasticsearchサービスを起動:
brew services start elastic/tap/elasticsearch-full

#2 es実行可能ファイルディレクトリに入る:
/opt/homebrew/Cellar/elasticsearch-full/7.17.1/bin

#3 上記のディレクトリでターミナルを開き、自動生成パスワードコマンドを実行:
./elasticsearch-setup-passwords auto

#4 コンソール出力のアカウントパスワード内容を記録します。後で使用します。
生成されたアカウントパスワードの例:
Changed password for user kibana_system
PASSWORD kibana_system = n9zXw2UnJwvWdrJ4ZPcg

Changed password for user elastic
PASSWORD elastic = Lhder7yQVB8z3rzdFoKY

  • ステップ 4: 上記の自動生成されたアカウントパスワードを Kibana に設定し、es にアクセスできるようにします。
#1 Kibana設定ファイルディレクトリに入る:
/opt/homebrew/etc/kibana/

#2 Kibana設定ファイルを変更し、内容を追加:
elasticsearch.username: "kibana_system"

#3 Kibana実行可能ファイルディレクトリに入る:
/opt/homebrew/Cellar/kibana-full/7.17.1/bin

#4 上記のディレクトリでターミナルを開き、順に実行:
    ./kibana-keystore create
    ./kibana-keystore add elasticsearch.password
    上記で生成されたkibana_systemパスワードを入力

#5 Kibanaサービスを再起動:
brew services start elastic/tap/kibana-full
  • ステップ 5: 上記の自動生成された elastic アカウントパスワードを使用して kibana にログインします。
アドレス: http://localhost:5601/
アカウント: elastic
パスワード: Lhder8yQVB8z3rzdFoKY

* kibana内でパスワードを変更できます

logstash のインストール#

brew を使用して M1 チップに適した logstash をインストールします:

# brew tap elastic/tap

brew install elastic/tap/logstash-full

インストール成功ログ:

Getting started guideをお読みください:
  https://www.elastic.co/guide/en/logstash/current/getting-started-with-logstash.html

今すぐelastic/tap/logstash-fullを開始し、ログイン時に再起動するには:
  brew services start elastic/tap/logstash-full
または、バックグラウンドサービスが不要な場合は、次のように実行できます:
  logstash
==> Summary
🍺  /opt/homebrew/Cellar/logstash-full/7.17.1: 14,003 files, 604.8MB, built in 13 seconds
==> Running `brew cleanup logstash-full`...
この動作を無効にするにはHOMEBREW_NO_INSTALL_CLEANUPを設定します。

logstash.yml にユーザー名とパスワードを設定します:

パス:/opt/homebrew/etc/logstash

xpack.monitoring.enabled: true

xpack.monitoring.elasticsearch.username: logstash_system

xpack.monitoring.elasticsearch.password: *****

xpack.monitoring.elasticsearch.hosts: ["http://127.0.0.1:9200"]

サービスを起動します:

brew services start elastic/tap/logstash-full

インストール成功を確認します:

# logstashディレクトリに入る
cd /opt/homebrew/Cellar/logstash-full/7.17.1/bin

# 次のコマンドを実行し、入力カーソルが表示されるのを待ちます
bin/logstash -e 'input { stdin { } } output { stdout { } }'

# helloと入力するとシステムのフィードバック:
{
      "@version" => "1",
       "message" => "hello",
    "@timestamp" => 2022-05-29T06:28:37.021Z,
          "host" => "izwz9cte3psk7ixd8kospzz"
}

パイプ構成ファイルを作成して使用します:
Logstash 管理には通常、1 つ以上の input、filter、output プラグインがあります。例えば:

//hello.conf

input { stdin { } }
output {
    elasticsearch {
     hosts => "http://127.0.0.1:9200"
     index => "logs"
     user => "elastic"
     password => "************"
   }
  stdout {}
  }

パイプを使用します:

# 実行
logstash -f hello.conf

# 入力:
hello world

# フィードバック:
{
          "host" => "Legalgeeks-MacBook.local",
    "@timestamp" => 2022-03-20T05:50:48.988Z,
      "@version" => "1",
       "message" => "hello world"
}

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。