????????etcd???
??????????etcd????????????????????????????????????????£?????????IP???????δ?????????????£????????etcd??????????????????etcd???????????У????????????????????????????????????
????????????????????????? ????????????? etcd clustering
????· ???????
????· etcd????
????· DNS????
???????潫????????????????etcd???:

???????????
???????????????????????????????????????????С???????????????????????????????ó???????????????????????????????????????У?
????ETCD_INITIAL_CLUSTER="infra0=http://10.0.1.10:2380??infra1=http://10.0.1.11:2380??infra2=http://10.0.1.12:2380"
????ETCD_INITIAL_CLUSTER_STATE=new
????--initial-cluster infra0=http://10.0.1.10:2380??infra1=http://10.0.1.11:2380??infra2=http://10.0.1.12:2380
????--initial-cluster-state new
?????????????????????±?????etcd??
$ etcd --name infra0 --initial-advertise-peer-urls http://10.0.1.10:2380
--listen-peer-urls http://10.0.1.10:2380
--listen-client-urls http://10.0.1.10:2379??http://127.0.0.1:2379
--advertise-client-urls http://10.0.1.10:2379
--initial-cluster-token etcd-cluster-1
--initial-cluster infra0=http://10.0.1.10:2380??infra1=http://10.0.1.11:2380??infra2=http://10.0.1.12:2380
--initial-cluster-state new
$ etcd --name infra1 --initial-advertise-peer-urls http://10.0.1.11:2380
--listen-peer-urls http://10.0.1.11:2380
--listen-client-urls http://10.0.1.11:2379??http://127.0.0.1:2379
--advertise-client-urls http://10.0.1.11:2379
--initial-cluster-token etcd-cluster-1
--initial-cluster infra0=http://10.0.1.10:2380??infra1=http://10.0.1.11:2380??infra2=http://10.0.1.12:2380
--initial-cluster-state new
$ etcd --name infra2 --initial-advertise-peer-urls http://10.0.1.12:2380
--listen-peer-urls http://10.0.1.12:2380
--listen-client-urls http://10.0.1.12:2379??http://127.0.0.1:2379
--advertise-client-urls http://10.0.1.12:2379
--initial-cluster-token etcd-cluster-1
--initial-cluster infra0=http://10.0.1.10:2380??infra1=http://10.0.1.11:2380??infra2=http://10.0.1.12:2380
--initial-cluster-state new
??????--initial-cluster??????????в?????etcd????????????????????????????????????????????????????????????б????
????CONFD
?????????Github??????????????????????
?????????????confd????etcd????nginx?????????
????????Щ?????
????etcdctl set /myapp/database/url db.example.com
????etcdctl set /myapp/database/user rob
?????????????????
????????????????????????????????????????
????sudo mkdir -p /etc/confd/{conf.d??templates}
??????????????????
????????????????????TOML???????????????嶨?塣
????/etc/confd/conf.d/myconfig.toml
????[template]
????src = "myconfig.conf.tmpl"
????dest = "/tmp/myconfig.conf"
????keys = [
????"/myapp/database/url"??
????"/myapp/database/user"??
????]
?????????????????
?????????????????Golang text templates???????
????/etc/confd/templates/myconfig.conf.tmpl
????[myconfig]
????database_url = {{getv "/myapp/database/url"}}
????database_user = {{getv "/myapp/database/user"}}
???????????
????confd??????????????????????????????????????????£?confd??????????и???????????????????????????
????confd -onetime -backend etcd -node http://127.0.0.1:4001
????Note: The metadata api prefix can be defined on the cli?? or as part of your keys in the template toml file.
???????:
????2014-07-08T20:38:36-07:00 confd[16252]: INFO Target config /tmp/myconfig.conf out of sync
????2014-07-08T20:38:36-07:00 confd[16252]: INFO Target config /tmp/myconfig.conf has been updated
?????????????????????
????cat /tmp/myconfig.conf
???????:
????# This a comment
????[myconfig]
????database_url = db.example.com
????database_user = rob
??????????????????nginx???????
??????????????????confd???????????nginx???????
???????????
etcdctl set /myapp/subdomain myapp
etcdctl set /myapp/upstream/app2 "10.0.1.100:80"
etcdctl set /myapp/upstream/app1 "10.0.1.101:80"
etcdctl set /yourapp/subdomain yourapp
etcdctl set /yourapp/upstream/app2 "10.0.1.102:80"
etcdctl set /yourapp/upstream/app1 "10.0.1.103:80"
??????????????
/etc/confd/conf.d/myapp-nginx.toml
[template]
prefix = "/myapp"
src = "nginx.tmpl"
dest = "/tmp/myapp.conf"
owner = "nginx"
mode = "0644"
keys = [
"/subdomain"??
"/upstream"??
]
check_cmd = "/usr/sbin/nginx -t -c {{.src}}"
reload_cmd = "/usr/sbin/service nginx reload"
/etc/confd/conf.d/yourapp-nginx.toml
[template]
prefix = "/yourapp"
src = "nginx.tmpl"
dest = "/tmp/yourapp.conf"
owner = "nginx"
mode = "0644"
keys = [
"/subdomain"??
"/upstream"??
]
check_cmd = "/usr/sbin/nginx -t -c {{.src}}"
reload_cmd = "/usr/sbin/service nginx reload"
???????????
/etc/confd/templates/nginx.tmpl
upstream {{getv "/subdomain"}} {
{{range getvs "/upstream/*"}}
server {{.}};
{{end}}
}
server {
server_name  {{getv "/subdomain"}}.example.com;
location / {
proxy_pass        http://{{getv "/subdomain"}};
proxy_redirect    off;
proxy_set_header  Host             $host;
proxy_set_header  X-Real-IP        $remote_addr;
proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
}
}