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
|
{
"services"
: [
{
"id"
:
"redisnode1"
,
"name"
:
"redis"
,
"tags"
: [
"master"
],
"address"
:
"192.168.1.241"
,
"port"
: 6379,
"checks"
: [
{
"script"
:
"/usr/local/sbin/redis-cli -h 192.168.1.241 -p 6379 info | grep role:master || exit 2"
,
"interval"
:
"5s"
}
]
},
{
"id"
:
"redisnode2"
,
"name"
:
"redis"
,
"tags"
: [
"master"
],
"address"
:
"192.168.1.242"
,
"port"
: 6379,
"checks"
: [
{
"script"
:
"/usr/local/sbin/redis-cli -h 192.168.1.242 -p 6379 info | grep role:master || exit 2"
,
"interval"
:
"5s"
}
]
},
{
"id"
:
"redisnode3"
,
"name"
:
"redis"
,
"tags"
: [
"master"
],
"address"
:
"192.168.1.243"
,
"port"
: 6379,
"checks"
: [
{
"script"
:
"/usr/local/sbin/redis-cli -h 192.168.1.243 -p 6379 info | grep role:master || exit 2"
,
"interval"
:
"5s"
}
]
}
]
}
|
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
|
mkdir
-p
/usr/local/consul/data
/usr/local/consul/config
cat
>
/usr/local/consul/config/rediscluster
.json<<eof
{
"services"
: [
{
"id"
:
"redisnode1"
,
"name"
:
"redis"
,
"tags"
: [
"master"
],
"address"
:
"192.168.1.241"
,
"port"
: 6379,
"checks"
: [
{
"script"
:
"/usr/local/sbin/redis-cli -h 192.168.1.241 -p 6379 info | grep role:master || exit 2"
,
"interval"
:
"5s"
}
]
},
{
"id"
:
"redisnode2"
,
"name"
:
"redis"
,
"tags"
: [
"master"
],
"address"
:
"192.168.1.242"
,
"port"
: 6379,
"checks"
: [
{
"script"
:
"/usr/local/sbin/redis-cli -h 192.168.1.242 -p 6379 info | grep role:master || exit 2"
,
"interval"
:
"5s"
}
]
},
{
"id"
:
"redisnode3"
,
"name"
:
"redis"
,
"tags"
: [
"master"
],
"address"
:
"192.168.1.243"
,
"port"
: 6379,
"checks"
: [
{
"script"
:
"/usr/local/sbin/redis-cli -h 192.168.1.243 -p 6379 info | grep role:master || exit 2"
,
"interval"
:
"5s"
}
]
}
]
}
eof
/bin/consul
agent -advertise=$(
ifconfig
$(route -n |
awk
'/^0.0.0.0/ && /UG/ {print $NF}'
) |
grep
inet |
egrep
-
v
"(inet6|127.0.0.1)"
|
cut
-d
":"
-f2 |
cut
-d
" "
-f1) -bind=$(
ifconfig
$(route -n |
awk
'/^0.0.0.0/ && /UG/ {print $NF}'
) |
grep
inet |
egrep
-
v
"(inet6|127.0.0.1)"
|
cut
-d
":"
-f2 |
cut
-d
" "
-f1) -data-
dir
=
/usr/local/consul/data
-config-
dir
=
/usr/local/consul/config
-
join
192.168.1.245
|
1
2
|
consul info -rpc-addr=192.168.1.245:8400
consul members -rpc-addr=192.168.1.245:8400
|