zoukankan      html  css  js  c++  java
  • Docker容器利用weave实现跨主机互联

    Docker容器利用weave实现跨主机互联

    环境:
    图片描述

    实现目的:实现主机A中容器1与主机B中容器1的网络互联

    主机A步骤:

    ①下载复制weave二进制执行文件(需要internet)
    [root@192 ~]#git clone https://github.com/weaveworks... #如没有git,yum install git
    [root@192 ~]#cp -p /root/weave/weave /usr/local/bin/
    [root@192 ~]#weave version
    weave version会检测weave运行容器状态,所以会先从注册服务器下载weaveexec容器

    ②在第一次weave launch会报各种错误,根据提示先排除错误在进行启动。
    [root@192 ~]# iptables -L FORWARD --line-numbers
    找到规则REJECT all anywhere anywhere reject-with icmp-host-prohibited的编号将它删除
    [root@192 ~]# iptables -D FORWARD 19
    打开本地tcp和udp对weave的端口
    [root@192 ~]# iptables -I INPUT -m state --state NEW,ESTABLISHED -p tcp --dport 6783 -j ACCEPT
    [root@192 ~]# iptables -I INPUT -m state --state NEW,ESTABLISHED -p udp --dport 6783 -j ACCEPT
    weave launch会自动进行tls检测,把它关掉启动
    [root@192 ~]# weave launch --no-detect-tls
    等待下载weave剩下的支持容器

    ③启动docker容器,使用weave网桥给容器分配沟通地址
    [root@192 ~]# docker run -dit -P centos/httpd:v1
    [root@192 ~]# weave attach 192.168.2.1/24 容器ID
    192.168.2.1

    主机B步骤:

    ①下载复制weave二进制执行文件(需要internet)
    [root@192 ~]#git clone https://github.com/weaveworks...
    [root@192 ~]#cp -p /root/weave/weave /usr/local/bin/
    [root@192 ~]#weave version
    weave version会检测weave运行容器状态,所以会先从注册服务器下载weaveexec容器

    ②在第一次weave launch会报各种错误,根据提示先排除错误在进行启动。
    [root@192 ~]# iptables -L FORWARD --line-numbers
    找到规则REJECT all anywhere anywhere reject-with icmp-host-prohibited的编号将它删除
    [root@192 ~]# iptables -D FORWARD 19
    打开本地tcp和udp对weave的端口
    [root@192 ~]# iptables -I INPUT -m state --state NEW,ESTABLISHED -p tcp --dport 6783 -j ACCEPT
    [root@192 ~]# iptables -I INPUT -m state --state NEW,ESTABLISHED -p udp --dport 6783 -j ACCEPT
    weave launch会自动进行tls检测,把它关掉启动
    [root@192 ~]# weave launch 192.168.1.9 --no-detect-tls #启动并连接主机A,注意主机A不要去连接主机B
    等待下载weave剩下的支持容器

    ③启动docker容器,使用weave网桥给容器分配沟通地址
    [root@192 ~]# docker run -dit -P centos/httpd:v1
    [root@192 ~]# weave attach 192.168.2.2/24 容器ID
    192.168.2.2

    测试:

    [root@192 ~]# docker exec -it 容器ID /bin/bash
    [root@192 ··]# ping 192.168.2.2
    PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
    64 bytes from 192.168.2.2: icmp_seq=1 ttl=64 time=3.06 ms
    64 bytes from 192.168.2.2: icmp_seq=2 ttl=64 time=2.21 ms
    跨主机通信成功

  • 相关阅读:
    Keil的使用-1创建项目和工程
    UICollectionView进阶练习
    UICollectionView基础API笔记
    UICollectionView笔记2
    UICollectionView笔记1
    OC与JS交互之WKWebView
    OC与JS交互之JavaScriptCore
    OC与JS交互之UIWebView
    OC与JS交互前言
    最牛B的编码套路
  • 原文地址:https://www.cnblogs.com/twodog/p/12137160.html
Copyright © 2011-2022 走看看