美文网首页
使用Weave让多台主机Docker网络互通

使用Weave让多台主机Docker网络互通

作者: romejiang | 来源:发表于2019-12-03 15:43 被阅读0次

    安装:


    sudo curl -L git.io/weave -o /usr/local/bin/weave

    sudo chmod a+x /usr/local/bin/weave

    启动:


    #主机启动

    weave launch

    #从机启动

    weave launch  172.33.16.6 主机ip

    or

    weave launch

    weave connect 172.33.16.6 主机ip


    设置环境变量:

    eval $(weave env) 

    检查状态:


    weave version  #查看weave版本

    weave status    #查看weave状态

    weave status dns

    weave status peers

    weave status  connections

    docker network ls

    docker network inspect weave

    防火墙设置:


    如果linux开启了防火墙,weave需要开启6783、6784、53端口,让服务器之间通讯。

    如果开启这些端口后容器之间还是无法连接、DNS无效,请关闭防火墙试试。

    systemctl disable firewalld

    systemctl stop firewalld

    关闭防火墙后iptables表可能需要重建,否则docker run的时候会报错

    systemctl restart docker

    测试连通情况:


    主机:

    docker run --name c1 -it busybox sh

    ping c2

    从机:

    docker run --name c2 -it busybox sh

    ping c1

    设置自启动:


    配置自启服务文件

    vim /etc/systemd/system/weave.service

    [Unit]

    Description=Weave Network

    Documentation=http://docs.weave.works/weave/latest_release/

    Requires=docker.service

    After=docker.service

    [Service]

    EnvironmentFile=-/etc/sysconfig/weave

    ExecStartPre=/usr/local/bin/weave launch --no-restart $PEERS

    ExecStart=/usr/bin/docker attach weave

    ExecStop=/usr/local/bin/weave stop

    [Install]

    WantedBy=multi-user.target

    如果是从机还需要配置这个文件

    vim /etc/sysconfig/weave

    PEERS="172.33.16.6 HOST2 .. HOSTn"

    然后尝试启动

    sudo systemctl start weave

    如果启动失败,先手动停止,然后再尝试启动

    eval $(weave env --restore)

    weave stop

    设置开机自启动

    sudo systemctl enable weave

    官方文档

    https://www.weave.works/docs/net/latest/install/installing-weave/

    相关文章

      网友评论

          本文标题:使用Weave让多台主机Docker网络互通

          本文链接:https://www.haomeiwen.com/subject/imgcgctx.html