docker跨主机连接之weave

1、准备两台虚拟机

  • 192.168.0.105
  • 192.168.0.106

在这里插入图片描述

节点间如果有防火墙,必须彼此放行TCP 6783 和UDP 6783/6784端口,这是weave控制和数据端口

2、安装weave

weave githup地址:https://github.com/weaveworks/weave

安装:

# 105:
[root@localhost ~]# wget -O /usr/bin/weave  https://github.com/weaveworks/weave/releases/download/v2.7.0/weave


# 106:
[root@localhost ~]# wget -O /usr/bin/weave  https://github.com/weaveworks/weave/releases/download/v2.7.0/weave

[root@localhost ~]# chmod a+x /usr/bin/weave 

帮助命令

[root@localhost ~]# weave --help
Usage:

weave --help | help
      setup
      version

weave launch        [--password <pass>] [--trusted-subnets <cidr>,...]
                    [--host <ip_address>]
                    [--name <mac>] [--nickname <nickname>]
                    [--no-restart] [--resume] [--no-discovery] [--no-dns]
                    [--dns-listen-address <address>:<port>]
                    [--ipalloc-init <mode>]
                    [--ipalloc-range <cidr> [--ipalloc-default-subnet <cidr>]]
                    [--plugin=false] [--proxy=false]
                    [-H <endpoint>] [--without-dns] [--no-multicast-route]
                    [--no-rewrite-hosts] [--no-default-ipalloc]
                    [--hostname-from-label <labelkey>]
                    [--hostname-match <regexp>]
                    [--hostname-replacement <replacement>]
                    [--rewrite-inspect]
                    [--log-level=debug|info|warning|error]
                    [--token <weave-cloud-service-token>]
                    <peer> ...

weave prime

weave env           [--restore]
      config
      dns-args

weave connect       [--replace] [<peer> ...]
      forget        <peer> ...

weave attach        [--without-dns] [--rewrite-hosts] [--no-multicast-route]
                      [<addr> ...] <container_id>
      detach        [<addr> ...] <container_id>

weave expose        [<addr> ...] [-h <fqdn>] [--without-masquerade]
      hide          [<addr> ...]

weave dns-add       [<ip_address> ...] <container_id> [-h <fqdn>] |
                    <ip_address> ... -h <fqdn>
      dns-remove    [<ip_address> ...] <container_id> [-h <fqdn>] |
                    <ip_address> ... -h <fqdn>
      dns-lookup    <unqualified_name>

weave status        [targets | connections | peers | dns | ipam]
      report        [-f <format>]
      ps            [<container_id> ...]

weave stop

weave reset         [--force]
      rmpeer        <peer_id> ...

where <peer>     = <ip_address_or_fqdn>[:<port>]
      <cidr>     = <ip_address>/<routing_prefix_length>
      <addr>     = [ip:]<cidr> | net:<cidr> | net:default
      <endpoint> = [tcp://][<ip_address>]:<port> | [unix://]/path/to/socket
      <peer_id>  = <nickname> | <weave internal peer ID>
      <mode>     = consensus[=<count>] | seed=<mac>,... | observer

To troubleshoot and visualize Weave networks, try Weave Cloud: http://www.weave.works/product/cloud/

启动并与其它主机建立联系

# 105:
[root@localhost ~]# chmod a+x /usr/bin/weave 

# 106
[root@localhost ~]# weave launch 192.168.0.105

测试连通性:

# 105
[root@localhost ~]# weave status connections
<- 192.168.0.106:57806   established fastdp 1e:42:eb:57:eb:cd(localhost.localdomain) mtu=1376

3、实验

# 105
[root@localhost ~]# docker run -itd --name mytest1 centos
[root@localhost ~]# weave attach 173.17.0.2/24 mytest1

# 106
[root@localhost ~]# docker run -itd --name mytest2 centos
[root@localhost ~]# weave attach 173.17.0.3/24 mytest2
# 105
[root@localhost ~]# docker exec -it mytest1 /bin/bash
[root@fd4c77455b6f /]# ping 173.17.0.3
PING 173.17.0.3 (173.17.0.3) 56(84) bytes of data.
64 bytes from 173.17.0.3: icmp_seq=1 ttl=64 time=8.29 ms
64 bytes from 173.17.0.3: icmp_seq=2 ttl=64 time=0.373 ms
64 bytes from 173.17.0.3: icmp_seq=3 ttl=64 time=0.363 ms

4、weave命令

命令描述
weave status查看weave状态
weave status connections查看连接详情
weave status peers查看节点之间的关系
weave launch启动并与其他主机建立连接,启动weave并下载镜像
weave launch 进行连接 IP连接对端服务器
weave stop关闭****weave
weave attach <container_id>将容器加入到weave网络,并分配ip
weave expose weave expose ip/24这个命令会把宿主机加入到weave 网络中, 宿主机就可以和容器之间自由通信了

iner_id> | 将容器加入到weave网络,并分配ip |
| weave expose | weave expose ip/24这个命令会把宿主机加入到weave 网络中, 宿主机就可以和容器之间自由通信了 |

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值