閫氳繃docker鎼缓ELK闆嗙兢

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了閫氳繃docker鎼缓ELK闆嗙兢相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e6%9f%a5%e7%9c%8b' title='鏌ョ湅'>鏌ョ湅   discover   manage   涓ゅ彴   stash   鏈哄櫒   end   鏁欑▼   

棣栧厛瀹夎docker 鍜?docker-compose

# 鏇存柊yum
    yum update

# 绉婚櫎docker鏃х増鏈?濡傛灉鏈夌殑璇?
    yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

# 瀹夎绯荤粺渚濊禆
    yum install -y yum-utils device-mapper-persistent-data lvm2 

# 娣诲姞docker婧愪俊鎭紙涓嬭浇閫熷害姣旇緝蹇級
    yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

# 鏇存柊yum缂撳瓨
    yum makecache fast

# 瀹夎docker-ce
    yum -y install docker-ce

# 鍚姩docker鍚庡彴鏈嶅姟
    sudo systemctl start docker

# 閰嶇疆闃块噷浜戦暅鍍忓姞閫熷櫒锛堝缓璁繘琛岄厤缃? 杩欓噷鍔犻€熷櫒鍦板潃浠呯敤浜庡睍绀猴紝鏃犲姞閫熷姛鑳斤紝璇蜂娇鐢ㄨ嚜宸辩殑闃块噷浜戝姞閫熷櫒锛屾暀绋嬭鐧惧害锛屽姞閫熷櫒鍏嶈垂锛?    mkdir /etc/docker
    sudo tee /etc/docker/daemon.json <<-'EOF'
        {"registry-mirrors": ["https://6y4h812t.mirror.aliyuncs.com"]}
    EOF
    sudo systemctl daemon-reload
    sudo systemctl restart docker

# 瀹夎docker-compose
    cd /usr/local/src
    sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose  
    sudo chmod +x /usr/local/bin/docker-compose
    docker-compose --version  

# 鑷虫锛宒ocker 鍜宒ocker-compose瀹夎瀹屾瘯锛?濡傛湁閿欒锛岃鐣欒█锛屾瘯绔熸槸涔嬪墠鍐欑殑鑷姩瀹夎鑴氭湰copy杩囨潵鐨勩€?/code>

棣栧厛鎼缓涓夎妭鐐笶S闆嗙兢锛屼互涓嬫楠ゅ潎闇€鍦ㄤ笁鍙版湇鍔″櫒鎵ц

  • 1銆佷娇鐢╠ocker-compose锛屽缓绔嬪瓨鏀緔ml鏂囦欢鐨勭洰褰?/li>
   寤虹珛鏂囦欢澶癸紝/root/elk锛堥殢鎰忓嵆鍙級
   mkdir /root/elk
  • 2銆佸垱寤篸ocker-compose.yml鏂囦欢
    cd /root/elk
    touch docker-compose.yml

-3銆乨ocker-compose.yml 鐨勬枃浠跺唴瀹瑰涓?/p>

version: '3'
services:
  elasticsearch:                    # 鏈嶅姟鍚嶇О
    image: elasticsearch:7.3.1      # 浣跨敤鐨勯暅鍍?    container_name: elasticsearch   # 瀹瑰櫒鍚嶇О
    restart: always                 # 澶辫触鑷姩閲嶅惎绛栫暐
    environment:                                    
      - node.name=41  # 鑺傜偣鍚嶇О锛岄泦缇ゆā寮忎笅姣忎釜鑺傜偣鍚嶇О鍞竴
      - network.publish_host=172.168.50.41  # 鐢ㄤ簬闆嗙兢鍐呭悇鏈哄櫒闂撮€氫俊,鍏朵粬鏈哄櫒璁块棶鏈満鍣ㄧ殑es鏈嶅姟
      - network.host=0.0.0.0                # 璁剧疆缁戝畾鐨刬p鍦板潃锛屽彲浠ユ槸ipv4鎴杋pv6鐨勶紝榛樿涓?.0.0.0锛?      - discovery.seed_hosts=172.168.50.40,172.168.50.240,172.168.50.41  # es7.x 涔嬪悗鏂板鐨勯厤缃紝鍐欏叆鍊欓€変富鑺傜偣鐨勮澶囧湴鍧€锛屽湪寮€鍚湇鍔″悗鍙互琚€変负涓昏妭鐐?      - cluster.initial_master_nodes=172.168.50.40,172.168.50.240,172.168.50.41  # es7.x 涔嬪悗鏂板鐨勯厤缃紝鍒濆鍖栦竴涓柊鐨勯泦缇ゆ椂闇€瑕佹閰嶇疆鏉ラ€変妇master
      - cluster.name=es-cluster   # 闆嗙兢鍚嶇О锛岀浉鍚屽悕绉颁负涓€涓泦缇?      # - http.cors.enabled=true    # 鏄惁鏀寔璺ㄥ煙锛屾槸锛歵rue // 杩欓噷璁剧疆涓嶈捣浣滅敤锛屼絾鏄彲浠ヨ繘鍏ュ鍣ㄩ噷闈㈠湪elasticsearch.yml 鏂囦欢涓坊鍔狅紝鎴栬€呭皢姝ゆ枃浠舵槧灏勫埌瀹夸富鏈鸿繘琛屼慨鏀癸紝鐒跺悗閲嶅惎锛岃В鍐宠法鍩?      # - http.cors.allow-origin="*" # 琛ㄧず鏀寔鎵€鏈夊煙鍚?     // 杩欓噷璁剧疆涓嶈捣浣滅敤锛屼絾鏄彲浠ヨ繘鍏ュ鍣ㄩ噷闈㈠湪elasticsearch.yml 鏂囦欢涓坊鍔狅紝鎴栬€呭皢姝ゆ枃浠舵槧灏勫埌瀹夸富鏈鸿繘琛屼慨鏀癸紝鐒跺悗閲嶅惎锛岃В鍐宠法鍩?      - bootstrap.memory_lock=true  # 鍐呭瓨浜ゆ崲鐨勯€夐」锛屽畼缃戝缓璁负true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m" # 璁剧疆鍐呭瓨
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - /root/elk/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml  # 灏嗗鍣ㄤ腑es鐨勯厤缃枃浠舵槧灏勫埌鏈湴锛岃缃法鍩燂紝 鍚﹀垯head鎻掍欢鏃犳硶杩炴帴璇ヨ妭鐐?      - esdata:/usr/share/elasticsearch/data  # 瀛樻斁鏁版嵁鐨勬枃浠讹紝 娉ㄦ剰锛氳繖閲岀殑esdata涓?椤剁骇volumes涓嬬殑涓€椤广€?    ports:
      - 9200:9200    # http绔彛
      - 9300:9300    # es鑺傜偣鐩存帴浜や簰鐨勭鍙o紝闈瀐ttp
volumes:
  esdata:
    driver: local    # 浼氱敓鎴愪竴涓搴旂殑鐩綍鍜屾枃浠讹紝濡備綍鏌ョ湅锛屼笅闈㈡湁璇存槑銆?/code>
  • 4銆佸彟澶栦袱鍙版湇鍔″櫒涔熺収鐫€杩欎釜閰嶇疆杩涜閰嶇疆锛屼絾IP锛屼互鍙婅妭鐐瑰悕绉伴渶瑕佹敼涓€涓嬪嵆鍙€?/li>
  • 5銆佸唴瀛樿缃紝涓夊彴鏈嶅姟鍣ㄩ兘闇€瑕?/li>
涓ょ鏂瑰紡锛?1銆佹満鍣ㄩ噸鍚悗闇€鍐嶆璁剧疆
    sysctl -w vm.max_map_count=262144

2銆佺洿鎺ヤ慨鏀归厤缃枃浠讹紝 杩涘叆sysctl.conf鏂囦欢娣诲姞涓€琛岋紙瑙e喅瀹瑰櫒鍐呭瓨鏉冮檺杩囧皬闂锛?
    vi /etc/sysctl.conf

    sysctl vm.max_map_count=262144

    sysctl -p 绔嬪嵆鐢熸晥

-6銆乪s鐨勯厤缃枃浠?/p>

  • 鍦ㄥ綋鍓嶇洰褰曚笅"/root/elk" 鎵ц vim elasticsearch.yml
  • elasticsearch.yml 鍐呭濡備笅锛?/li>
    network.host: 0.0.0.0
    http.cors.enabled: true      # 璁剧疆璺ㄥ煙锛屼富瑕佺敤浜巋ead鎻掍欢璁块棶es
    http.cors.allow-origin: "*"
  • 7銆佸惎鍔╡s闆嗙兢, 涓夊彴鏈嶅姟鍣ㄤ緷娆℃墽琛?docker-compose up -d
  • 8銆佺劧鍚庤闂?http://172.168.50.41:9200/_cluster/health?pretty 鏌ョ湅鏄惁闆嗙兢姝e父杩愯, 姝e父杩愯浼氳繑鍥炲涓嬩俊鎭?/li>
{
  "cluster_name" : "es-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}
  • 9銆佷娇鐢╤ead鐩戞帶es闆嗙兢
    // 鎷夊彇闀滃儚
    docker pull mobz/elasticsearch-head:5
    // 鍚姩
    docker run -d --name es_admin -p 9100:9100 mobz/elasticsearch-head:5
  • 10銆佸湪娴忚鍣ㄨ緭鍏ttp://IP:9100
    鎶€鏈浘鐗? src=
    娉ㄦ剰锛孖P鍦板潃瑕佷娇鐢ㄤ綘es鎵€鍦ㄦ湇鍔″櫒鐨勫湴鍧€锛岀劧鍚庣偣鍑昏繛鎺ワ紝鍑虹幇绫讳技鐨勬樉绀鸿鏄庯紝娌¢棶棰橈紝杩欓噷鏄笁涓妭鐐癸紝鏄熸槦浠h〃master銆?
    濡傛灉鐐瑰嚮杩炴帴娌℃湁鍙嶅簲锛孎12鏌ョ湅network鏄?03锛屾垨鑰?00锛屼絾鏄痗onsole涓彁绀鸿法鍩燂紝閭d箞璇存槑璺ㄥ煙璁剧疆鐨勬湁闂锛岀洿鎺ヨ繘鍏ュ鍣ㄤ腑锛屼娇鐢?docker exec -it 瀹瑰櫒ID /bin/bash 锛屾鏌?usr/share/elasticsearch/config/elasticsearch.yml鏂囦欢锛屾槸鍚︽湁浠ヤ笅涓よ锛?    http.cors.enabled: true
    http.cors.allow-origin: "*"
  • 涓婇潰璇村埌鐨勯《绾olumes锛?濡備綍鏌ョ湅鎸傝浇鍗峰湪瀹夸富鏈虹殑浣嶇疆鍛紵
    # docker volume create elk_data // 鍒涘缓涓€涓嚜瀹氫箟瀹瑰櫒鍗?    # docker volume ls // 鏌ョ湅鎵€鏈夊鍣ㄥ嵎
    # docker volume inspect elk_data // 鏌ョ湅鎸囧畾瀹瑰櫒鍗疯鎯呬俊鎭? 鍖呮嫭鐪熷疄鐩綍
    娉ㄦ剰锛?濡傛灉浣犺鍒犻櫎涓€涓寕杞藉嵎锛屾垨鑰呴噸鏂扮敓鎴愶紝璇锋墽琛屽垹闄ゅ嵎鎿嶄綔
    # docker volume rm edc-nginx-vol  // 鐩存帴鎵ц杩欎釜鍛戒护锛屽悓鏃朵細鍒犻櫎鏂囦欢锛屼絾鏄厛鍒犻櫎鏂囦欢鐨勮瘽锛屽繀椤绘墽琛屾鍛戒护锛屽惁鍒欏彲鑳藉鑷磋鑺傜偣鏃犳硶鍔犲叆闆嗙兢銆?/code>

浠ヤ笂閮藉畬鎴愶紝鍒檈s涓夎妭鐐归泦缇ゆ惌寤哄畬鎴愶紝涓嬮潰淇敼172.168.50.41鏈嶅姟鍣ㄧ殑/root/elk/docker-compose.yml鏂囦欢锛屼箣鍓嶅彧鏄痚s锛岀幇鍦ㄥ皢鏀寔ELK

ELK 鍓嶇疆宸ヤ綔, 鍗囩骇pip锛岄鍏堟媺鍙栬浣跨敤鐨勯暅鍍?/h3>
    yum -y install epel-release
    yum -y install python-pip
    
    // 鏇存柊pip
    pip install --upgrade pip

    // 涓嬭浇elasticsearch锛宭ogstash锛宬ibana锛?鑷猠s5寮€濮嬶紝涓€鑸笁涓蒋浠剁殑鐗堟湰閮戒繚鎸佷竴鑷翠簡銆?
    docker pull docker.elastic.co/elasticsearch/elasticsearch:7.1.1 && docker pull docker.elastic.co/logstash/logstash:7.1.1 && docker pull docker.elastic.co/kibana/kibana:7.1.1

ELK鎼缓

  • 1銆佸缓绔嬪瓨鏀緀lk閰嶇疆鏂囦欢鐨勭洰褰曪紝
    cd /root/elk
    vim docker-compose.yml // 浣滀负docker-compose鍚姩elk杩欎竴缁勫鍣ㄧ殑寮曞鏂囦欢
  • 2銆乨ocker-compose.yml鏂囦欢鍐呭濡備笅
version: '3'
services:
  elasticsearch:                                                    # 鏈嶅姟鍚嶇О
    image: docker.elastic.co/elasticsearch/elasticsearch:7.1.1      # 浣跨敤鐨勯暅鍍?    container_name: elasticsearch7.1.1                              # 瀹瑰櫒鍚嶇О
    environment:                                                    # 鐜鍙橀噺
      - node.name=node-41                                           # 鑺傜偣鍚嶇О锛岄泦缇ゆā寮忎笅姣忎釜鑺傜偣鍚嶇О鍞竴
      - network.publish_host=172.168.50.41                          # 鐢ㄤ簬闆嗙兢鍐呭悇鏈哄櫒闂撮€氫俊,鍏朵粬鏈哄櫒璁块棶鏈満鍣ㄧ殑es鏈嶅姟
      - network.host=0.0.0.0                                        # 璁剧疆缁戝畾鐨刬p鍦板潃锛屽彲浠ユ槸ipv4鎴杋pv6鐨勶紝榛樿涓?.0.0.0锛?      - discovery.seed_hosts=172.168.50.40,172.168.50.240,172.168.50.41             # es7.x 涔嬪悗鏂板鐨勯厤缃紝鍐欏叆鍊欓€変富鑺傜偣鐨勮澶囧湴鍧€锛屽湪寮€鍚湇鍔″悗鍙互琚€変负涓昏妭鐐?      - cluster.initial_master_nodes=172.168.50.40,172.168.50.240,172.168.50.41     # es7.x 涔嬪悗鏂板鐨勯厤缃紝鍒濆鍖栦竴涓柊鐨勯泦缇ゆ椂闇€瑕佹閰嶇疆鏉ラ€変妇master
      - cluster.name=es-cluster                                     # 闆嗙兢鍚嶇О锛岀浉鍚屽悕绉颁负涓€涓泦缇?      #- http.cors.enabled=true                                     # 鏄惁鏀寔璺ㄥ煙锛屾槸锛歵rue锛屼富瑕佺敤浜巋ead鎻掍欢璁块棶es锛岃繖閲岃缃笉璧蜂綔鐢紝鍘熷洜鏈煡锛屾垜浠細灏唀s鐨勯厤缃枃浠舵槧灏勫埌瀹夸富鏈鸿繘琛屼慨鏀?      #- http.cors.allow-origin="*"                                 # 琛ㄧず鏀寔鎵€鏈夊煙鍚嶏紝鏄細true锛岃繖閲岃缃笉璧蜂綔鐢紝鍘熷洜鏈煡锛屾垜浠細灏唀s鐨勯厤缃枃浠舵槧灏勫埌瀹夸富鏈鸿繘琛屼慨鏀?      - bootstrap.memory_lock=true                                  # 鍐呭瓨浜ゆ崲鐨勯€夐」锛屽畼缃戝缓璁负true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"                            # 璁剧疆鍐呭瓨澶у皬
    volumes:
      - esdata:/usr/share/elasticsearch/data                                           # 璁剧疆es鏁版嵁瀛樻斁鐨勭洰褰?      - /root/elk/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml  # 鏄犲皠es瀹瑰櫒涓殑閰嶇疆鏂囦欢鍒板涓绘満
    hostname: elasticsearch                                         # 鏈嶅姟hostname
    ulimits:                                                        # 鏄惁闄愬埗鍐呭瓨
      memlock:
        soft: -1
        hard: -1
    restart: always                                                 # 閲嶅惎绛栫暐
    ports:
      - 9200:9200                                                   # http绔彛
      - 9300:9300                                                   # es鑺傜偣鐩存帴浜や簰鐨勭鍙o紝闈瀐ttp
  kibana:
    image: docker.elastic.co/kibana/kibana:7.1.1
    container_name: kibana7.1.1
    environment:
      - elasticsearch.hosts=http://elasticsearch:9200               # 璁剧疆杩炴帴鐨別s鑺傜偣
    hostname: kibana
    depends_on:
      - elasticsearch                                               # 渚濊禆es鏈嶅姟锛屼細鍏堝惎鍔╡s瀹瑰櫒鍦ㄥ惎鍔╧ibana
    restart: always
    ports:
      - 5601:5601                                                   # 瀵瑰璁块棶绔彛
  logstash:
    image: docker.elastic.co/logstash/logstash:7.1.1
    container_name: logstash7.1.1
    hostname: logstash
    restart: always
    depends_on:
      - elasticsearch
    ports:
      - 9600:9600
      - 5044:5044
volumes:                                                            # 椤剁骇volumes
  esdata:
    driver: local                                                   # 浼氱敓鎴愪竴涓搴旂殑鐩綍鍜屾枃浠讹紝濡備綍鏌ョ湅锛屼笅闈㈡湁璇存槑銆?
  • 褰撳墠鐩綍鎵ц docker-compose up -d 鍚姩ELK鏈嶅姟
    鍑虹幇done琛ㄧず鎴愬姛锛宒ocker-compose logs 鏌ョ湅鏃ュ織锛堝垎鍒緭鍑篹lk涓変釜鏈嶅姟鐨勬棩蹇楋級鎵цdocker ps -a 鍙互鐪嬪埌涓変釜鏈嶅姟鐨勮繍琛岀姸鎬?    鍦ㄦ祻瑙堝櫒杈撳叆http://IP:5601/ 璁块棶kibana

鎺ヤ笅鏉ワ紝鎴戜細鍐欎竴绡囦娇鐢ㄥ浣曚娇鐢‥LK鐨勬枃绔犮€傚啓濂藉悗鎴戜細灏嗘枃绔犲湴鍧€璐村湪姝ゅ銆?/h3>

以上是关于閫氳繃docker鎼缓ELK闆嗙兢的主要内容,如果未能解决你的问题,请参考以下文章

Docker涔媠warm閮ㄧ讲闆嗙兢

Docker Swanm闆嗙兢閰嶇疆

flink1.10 Linux 闆嗙兢瀹夎

Redis闆嗙兢閮芥湁鍝簺妯″紡

linux闆嗙兢

鍐呯綉闆嗙兢鍑嗗悓姝hell鑴氭湰

(c)2006-2024 SYSTEM All Rights Reserved IT常识