您的当前位置:首页 >人工智能 >如何使用Elasticsearch和cAdvisor监控Docker容器 正文

如何使用Elasticsearch和cAdvisor监控Docker容器

时间:2025-11-04 13:16:53 来源:网络整理编辑:人工智能

核心提示

复制#!/usr/bin/envbash # #CreateaSwarmModeclusterwithasinglemasterandaconfigurab

如何使用Elasticsearch和cAdvisor监控Docker容器
复制#!/usr/bin/env bash  #  # Create a Swarm Mode cluster with a single master and a configurable number of workers    workers=${WORKERS:-"worker1 worker2"}    #######################################  # Creates a machine on Digital Ocean  # Globals:  #   DO_ACCESS_TOKEN The token needed to access DigitalOceans API  # Arguments:  #   $1 the actual nameto give to the machine  #######################################  create_machine() {    docker-machine create       -d digitalocean       --digitalocean-access-token=$DO_ACCESS_TOKEN      --digitalocean-size 2gb      $1 }    #######################################  # Executes a command on the specified machine  # Arguments:  #   $1     The machine on which to run the command  #   $2..$n The command toexecuteon that machine  #######################################  machine_do() {    docker-machine ssh $@ }    main() {      if [ -z "$DO_ACCESS_TOKEN" ]; then     echo "Please export a DigitalOcean Access token: https://cloud.digitalocean.com/settings/api/tokens/new"     echo "export DO_ACCESS_TOKEN=<yourtokenhere>"     exit 1    fi      if [ -z "$WORKERS" ]; then     echo "You havent provided your workers by setting the \$WORKERS environment variable,何使和 using the default ones: $workers" fi      # Create the firstandonly master    echo "Creating the master"     create_machine master1    master_ip=$(docker-machine ip master1)      # Initialize the swarm mode on it      echo "Initializing the swarm mode"   machine_do master1 docker swarm init --advertise-addr $master_ip   # Obtain the token to allow workers tojoin     worker_tkn=$(machine_do master1 docker swarm join-token -q worker)    echo "Worker token: ${worker_tkn}"   # Createandjoin the workers   for worker in $workers; do      echo "Creating worker ${worker}"     create_machine $worker      machine_do $worker docker swarm join--token $worker_tkn $master_ip:2377   done  }    main $@  1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.