{"id":1327,"date":"2017-01-28T21:27:40","date_gmt":"2017-01-28T13:27:40","guid":{"rendered":"http:\/\/www.royalwzy.com\/?p=1327"},"modified":"2017-01-28T21:31:50","modified_gmt":"2017-01-28T13:31:50","slug":"mysql-on-docker-multi-host-networking-for-mysql-containers","status":"publish","type":"post","link":"http:\/\/www.royalwzy.com\/?p=1327","title":{"rendered":"MySQL on Docker: Multi-Host Networking for MySQL Containers"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4f1a\u5728\u57fa\u4e8eCalico\u7f51\u7edc\u9a71\u52a8\u7684\u591a\u53f0\u5bbf\u4e3b\u673a\u4e0a\u90e8\u7f72MySQL Replication;<\/p>\n<p>Docker v1.12\u7248\u672c\u7684Swarm\u6a21\u5f0f\u662f\u4e00\u4e2a\u539f\u751f\u7684\u7f16\u6392\u5de5\u5177,\u7136\u800c\u5b83\u4e0d\u652f\u6301\u5176\u5b83\u7684\u7f51\u7edc\u63d2\u4ef6(\u6bd4\u5982Calico,Weave,Flannel);\u5982\u679c\u60f3\u8981\u8fd0\u884c\u8fd9\u4e9b\u7f51\u7edc\u63d2\u4ef6,\u5fc5\u987b\u5728Swarm\u6a21\u5f0f\u5916\u9762\u8fd0\u884c,\u5e76\u4e14\u4f7f\u7528\u5176\u5b83\u7684\u7f16\u6392\u5de5\u5177(Kubernetes, Mesos \u6216\u8005 Docker Swarm);<\/p>\n<p>Calico\u4e0d\u80fd\u88ab\u79f0\u4e3a&#8221;overlay network&#8221;,\u8fd9\u610f\u5473\u7740\u5b83\u4e0d\u4f1a\u5c06\u4e00\u4e2a\u6570\u636e\u5305\u5c01\u88c5\u5728\u53e6\u4e00\u4e2a\u6570\u636e\u5305\u4e2d;\u5b83\u4f7f\u7528\u7eaf\u7b2c3\u5c42\u65b9\u6cd5,\u5e76\u907f\u514d\u4e0e\u7b2c2\u5c42\u89e3\u51b3\u65b9\u6848\u76f8\u5173\u8054\u7684\u6570\u636e\u5305\u5c01\u88c5,\u8fd9\u7b80\u5316\u4e86\u8bca\u65ad,\u51cf\u5c11\u4e86\u4f20\u8f93\u5f00\u9500\u5e76\u63d0\u9ad8\u4e86\u6027\u80fd;Calico\u8fd8\u5b9e\u73b0BGP\u534f\u8bae,\u7528\u4e8e\u4e0e\u7eafIP\u7f51\u7edc\u76f8\u7ed3\u5408\u7684\u8def\u7531,\u4ece\u800c\u5141\u8bb8\u865a\u62df\u7f51\u7edc\u7684\u56e0\u7279\u7f51\u6269\u5c55;<\/p>\n<p>&#8212; \u6d4b\u8bd5\u73af\u5883,\u4e09\u53f0\u5bbf\u4e3b\u673a\u90fd\u5b89\u88c5\u4e86Docker\u5f15\u64cev1.12.3\u7248\u672c;<br \/>\n192.168.10.201    docker1.htsec.com    docker1<br \/>\n192.168.10.202    docker2.htsec.com    docker2<br \/>\n192.168.10.203    docker3.htsec.com    docker3<\/p>\n<p>&#8212; Key-Value\u5b58\u50a8(etcd);<br \/>\netcd\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u5206\u5e03\u5f0f\u952e\u503c\u5b58\u50a8,\u4e3b\u8981\u7528\u4e8e\u914d\u7f6e\u5171\u4eab\u548c\u670d\u52a1\u53d1\u73b0;\u4e00\u4e2a\u7b80\u5355\u7684\u5e94\u7528\u573a\u666f\u662f\u5b58\u50a8\u6570\u636e\u5e93\u7684\u8fde\u63a5\u6216\u8005\u662f\u7279\u6027\u6807\u793a;<\/p>\n<p>Calico\u9700\u8981etcd\u8fdb\u884c\u64cd\u4f5c;etcd\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u5b9e\u4f8b\u8fdb\u884c\u96c6\u7fa4,\u4f8b\u5b50\u4e2d\u4f7f\u7528\u4e09\u4e2a\u8282\u70b9\u7684etcd\u96c6\u7fa4\u6765\u4fdd\u8bc1\u9ad8\u53ef\u7528\u6027;<\/p>\n<p>1.\u5206\u522b\u5b89\u88c5etcd\u5305;<br \/>\nyum install -y etcd;<\/p>\n<p>2.\u4fee\u6539\u76f8\u5e94\u7684\u914d\u7f6e\u6587\u4ef6;<br \/>\n[root@docker1 ~]# vi \/etc\/etcd\/etcd.conf<br \/>\nETCD_NAME=etcd1<br \/>\nETCD_LISTEN_PEER_URLS=&#8221;http:\/\/0.0.0.0:2380&#8243;<br \/>\nETCD_LISTEN_CLIENT_URLS=&#8221;http:\/\/0.0.0.0:2379&#8243;<br \/>\nETCD_INITIAL_ADVERTISE_PEER_URLS=&#8221;http:\/\/192.168.10.201:2380&#8243;<br \/>\nETCD_INITIAL_CLUSTER=&#8221;etcd1=http:\/\/192.168.10.201:2380,etcd2=http:\/\/192.168.10.202:2380,etcd3=http:\/\/192.168.10.203:2380&#8243;<br \/>\nETCD_INITIAL_CLUSTER_STATE=&#8221;new&#8221;<br \/>\nETCD_INITIAL_CLUSTER_TOKEN=&#8221;etcd-cluster-1&#8243;<br \/>\nETCD_ADVERTISE_CLIENT_URLS=&#8221;http:\/\/0.0.0.0:2379&#8243;<\/p>\n<p>[root@docker2 ~]# vi \/etc\/etcd\/etcd.conf<br \/>\nETCD_NAME=etcd2<br \/>\nETCD_LISTEN_PEER_URLS=&#8221;http:\/\/0.0.0.0:2380&#8243;<br \/>\nETCD_LISTEN_CLIENT_URLS=&#8221;http:\/\/0.0.0.0:2379&#8243;<br \/>\nETCD_INITIAL_ADVERTISE_PEER_URLS=&#8221;http:\/\/192.168.10.202:2380&#8243;<br \/>\nETCD_INITIAL_CLUSTER=&#8221;etcd1=http:\/\/192.168.10.201:2380,etcd2=http:\/\/192.168.10.202:2380,etcd3=http:\/\/192.168.10.203:2380&#8243;<br \/>\nETCD_INITIAL_CLUSTER_STATE=&#8221;new&#8221;<br \/>\nETCD_INITIAL_CLUSTER_TOKEN=&#8221;etcd-cluster-1&#8243;<br \/>\nETCD_ADVERTISE_CLIENT_URLS=&#8221;http:\/\/0.0.0.0:2379&#8243;<\/p>\n<p>[root@docker3 ~]# vi \/etc\/etcd\/etcd.conf<br \/>\nETCD_NAME=etcd3<br \/>\nETCD_LISTEN_PEER_URLS=&#8221;http:\/\/0.0.0.0:2380&#8243;<br \/>\nETCD_LISTEN_CLIENT_URLS=&#8221;http:\/\/0.0.0.0:2379&#8243;<br \/>\nETCD_INITIAL_ADVERTISE_PEER_URLS=&#8221;http:\/\/192.168.10.203:2380&#8243;<br \/>\nETCD_INITIAL_CLUSTER=&#8221;etcd1=http:\/\/192.168.10.201:2380,etcd2=http:\/\/192.168.10.202:2380,etcd3=http:\/\/192.168.10.203:2380&#8243;<br \/>\nETCD_INITIAL_CLUSTER_STATE=&#8221;new&#8221;<br \/>\nETCD_INITIAL_CLUSTER_TOKEN=&#8221;etcd-cluster-1&#8243;<br \/>\nETCD_ADVERTISE_CLIENT_URLS=&#8221;http:\/\/0.0.0.0:2379&#8243;<\/p>\n<p>3.\u5206\u522b\u542f\u52a8docker1,docker2\u548cdocker3\u4e0a\u7684etcd\u670d\u52a1;<br \/>\nsystemctl start etcd.service<br \/>\nsystemctl enable etcd.service<\/p>\n<p>4.\u68c0\u67e5etcd\u96c6\u7fa4\u72b6\u6001;<br \/>\n[root@docker1 ~]# etcdctl member list<br \/>\n29868e609fc76b11: name=etcd3 peerURLs=http:\/\/192.168.10.203:2380 clientURLs=http:\/\/0.0.0.0:2379 isLeader=false<br \/>\n6ebf0a399d4f3850: name=etcd1 peerURLs=http:\/\/192.168.10.201:2380 clientURLs=http:\/\/0.0.0.0:2379 isLeader=true<br \/>\naf11bb15f5145af9: name=etcd2 peerURLs=http:\/\/192.168.10.202:2380 clientURLs=http:\/\/0.0.0.0:2379 isLeader=false<br \/>\n[root@docker1 ~]# etcdctl cluster-health<br \/>\nmember 29868e609fc76b11 is healthy: got healthy result from http:\/\/0.0.0.0:2379<br \/>\nmember 6ebf0a399d4f3850 is healthy: got healthy result from http:\/\/0.0.0.0:2379<br \/>\nmember af11bb15f5145af9 is healthy: got healthy result from http:\/\/0.0.0.0:2379<br \/>\ncluster is healthy<\/p>\n<p>&#8212; \u5b89\u88c5Calico;<br \/>\n1.\u4e0b\u8f7dCalico\u5e76\u4f7f\u5b83\u53ef\u6267\u884c;<br \/>\n$ wget http:\/\/www.projectcalico.org\/builds\/calicoctl -P \/usr\/local\/bin<br \/>\n$ chmod +x \/usr\/local\/bin\/calicoctl<\/p>\n<p>2.\u5728docker1\u4e0a\u521b\u5efacalico\u8282\u70b9,\u6307\u5b9aDocker\u5bbf\u4e3b\u673a\u7684IP\u5730\u5740;<\/p>\n<p>docker run -d &#8211;restart=always &#8211;net=host &#8211;privileged &#8211;name=calico-node \\<br \/>\n -e HOSTNAME=docker1.htsec.com -e IP=192.168.10.201 \\<br \/>\n -e IP6= -e CALICO_NETWORKING_BACKEND=bird -e AS= -e NO_DEFAULT_POOLS= \\<br \/>\n -e ETCD_AUTHORITY=127.0.0.1:2379 -e ETCD_SCHEME=http \\<br \/>\n -v \/var\/log\/calico:\/var\/log\/calico -v \/lib\/modules:\/lib\/modules \\<br \/>\n -v \/var\/run\/calico:\/var\/run\/calico \\<br \/>\n calico\/node:latest<\/p>\n<p>docker run -d &#8211;restart=always &#8211;net=host &#8211;privileged &#8211;name=calico-node \\<br \/>\n -e HOSTNAME=docker2.htsec.com -e IP=192.168.10.202 \\<br \/>\n -e IP6= -e CALICO_NETWORKING_BACKEND=bird -e AS= -e NO_DEFAULT_POOLS= \\<br \/>\n -e ETCD_AUTHORITY=127.0.0.1:2379 -e ETCD_SCHEME=http \\<br \/>\n -v \/var\/log\/calico:\/var\/log\/calico -v \/lib\/modules:\/lib\/modules \\<br \/>\n -v \/var\/run\/calico:\/var\/run\/calico \\<br \/>\n calico\/node:latest<\/p>\n<p>docker run -d &#8211;restart=always &#8211;net=host &#8211;privileged &#8211;name=calico-node \\<br \/>\n -e HOSTNAME=docker3.htsec.com -e IP=192.168.10.203 \\<br \/>\n -e IP6= -e CALICO_NETWORKING_BACKEND=bird -e AS= -e NO_DEFAULT_POOLS= \\<br \/>\n -e ETCD_AUTHORITY=127.0.0.1:2379 -e ETCD_SCHEME=http \\<br \/>\n -v \/var\/log\/calico:\/var\/log\/calico -v \/lib\/modules:\/lib\/modules \\<br \/>\n -v \/var\/run\/calico:\/var\/run\/calico \\<br \/>\n calico\/node:latest<\/p>\n<p>TODO:<br \/>\nhttp:\/\/severalnines.com\/blog\/mysql-docker-multi-host-networking-mysql-containers-part-2-calico<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4f1a\u5728\u57fa\u4e8eCalico\u7f51\u7edc\u9a71\u52a8\u7684\u591a\u53f0\u5bbf\u4e3b\u673a\u4e0a\u90e8\u7f72MySQL Replication; Docker v1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[27],"class_list":["post-1327","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql"],"_links":{"self":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/1327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1327"}],"version-history":[{"count":1,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/1327\/revisions"}],"predecessor-version":[{"id":1328,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/1327\/revisions\/1328"}],"wp:attachment":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1327"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}