RHEL7RC+EPELçDockerã®åæã§è§£èª¬ãã¾ããRHEL7RCãæå°æ§æã§å ¥ãã¦ã次ã®æé ã§Dockerãå°å ¥ãã¾ãã
# yum -y install bridge-utils net-tools # yum -y install http://download.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-0.1.noarch.rpm # yum -y install docker-io # systemctl enable docker.service
Dockerãè¨å®ããiptablesã®å 容ãè¦ãããã«ï¼è¦ãããããããã«ï¼ãfirewalldãåæ¢ããä¸ã§dockerãµã¼ãã¹ãèµ·åãã¾ãã
# systemctl stop firewalld.service # systemctl mask firewalld.service # systemctl restart docker.service
ã¾ãã¯æ®éã®èª¬æ
dockerãµã¼ãã¹ãèµ·åããã¨ãã³ã³ããæ¥ç¶ç¨ã®ä»®æ³ããªãã¸ãdocker0ããç¨æããã¾ãã
# brctl show bridge name bridge id STP enabled interfaces docker0 8000.56847afe9799 no # ifconfig docker0 docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.17.42.1 netmask 255.255.0.0 broadcast 0.0.0.0 inet6 fe80::5484:7aff:fefe:9799 prefixlen 64 scopeid 0x20<link> ether 56:84:7a:fe:97:99 txqueuelen 0 (Ethernet) RX packets 10956 bytes 600362 (586.2 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 19642 bytes 27720858 (26.4 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ãã®ããªãã¸ã¯ãç©çNICã¨ã¯æ¥ç¶ãã¦ããªãã®ã§ãå¤é¨ãããã¯ã¼ã¯ã¨ã³ã³ãããç´æ¥ã«éä¿¡ããããã®ãã®ã§ã¯ããã¾ãããiptablesãè¦ãã¨æ¬¡ã®ããã«ãªã£ã¦ãã¾ããè¥å¹²ãå¤ãªã«ã¼ã«è¨å®ã§ãããå°ãªãã¨ããdocker0ã«æ¥ç¶ããã³ã³ããããå¤é¨ãããã¯ã¼ã¯ã¸ã¯ãIPãã¹ã«ã¬ã¼ãã§åºã¦ãããããã«ãªã£ã¦ãã¾ãã
# iptables-save | grep -v "^#" *nat :PREROUTING ACCEPT [1:100] :INPUT ACCEPT [1:100] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] :DOCKER - [0:0] -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER -A POSTROUTING -s 172.17.0.0/16 ! -d 172.17.0.0/16 -j MASQUERADE COMMIT *filter :INPUT ACCEPT [133:10308] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [72:9600] -A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A FORWARD -i docker0 ! -o docker0 -j ACCEPT -A FORWARD -i docker0 -o docker0 -j ACCEPT COMMIT
CentOS6ã®ã¤ã¡ã¼ã¸ããã¦ã³ãã¼ããã¦ãã³ã³ãããèµ·åãã¦ã¿ã¾ãã
# docker pull centos # docker run -it centos /bin/bash
ã³ã³ããå é¨ã«ã¯eth0ããã£ã¦ãå¾ã§ã¿ãããã«ãããã¯ããªãã¸ãdocker0ãã«æ¥ç¶ããã¦ãã¾ããdocker0ã¨åããµããããã®IPãå²ãå½ã¦ããã¦ãããdocker0ã«pingãå±ãã¾ããIPãã¹ã«ã¬ã¼ãã§ã¤ã³ã¿ã¼ãããã¾ã§åºã¦è¡ããã¨ãã§ãã¾ãã
bash-4.1# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 26:B7:4A:7F:01:BC inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::24b7:4aff:fe7f:1bc/64 Scope:Link UP BROADCAST RUNNING MTU:1500 Metric:1 RX packets:7 errors:0 dropped:2 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:558 (558.0 b) TX bytes:648 (648.0 b) bash-4.1# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.17.42.1 0.0.0.0 UG 0 0 0 eth0 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 bash-4.1# yum -y install iputils traceroute bash-4.1# ping -c1 172.17.42.1 PING 172.17.42.1 (172.17.42.1) 56(84) bytes of data. 64 bytes from 172.17.42.1: icmp_seq=1 ttl=64 time=0.104 ms --- 172.17.42.1 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.104/0.104/0.104/0.000 ms bash-4.1# traceroute -I 8.8.8.8 traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets 1 172.17.42.1 (172.17.42.1) 0.096 ms 0.018 ms 0.012 ms 2 192.168.122.1 (192.168.122.1) 0.234 ms 0.212 ms 0.204 ms ...ï¼ä¸ç¥ï¼... 15 209.85.243.156 (209.85.243.156) 72.423 ms 71.965 ms 71.918 ms 16 209.85.244.25 (209.85.244.25) 90.231 ms 89.823 ms 89.788 ms 17 * * * 18 google-public-dns-a.google.com (8.8.8.8) 70.944 ms 70.928 ms 71.182 ms
ã³ã³ãããèµ·åããã¾ã¾ãå¥ç«¯æ«ãããã¹ãLinuxã«åãã°ã¤ã³ãã¦ãããªãã¸docker0ãè¦ãã¨ã³ã³ããå ã®eth0ã®çå²ãã®vethãæ¥ç¶ããã¦ãã¾ãã
# brctl show bridge name bridge id STP enabled interfaces docker0 8000.56847afe9799 no veth452d # ifconfig veth452d veth452d: flags=67<UP,BROADCAST,RUNNING> mtu 1500 inet6 fe80::874:87ff:fe84:6aa2 prefixlen 64 scopeid 0x20<link> ether 0a:74:87:84:6a:a2 txqueuelen 1000 (Ethernet) RX packets 4479 bytes 310641 (303.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 7727 bytes 10625737 (10.1 MiB) TX errors 0 dropped 1 overruns 0 carrier 0 collisions 0
vethï¼Virtual Ethernetï¼ã¯ãã¯ãã¹ã±ã¼ãã«ã§ç´çµãããä»®æ³NICã®ãã¢ãä½ãLinuxã®æ©è½ã§ããã³ãçµµã«ããã¨ãããªç¶æ ã«ãªãã¾ãã
ã¡ãªã¿ã«ãã³ã³ããå ã®IPã¢ãã¬ã¹ãã©ã®ããã«è¨å®ããã¦ãããæ°ã«ãªãããç¥ãã¾ããã
ãDHCPãããªãã®ï¼ã
ã¨æã£ãããªãã
æ®å¿µããããããOpenStackã®åå¼·ã®ãéãã§ãããããããã
ã³ã³ããã®ä¸ã§åãã¦ããã®ã¯ãbashã ãã§ããã©ãã«ãDHCPã¯ã©ã¤ã¢ã³ãã¯ããã¾ããã
bash-4.1# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 05:45 ? 00:00:00 /bin/bash root 79 1 0 06:13 ? 00:00:00 ps -ef
å®ã¯ããã®ã¢ãã¬ã¹ã¯ãDockerãã³ã³ãããä½æããéã«ã³ã³ããã®ä¸ã«å ¥ãè¾¼ãã§ãç¬èªã«IPã¢ãã¬ã¹ãè¨å®ãã¦ãã¾ããããå°ãæ£ç¢ºã«ããã¨ããã®ã³ã³ããã®ããããã¯ã¼ã¯ãã¼ã ã¹ãã¼ã¹ï¼netnsï¼ãã«å ¥ãè¾¼ãã§è¨å®ãã¦ãã¾ãã
ã³ã³ããã®netnsã«æ½ãè¾¼ã
ããã§ã¯ãã¡ãã£ã¨ãããéã³ã§ããã¹ãLinuxããã³ã³ããå ã®netnsã«æ½ãè¾¼ãã§ã¿ã¾ããããã³ã³ããã¯ãããã»ã¹ã®å®è¡ç°å¢ãåé¢ããæ©è½ã§ãããããããã¯ã¼ã¯ç°å¢ã®åé¢ï¼netnsãããã¡ã¤ã«ã·ã¹ãã ã®åé¢=mntnsããããã»ã¹ãã¼ãã«ã®åé¢=pidnsãã®ããã«åé¢ãããªã½ã¼ã¹ãã¨ã«å¥ã ã®ãã¼ã ã¹ãã¼ã¹æ©è½ã§åé¢ãã¦ãã¾ãããããã£ã¦ããã¹ãLinuxããã³ã³ããå ã®netnsã«æ½ãè¾¼ãã¨ããã¡ã¤ã«ã·ã¹ãã ãããã»ã¹ãã¼ãã«ã¯ã³ã³ããã®å¤å´ï¼ãã¹ãLinuxï¼ãªã®ã«ããããã¯ã¼ã¯è¨å®ã ãã³ã³ããã®ä¸ãè¦ãããã¨ããé¢ç½ãç¶æ ã«ãªãã¾ãã
netnsãæä½ããå®çªãã¼ã«ã¯ipã³ãã³ãã§ããããã®ã³ã³ããã®netnsãipã³ãã³ãã§ç®¡çã§ããããã«ã¡ãã£ã¨ããä»è¾¼ã¿ããã¾ããã¾ããã³ã³ããå ã§èµ·åãã¦ããbashã®ãã¹ãLinuxä¸ã§ã®PIDã調ã¹ã¾ããdockerãã¼ã¢ã³ã®åããã»ã¹ã®bashãæ¢ãã°OKã§ãã
# ps -ef | grep "docker -[d]" root 9498 1 0 13:17 ? 00:00:02 /usr/bin/docker -d # ps -ef | grep bash | grep 9498 root 10170 9498 0 18:00 pts/2 00:00:00 /bin/bash
ãã®ããã»ã¹ã®/procæ å ±ã®ä¸ã«ããã®ããã»ã¹ãå±ããnetnsãæä½ããFDã¸ã®ãªã³ã¯ãããã¾ãã
# ls -l /proc/10170/ns/net lrwxrwxrwx. 1 root root 0 4æ 24 18:01 /proc/10170/ns/net -> net:[4026532160]
/var/run/netns/以ä¸ããã·ã³ããªãã¯ãªã³ã¯ãå¼µãã¨ãipã³ãã³ã管çä¸ã®netnsã¨ãã¦èªèããã¾ãã
# ln -s /proc/10170/ns/net /var/run/netns/hoge # ip netns hoge
ããã¾ã§ããã°ãNeutronã®ãããã°ã§éããip netnsãé§ä½¿ãã¦ããæ¾é¡ã§ããããã®netnså é¨ã§bashãèµ·åãã¾ãã
# ip netns exec hoge bash
次ã®ããã«ã³ã³ããå ã®ãããã¯ã¼ã¯ç°å¢ã丸è¦ãã§ãã
# ifconfig eth0 eth0: flags=67<UP,BROADCAST,RUNNING> mtu 1500 inet 172.17.0.2 netmask 255.255.0.0 broadcast 0.0.0.0 inet6 fe80::8874:a6ff:fe1c:1b2a prefixlen 64 scopeid 0x20<link> ether 8a:74:a6:1c:1b:2a txqueuelen 1000 (Ethernet) RX packets 8 bytes 648 (648.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 8 bytes 648 (648.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.17.42.1 0.0.0.0 UG 0 0 0 eth0 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
ããã¾ã§ãnetnsã ããåãæ¿ãã¦ããã®ã§ããããã¯ã¼ã¯ä»¥å¤ã®ç°å¢ï¼ãã¡ã¤ã«ã·ã¹ãã ãããã»ã¹ãã¼ãã«ï¼ã¯ããã¹ãLinuxã¨åãç¶æ ã§ããç¹ã«æ³¨æãã¦ãã ãããbashãçµäºããã¨ããã¹ãLinuxã®ãããã¯ã¼ã¯ç°å¢ã«æ»ãã¾ãã
# exit
Dockerãã³ã³ãããä½ãã¿ã¤ãã³ã°ã§ããã¹ãLinuxå´ãã次ã®ãããªæä½ããã¦ãã³ã³ããå ã®IPã¢ãã¬ã¹ãè¨å®ãã¦ãããã®ã¨èãããã¾ãã
ã»ãã¹ãLinuxå´ã§vethãã¢ãä½æããã
ã»ãã®çå²ããã³ã³ããã®netnsã«çªã£è¾¼ãã§ãã³ã³ããããeth0ã¨ãã¦è¦ããããã«ããã
ã»ã³ã³ããã®netnsã«å
¥ãè¾¼ãã§ãã³ã³ããå
ã®eth0ã«IPã¢ãã¬ã¹ãã»ããããã
ã³ã³ããã«NICã追å ãã
åè¿°ã®ææ³ãå¿ç¨ããã¨ãèµ·åä¸ã®ã³ã³ããã«å¯¾ãã¦ããã¹ãLinuxä¸ã§vethãã¢ãä½æãã¦ãå¾ããã³ã³ããã«NICã追å ãããã¨ãã§ãã¦ãã¾ãæ°ããã¾ããè«ãã証æ ã§ãå®éã«ãã£ã¦ã¿ã¾ãããã
ç®æ¨ã¯ãããªæãã§ããããªãã¸ãbr0ããå®ã«æµ®ãã¦ãã¾ããããããç©çNICã«æ¥ç¶ããã°ãã³ã³ããã¨å¤é¨ãããã¯ã¼ã¯ãç´çµãããã¨ãå¯è½ã«ãªãã¾ãã
ã¾ãããªãã¸ãbr0ããä½æãã¾ãã
# brctl addbr br0 # ip link set br0 up # ip addr add 192.168.200.1/24 dev br0
ç¶ãã¦ãvethã®ãã¢ãä½æãã¾ããããã§ã¯ã[veth-host]----[veth-guest]ã¨ããååã§ä½æããä¸ã§ããã¹ãå´ï¼veth-hostï¼ãbr0ã«æ¥ç¶ãã¾ãã
# ip link add name veth-host type veth peer name veth-guest # ip link set veth-host up # brctl addif br0 veth-host # brctl show br0 bridge name bridge id STP enabled interfaces br0 8000.b638185b3372 no veth-host # ifconfig veth-host veth-host: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether b6:38:18:5b:33:72 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 # ifconfig veth-guest veth-guest: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether d6:52:68:0a:1d:0e txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ãã®æç¹ã§ã¯ã²ã¹ãå´ã®veth-guestãè¦ãã¦ãã¾ããã次ã®ã³ãã³ãã§ã³ã³ããã®netnsã«çªã£è¾¼ãã¨ããã¹ãããã¯è¦ããªããªãã¾ãã
# ip link set veth-guest netns hoge # ifconfig veth-guest veth-guest: error fetching interface information: Device not found
éã«ã³ã³ããå´ã§ãveth-guestãè¦ããããã«ãªã£ã¦ãã¾ãã
bash-4.1# ifconfig veth-guest veth-guest Link encap:Ethernet HWaddr D6:52:68:0A:1D:0E BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
ç¶ãã¦ãã³ã³ããå ã®NICã®è¨å®ãè¡ãã¾ããããããå ã»ã©ã®ãip netns execããé§ä½¿ãã¦ãã¹ãå´ã§è¡ãã¾ããã¾ããã³ã³ããå ã§ã®ããã¤ã¹åããeth1ãã«å¤æ´ãã¾ãã
# ip netns exec hoge ip link set veth-guest name eth1
ãeth1ãã«å¯¾ããIPã®è¨å®ãè¡ãã¾ããã«ã¼ãã£ã³ã°ãã¼ãã«ãå¤æ´ãã¦ãeth1å´ãããã©ã«ãã²ã¼ãã¦ã§ã¤ã«ãã¾ãã
# ip netns exec hoge ip addr add 192.168.200.101/24 dev eth1 # ip netns exec hoge ip link set eth1 up # ip netns exec hoge ip route delete default # ip netns exec hoge ip route add default via 192.168.200.1
ããã§å®æã§ãããã¹ãããpingãéãã¾ãã
# ping -c1 192.168.200.101 PING 192.168.200.101 (192.168.200.101) 56(84) bytes of data. 64 bytes from 192.168.200.101: icmp_seq=1 ttl=64 time=0.082 ms --- 192.168.200.101 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.082/0.082/0.082/0.000 ms
ã³ã³ããå ã§ã¯æ¬¡ã®ããã«è¨å®ããã¦ãã¾ãã
bash-4.1# ifconfig eth1 eth1 Link encap:Ethernet HWaddr D6:52:68:0A:1D:0E inet addr:192.168.200.101 Bcast:0.0.0.0 Mask:255.255.255.0 inet6 addr: fe80::d452:68ff:fe0a:1d0e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:648 (648.0 b) bash-4.1# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.200.1 0.0.0.0 UG 0 0 0 eth1 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 192.168.200.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
ãã°ãããããããã
ã¡ãªã¿ã«ã³ã³ãããåæ¢ããã¨ãå¾ãã追å ããvethãã¢ããã¾ãæ¶ãã¦ãããããã§ãããã ãã/var/run/netns以ä¸ã®ã·ã³ããªãã¯ãªã³ã¯ãæ®ãã®ã§ãããã¯æã§åé¤ããå¿ è¦ãããã¾ããããã¯ããip netnsãã§æä½ããããã ãã«å¿ è¦ãªã®ã§ãä¸è¨ã®è¨å®ãçµãã£ãã¿ã¤ãã³ã°ã§ããã«åé¤ãã¦ãæ§ããªãã§ãããã
ã§ãããã
å®ã¯ãä¸è¨ã®ä½æ¥ãå ¨é¨ãã£ã¦ãããã·ã§ã«ã¹ã¯ãªããï¼pipeworkï¼ããã§ã«å ¬éããã¦ã¾ããèå³ã®ããæ¹ã¯ãã¹ã¯ãªããã®ä¸èº«ãèªã¿è§£ãã¦ã¿ã¦ãã ããã