
主に検証を目的にOpenSearchをコンテナで動かす際の自分用メモ。
構築手順
adminパスワードを設定
環境変数OPENSEARCH_INITIAL_ADMIN_PASSWORDか.envファイルに設定。
export OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password>
OpenSearchのデフォルトのパスワードポリシーは以下の通り。
- パスワードの最小文字数: 8文字
- パスワードの最大文字数: 100文字
- 特殊文字、数字、大文字の使用は必須ではない
- パスワードは
zxcvbnエントロピーベースの計算でstrong(強力)と評価される必要がある
zxcvbnはDropboxが開発したエントロピーベースでパスワードの複雑性を評価するライブラリ。固定のルールベースではない。
ドキュメントより、ポイントは以下の通り。
ルールだけでなく、エントロピーに注目する: 数字や特殊文字を追加するだけでなく、全体的な予測不可能性を優先しましょう。ランダムな単語や文字で構成された長いパスワードは、従来の複雑性ルールを満たす短いパスワードよりも高いエントロピーを提供し、より安全です。
一般的なパターンや辞書の単語を避ける:
zxcvbnライブラリは、よく使われる単語、日付、連続文字(例:1234やqwerty)、さらには予測可能な文字置換(例:Eの代わりに3)も検出します。強固なセキュリティを確保するため、パスワードにこれらのパターンを使用しないようにしましょう。長さが重要: 一般的に、長いパスワードほど高いセキュリティを提供します。例えば、
correct horse battery stapleのようなパスフレーズは、特殊文字や数字を含んでいなくても、その長さとランダム性により強力だと考えられています。予測不可能性が鍵: ランダムな文字列を選ぶか、関連性のない単語で構成されたパスフレーズを選ぶかにかかわらず、パスワードセキュリティの鍵は予測不可能性です。高いエントロピーは必要な推測回数を大幅に増やし、パスワードを攻撃に対してより耐性のあるものにします。
パスワードポリシーは設定から変更可能。
docker-composeファイルを作成
公式のサンプルを元に要件に合わせて作成する。
services: opensearch-node1: # This is also the hostname of the container within the Docker network (i.e. https://opensearch-node1/) image: opensearchproject/opensearch:latest # Specifying the latest available image - modify if you want a specific version container_name: opensearch-node1 environment: - cluster.name=opensearch-cluster # Name the cluster - node.name=opensearch-node1 # Name the node that will run in this container - discovery.seed_hosts=opensearch-node1,opensearch-node2 # Nodes to look for when discovering the cluster - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 # Nodes eligible to serve as cluster manager - bootstrap.memory_lock=true # Disable JVM heap memory swapping - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_INITIAL_ADMIN_PASSWORD} # Sets the demo admin user password when using demo configuration, required for OpenSearch 2.12 and later ulimits: memlock: soft: -1 # Set memlock to unlimited (no soft or hard limit) hard: -1 nofile: soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536 hard: 65536 volumes: - opensearch-data1:/usr/share/opensearch/data # Creates volume called opensearch-data1 and mounts it to the container ports: - 9200:9200 # REST API - 9600:9600 # Performance Analyzer networks: - opensearch-net # All of the containers will join the same Docker bridge network opensearch-node2: image: opensearchproject/opensearch:latest # This should be the same image used for opensearch-node1 to avoid issues container_name: opensearch-node2 environment: - cluster.name=opensearch-cluster - node.name=opensearch-node2 - discovery.seed_hosts=opensearch-node1,opensearch-node2 - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 - bootstrap.memory_lock=true - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_INITIAL_ADMIN_PASSWORD} ulimits: memlock: soft: -1 hard: -1 nofile: soft: 65536 hard: 65536 volumes: - opensearch-data2:/usr/share/opensearch/data networks: - opensearch-net opensearch-dashboards: image: opensearchproject/opensearch-dashboards:latest # Make sure the version of opensearch-dashboards matches the version of opensearch installed on other nodes container_name: opensearch-dashboards ports: - 5601:5601 # Map host port 5601 to container port 5601 expose: - "5601" # Expose port 5601 for web access to OpenSearch Dashboards environment: OPENSEARCH_HOSTS: '["https://opensearch-node1:9200","https://opensearch-node2:9200"]' # Define the OpenSearch nodes that OpenSearch Dashboards will query networks: - opensearch-net volumes: opensearch-data1: opensearch-data2: networks: opensearch-net:
立ち上げる
docker compose up -d
デフォルトでは3ノード構成のOpenSearchが立ち上がる。
❯ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 302972caa879 opensearchproject/opensearch:latest "./opensearch-docker…" 8 minutes ago Up 8 minutes 9200/tcp, 9300/tcp, 9600/tcp, 9650/tcp opensearch-node2 0c2f9b2076b8 opensearchproject/opensearch-dashboards:latest "./opensearch-dashbo…" 8 minutes ago Up 8 minutes 0.0.0.0:5601->5601/tcp, :::5601->5601/tcp opensearch-dashboards f4f1ea05ab90 opensearchproject/opensearch:latest "./opensearch-docker…" 8 minutes ago Up 8 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9600->9600/tcp, :::9600->9600/tcp opensearch-node1
OpenSearchダッシュボードにアクセスする
http://localhost:5601からダッシュボードにアクセスする。
初期ユーザのユーザ名はadmin、パスワードは最初に設定したものになる。
memo
ホストマシンのメモリ割り当て
最低4GBが利用できるようにしておく。
Docker Desktopの場合はSettings → Resourcesから設定する。