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 网络中, 宿主机就可以和容器之间自由通信了 |