1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
| #confd的安装
wget https://github.com/kelseyhightow ... -0.11.0-linux-amd64
mv confd* /usr/local/bin/confd
chmod +x /usr/local/bin/confd
/usr/local/bin/confd -version
#etcd的安装
wget https://github.com/coreos/etcd/r ... -linux-amd64.tar.gz
tar zxf etcd-v3.1.1-linux-amd64.tar.gz
cd etcd-v3.1.1-linux-amd64
cp etcd* /bin/
/bin/etcd -version
#etcd的启动
mkdir /data/etcd
etcd --name etcdserver --data-dir /data/dir --listen-peer-urls 'http://192.168.2.202:2380' --listen-client-urls 'http://192.168.2.202:2379,http://127.0.0.1:2379' --initial-advertise-peer-urls 'http://192.168.2.202:2380' --advertise-client-urls 'http://192.168.2.202:2379,http://127.0.0.1:2379' &
#confg的配置
mkdir -p /etc/confd/{conf.d,templates}
vim /etc/confd/conf.d/haproxy.toml
[template]
src = "haproxy.cfg.tmpl"
dest = "/etc/haproxy/haproxy.cfg"
keys = [
"/web",
]
reload_cmd = "/etc/init.d/haproxy reload"
/etc/confd/templates/haproxy.cfg.tmpl
global
log 127.0.0.1 local3
maxconn 5000
uid 99
gid 99
daemon
defaults
log 127.0.0.1 local3
mode http
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
frontend webin
bind :80
mode http
{{ $domains := lsdir "/web"}}
{{range $domain := $domains}}
acl is_{{$domain}} hdr(host) -i {{$domain}}
{{end}}
{{range $domain := $domains}}
use_backend {{$domain}}_cluster if is_{{$domain}}
{{end}}
{{range $domain := $domains}}
backend {{$domain}}_cluster
cookie SERVERID insert indirect nocache
{{$servers := printf "/web/%s/*" $domain}}{{range gets $servers}}
server {{base .Key}} {{.Value}} check inter 5000 rise 2 fall 3 weight 1
{{end}}
{{end}}
#启动confd
/usr/local/bin/confd -interval 5 -node '192.168.2.202:2379' -confdir /etc/confd &
|