CENTOS7 Docker Multi-host container interconnect-based on OvS

Source: Internet
Author: User
Tags docker run rpmbuild openvswitch

A picture of yourself, mark:2016. June 27 17:09:14

I understand, if there are mistakes thank you advice.

CENTOS7, deploy OvS and Docker, and centos6.8-based SSH images commands.

#!/bin/bash#auther:vyum upgrade-ysed-i '/selinux/s/enforcing/disabled/'/etc/selinux/configsystemctl stop Firewalld.service && systemctl Disable firewalld.servicecat>>/etc/yum.repos.d/docker.repo<< V[ Docker-repo]name= Docker repobaseurl=https://yum.dockerproject.org/repo/main/centos/7enabled=1gpgcheck=1gpgkey= Https://yum.dockerproject.org/gpgVyum Install Docker-engine-ychkconfig Docker onsystemctl enable Docker.servicesystemctl preset-allsystemctl start Docker.servicesystemctl enable Docker.servicedocker pull CentOS: Centos6.8mkdir sshcd sshyum-y Install vimcat>> dockerfile<<v#---------ssh! From Centos:centos6.8maintainer ' [email protected] ' ENV. Xtermrun yum-y Install Openssh-server;yum clean AllRUN Mkdir/var/run/sshdrun ssh-keygen-t rsa-f/etc/ssh/ssh_host_rsa_keyrun ssh-keygen-t dsa-f/etc/ssh/ssh_host_dsa_keyRU N/bin/echo ' root:anjubao.com ' |chpasswdrun/bin/sed-i ' s/.*session.*required.*pam_loginuid.so.*/session optional Pam _loginuiD.so/g '/etc/pam.d/sshdrun/bin/echo-e "lang=\" en_US. Utf-8\ "" >/etc/default/localexpose 22CMD ["/usr/sbin/sshd", "-D"]vdocker build-t= ' syw/ssh:centos6.8 '. If [$?-ne 0]; Thenecho ' Build error ' exit 0fidocker run-d--name test1 syw/sshyum install bridge-utils-ycd ~yum install wget-yyum-y i Nstall openssl-devel Kernel-develyum Groupinstall "Development Tools" wget http://openvswitch.org/releases/ Openvswitch-2.5.0.tar.gzyum install gcc make python-devel openssl-devel kernel-devel Graphviz kernel-debug-devel autoconf automake rpm-build redhat-rpm-config libtool-ymkdir-p ~/rpmbuild/sourcestar zxf OPENVSWITCH-2.5.0.TAR.GZCP Openvswitch-2.5.0.tar.gz ~/rpmbuild/sources/ls/lib/modules/$ (uname-r)-lnrpmbuild-bb--without Check Openvswitch-2.5.0/rhel/openvswitch.specyum-y Install TREECD Rpmbuild/rpms/x86_64/yum localinstall Openvswitch-2.5.0-1.x86_64.rpm-ysystemctl Start Openvswitch.service

Second, the configuration OvS

HOST1

#!/bin/bash#author:vethname= ' IP addr|grep-w ' 2: ' |awk ' {print $ {} ' |awk-f: ' {print '} ' ipaddr= ' IP addr|grep inet|grep-v "Inet6" |awk ' nr==2 {print $ {} ' |awk-f "/" ' {print '} ' echo 1 >/proc/sys/net/ipv4/ip_forwardovs-vsctl add-br ovsbr0 Ovs-vsctl add-port ovsbr0 gre0--set Interface gre0 type=gre options:remote_ip=192.168.17.129brctl addbr kbr0brctl addif Kbr0 ovsbr0ip link Set dev Docker0 downip link del Dev docker0#=============configure kbr0 by:v===== Online Some versions will be less parameters, Centos7 will error Oh =====cat >>/etc/sysconfig/network-scripts/ifcfg-kbr0 << vdevice=kbr0onboot=yesbootproto=staticipaddr =172.17.1.1netmask=255.255.255.0gateway=172.17.1.254userctl=notype=bridgeipv6init=novcat >>/etc/sysconfig /network-scripts/route-ens32 <<v172.17.2.0/24 via 192.168.17.129 Dev eno16777736vsystemctl restart Network.servicesystemctl Stop Docker.service#===============================configure Docker network====by:v===== Cat >>/etc/systemd/system/docker.service.d/docker.conf<< v[Service]execstart=execstart=/usr/bin/docker daemon-h fd://-B kbr0vchmod +x/etc/rc.d/rc.localcat >>/etc/rc.d/  rc.local<< Vip Route del defaultip route add default via 192.168.17.2 dev $ETHNAMEbrctl addif kbr0 ovsbr0v systemctl Start Docker.service

 host2

#!/bin/bash#author:vethname= ' IP addr|grep-w ' 2: ' |awk ' {print $ {} ' |awk-f: ' {print '} ' ipaddr= ' IP addr|grep inet|grep-v "Inet6" |awk ' nr==2 {print $ {} ' |awk-f "/" ' {print '} ' echo 1 >/proc/sys/net/ipv4/ip_forwardovs-vsctl add-br ovsbr0 Ovs-vsctl add-port ovsbr0 gre0--set Interface gre0 type=gre options:remote_ip=192.168.17.128brctl addbr kbr0brctl addif Kbr0 ovsbr0ip link Set dev Docker0 downip link del Dev docker0#=============configure kbr0 by:v===== Online Some versions will be less parameters, Centos7 will error Oh =====cat >>/etc/sysconfig/network-scripts/ifcfg-kbr0 << vdevice=kbr0onboot=yesbootproto=staticipaddr =172.17.2.1netmask=255.255.255.0gateway=172.17.2.254userctl=notype=bridgeipv6init=novcat >>/etc/sysconfig /network-scripts/route-ens32 <<v172.17.2.0/24 via 192.168.17.128 Dev eno16777736vsystemctl restart Network.servicesystemctl Stop Docker.service#===============================configure Docker network====by:v===== Cat >>/etc/systemd/system/docker.service.d/docker.conf<< v[Service]execstart=execstart=/usr/bin/docker daemon-h fd://-B kbr0vchmod +x/etc/rc.d/rc.localcat >>/etc/rc.d/  rc.local<< Vip Route del defaultip route add default via 192.168.17.2 dev $ETHNAMEbrctl addif kbr0 ovsbr0v systemctl Start Docker.service

Container A can ping the HOST2 container A. HOST1 can be logged into the HOST2 container using SSH. So you just need to point the route to the container outside.

Ps:

1, in the Docker run when the cmd will overwrite dockerfile cmd that, if you need to overwrite can start sshd in the container/usr/sbin/sshd-d.

2, Benbovin OvS for the bug fixed before 2.5, so do not need to modify the spec file.

3, Centos7 or Docker 1.11 version of the Docker bound NIC Path is/etc/systemd/system/docker.service.d/docker.conf. The instructions for the system folder are started with the systems. And the inside of the Execstart can look at the official document rules, must be empty to define one.

4, the gateway (using IP route view) default gateway for KBR0 defined gateway, here need to remove the replacement gateway, or host and container can not be out of the network.

5, Brctl addif Ovsbr0 added to kbr0 this bridge. Restart the network service will disappear, so do not restart the service, or restart the system, here we add to rc.local Centos7 rc.local This is not execute permissions so need chmod +x.

6, here for GRE0 mode, if you want to convert to Vxlan modify the corresponding type can, the specific difference please Baidu.

7, the above script is only suitable for CENTOS7, but the process is the same.

Please leave a message if you have any questions!

CENTOS7 Docker Multi-host container interconnect-based on OvS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.