目的:实现容器和公司服务器同网段ip,公司服务器为esxi创建的虚拟机
注意:首先需要将公司esxi虚拟系统的主机网络设置为混杂模式
混杂模式:指一台机器能够接收所有经过它的数据流,而不论其目的地址是否是他
1. 登录VMWare vsphere client,找到主机配置中的网络,点击属性
2. 修改网络模式为混杂模式
1、安装docker
[root@Zabbix ~]# rpm -ivh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@Zabbix ~]# rpm --import/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[root@Zabbix ~]# yum -y install docker-io
[root@Zabbix ~]# yum installdevice-mapper-event-libs #防止启动docker时 死锁
[root@Zabbix ~]# service docker restart
[root@Zabbix ~]# service docker status
[root@Zabbix ~]# docker pull centos:6
[root@Zabbix ~]# ip link set dev docker0down #删除以前的网桥,docker0为你启动容器时候自动创建
[root@Zabbix ~]# brctl delbr docker0
[root@Zabbix ~]# cd/etc/sysconfig/network-scripts/
[root@Zabbix network-scripts]# vimifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:6D:DF:B8
TYPE=Ethernet
UUID=0b55c691-24ed-422d-bfbd-16bc03fecda4
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
BRIDGE=br0
vim ifcfg-br0
DEVICE=br0
HWADDR=00:0C:29:6D:DF:B8
TYPE=Bridge
UUID=0b55c691-24ed-422d-bfbd-16bc03fecda4
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.1.104
GATEWAY=192.168.1.1
DNS=114.114.114.114
[root@Zabbix network-scripts]# servicenetwork restart
[root@Zabbix network-scripts]# unzippipework-master.zip
[root@Zabbix network-scripts]# cppipework-master/pipework /usr/local/bin/
[root@Zabbix network-scripts]# cd
#由于6版本中 iproute版本过低,后期分配IP给容器时会报错,所以需要升级
[root@Zabbix ~]# rpm -qa|grep iproute #当前iproute版本
iproute-2.6.32-31.el6.x86_64
[root@Zabbix ~]# yum install -yhttp://rdo.fedorapeople.org/rdo-release.rpm
[root@Zabbix ~]# vim/etc/yum.repos.d/rdo-release.repo
[openstack-queens]
name=OpenStack Queens Repository
baseurl=https://repos.fedorapeople.org/repos/openstack/EOL/openstack-icehouse/epel-6/
skip_if_unavailable=0
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-RDO-kilo
doc
[root@Zabbix ~]# yum repolist
[root@Zabbix ~]# yum install -y iproute
[root@Zabbix ~]# rpm -qa|grep iproute #升级后的iproute版本
iproute-2.6.32-130.el6ost.netns.2.x86_64
[root@Zabbix ~]# docker run -itd --net=none--name test centos:6 /bin/bash #运行容器
[root@Zabbix ~]# pipework br0 test192.168.1.104/[email protected]
[root@Zabbix ~]# docker exec -it test3/bin/bash
[root@5d9a7e86cb62 /]# ifconfig | head -5
eth1 Link encap:Ethernet HWaddrBE:1F:68:72:40:08
inet addr:192.168.1.104 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::bc1f:68ff:fe72:4008/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11266 errors:0 dropped:0 overruns:0 frame:0
[root@5d9a7e86cb62 /]# yum -y installiputils #安装ping命令软件包
[root@5d9a7e86cb62 /]# ping 192.168.1.1 #ping网关
PING 192.168.1.1 (192.168.1.1) 56(84) bytesof data.
64 bytes from 192.168.1.1: icmp_seq=1ttl=254 time=5.53 ms
[root@5d9a7e86cb62 /]# pingwww.baidu.com #到此完成
PING www.a.shifen.com (14.215.177.39)56(84) bytes of data.
64 bytes from 14.215.177.39: icmp_seq=1ttl=55 time=6.36 ms
64 bytes from 14.215.177.39: icmp_seq=2ttl=55 time=7.14 ms