パート1: ログコレクション環境を設定する
ログを生成するコンテナ、Splunk Distribution of the OpenTelemetry Collector、Splunk Enterprise サーバーなど、チュートリアル環境に必要なすべてのサービスを設定します。チュートリアルの概要については、「Tutorial: Use the Collector to send container logs to Splunk Enterprise」を参照してください。
ログコレクション環境を作成する
このチュートリアルで使用するすべての構成ファイルは、1 つのディレクトリ内にあります。ディレクトリと最初のファイルを作成するには、次の手順に従います。
-
log-collectionというディレクトリを作成します。
-
ログ収集ディレクトリにdocker-compose.ymlというファイルを作成します。
ログインサービスを追加する
Docker Compose は、このチュートリアルで使用するサービスをデプロイし、管理します。ログを出力する Bash サービスを設定するには、docker-compose.yml ファイルに以下を追加します。
services:
logging1:
image: bash:latest
container_name: logging1
# Command that runs when the container starts.
command: bash -c "while(true) do echo '{\"message\":\"logging1\"}' >> /output/file.log ; sleep 1; done"
# Sets the logging services not to start until the Collector service starts.
depends_on:
- otelcollector
# Routes the `./output` directory from the host machine to the `/output` volume.
volumes:
- ./output1:/output
logging2:
image: bash:latest
container_name: logging2
command: bash -c "while(true) do echo '{\"message\":\"logging2\"}' >> /output/file.log ; sleep 1; done"
depends_on:
- otelcollector
volumes:
- ./output2:/output
Collectorサービスを追加する
ロギングサービスから受信するログデータを受け入れ、チュートリアルの次のパートで定義する Collector コンポーネントを実行する Collector サービスを作成します。 [services] セクションで、次のコードを追加します。
otelcollector:
image: quay.io/signalfx/splunk-otel-collector:latest
container_name: otelcollector
# Command that runs when the container starts.
command: ["--config=/etc/otel-collector-config.yml"]
# Routes files and directories from the host machine to the container volumes
volumes:
- ./otel-collector-config.yml:/etc/otel-collector-config.yml
- ./output1:/output1
- ./output2:/output2
# Sets the otelcollector service not to start until splunk service starts
# and is in the Healthy state.
depends_on:
splunk:
condition: service_healthy
# Host machine port 18088 forwards to the container port 8088,
# on which the otelcollector service listens for incoming log data.
ports:
- 18088:8088
Splunk Enterpriseサービスを追加する
Collector サービスから受信するログデータを受け入れる Splunk Enterprise サービスを作成します。 [services] セクションで、次のコードを追加します。
splunk:
image: splunk/splunk:9.1.2
container_name: splunk
# Sets environment variables to automatically accept the license agreement,
# define the token for the Splunk HTTP Event Collector (HEC), and define the administrator password.
environment:
- SPLUNK_START_ARGS=--accept-license
- SPLUNK_HEC_TOKEN=00000000-0000-0000-0000-0000000000000
- SPLUNK_PASSWORD=changeme
# Host machine port 18000 forwards to the container port 8000,
# on which the splunk service listens for incoming log data.
ports:
- 18000:8000
# Command that runs at regular intervals to check the health of the splunk service.
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:8000']
interval: 5s
timeout: 5s
retries: 20
# Routes the `./splunk.yml` file from the host machine to the `/tmp/defaults/default.yml` file
# inside the container, and creates persistent storage locations for data and configuration files.
volumes:
- ./splunk.yml:/tmp/defaults/default.yml
- /opt/splunk/var
- /opt/splunk/etc
splunk/splunk] イメージには必ず [9.1.2] タグを使用してください。 [latest] タグを使用すると、HEC トークンの作成に関連して発生する既知の問題があります。次のステップ
これで、Collector を使用してコンテナログを収集し、Splunk Enterprise インスタンスに送信するために必要なサービスを設定しました。次に、コンテナログの受信、処理、エクスポートに使用する Collector コンポーネントを設定します。続いて、Splunk Web で検索および取得するためのログを保存する Splunk Enterprise インデックスを設定します。続行するには、「Part 2: Configure the Collector and Splunk Enterprise instance」を参照してください。
さらに詳しく
-
Collector を使用して Docker コンテナを監視する方法の詳細については、「Docker コンテナ」を参照してください。
-
Splunk Enterprise コンテナの詳細については、「docker-splunk 」ドキュメントおよび 「Docker-Splunk」GitHub リポジトリを参照してください。