Skip to content

Commit

Permalink
Merge pull request #261 from khs1994-docker/dev
Browse files Browse the repository at this point in the history
Update ClusterKit Redis Sentinel
  • Loading branch information
khs1994 authored Mar 17, 2018
2 parents 4c69983 + 5c8cace commit fbd2627
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
5 changes: 5 additions & 0 deletions cluster/redis.sentinel/docker-entrypoint.redis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

cat /redis.conf.default > /data/redis.conf

exec docker-entrypoint.sh "$@"
20 changes: 13 additions & 7 deletions cluster/redis.sentinel/docker-entrypoint.sentinel.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/sh

until redis-cli -h redis_sentinel_master_1; do
echo "Redis master is unavailable - sleeping"
sleep 1
done

echo "Redis master is available"

echo "
# Example sentinel.conf
Expand All @@ -23,7 +30,7 @@ echo "
# The port that this sentinel instance will run on
port SENTINEL_PORT
sentinel announce-ip HOST_IP
sentinel announce-ip SENTINEL_HOST_IP
sentinel announce-port SENTINEL_PORT
#
# The above two configuration directives are useful in environments where,
Expand Down Expand Up @@ -69,7 +76,7 @@ dir /data
#
# Note: master name should not include special characters or spaces.
# The valid charset is A-z 0-9 and the three characters ".-_".
sentinel monitor mymaster MASTER_IP MASTER_PORT SENTINEL_NUM
sentinel monitor mymaster SENTINEL_MASTER_IP SENTINEL_MASTER_PORT SENTINEL_NUM
# sentinel auth-pass <master-name> <password>
#
Expand Down Expand Up @@ -201,13 +208,12 @@ sentinel failover-timeout mymaster 180000

sed -i "s!SENTINEL_PORT!${SENTINEL_PORT}!g" /redis.sentinel.conf

sed -i "s!HOST_IP!${HOST_IP}!g" /redis.sentinel.conf
sed -i "s!SENTINEL_HOST_IP!${SENTINEL_HOST_IP}!g" /redis.sentinel.conf

sed -i "s!MASTER_IP!${MASTER_IP}!g" /redis.sentinel.conf
sed -i "s!SENTINEL_MASTER_IP!${SENTINEL_MASTER_IP}!g" /redis.sentinel.conf

sed -i "s!MASTER_PORT!${MASTER_PORT}!g" /redis.sentinel.conf
sed -i "s!SENTINEL_MASTER_PORT!${SENTINEL_MASTER_PORT}!g" /redis.sentinel.conf

sed -i "s!SENTINEL_NUM!${SENTINEL_NUM}!" /redis.sentinel.conf


exec redis-sentinel /redis.sentinel.conf "$@"
exec docker-entrypoint.sh redis-sentinel /redis.sentinel.conf "$@"
4 changes: 2 additions & 2 deletions docker-cluster.redis.master.slave.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ services:
#
# image: khs1994/lnmp-redis:4.0.8
ports:
- "127.0.0.1:21000:21000"
- "21000:21000"
volumes:
- redis_master-data:/data:rw
command: [
Expand Down Expand Up @@ -93,7 +93,7 @@ services:
# image: khs1994/lnmp-redis:4.0.8
#
ports:
- "127.0.0.1:22000:22000"
- "22000:22000"
volumes:
- redis_slave-1-data:/data:rw
command: [
Expand Down
37 changes: 26 additions & 11 deletions docker-cluster.redis.sentinel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ x-common:
# ipv4_address: 172.15.0.105
secrets:
- source: cluster_redis_conf
target: /redis.conf
target: /redis.conf.default
- source: cluster_redis_entrypoint
target: /docker-entrypoint.redis.sh

x-deploy:
&default-deploy
Expand All @@ -51,13 +53,15 @@ x-deploy:
order: stop-first

services:

redis_sentinel_master_1:
<< : *default-common
ports:
- "10000:10000"
entrypoint: /docker-entrypoint.redis.sh
command: [
"redis-server",
"/redis.conf",
"/data/redis.conf",
"--daemonize no",
"--bind 0.0.0.0",
"--port 10000",
Expand Down Expand Up @@ -92,9 +96,10 @@ services:
<< : *default-common
depends_on:
- redis_sentinel_master_1
entrypoint: /docker-entrypoint.redis.sh
command: [
"redis-server",
"/redis.conf",
"/data/redis.conf",
"--daemonize no",
"--bind 0.0.0.0",
"--port 10001",
Expand Down Expand Up @@ -134,9 +139,10 @@ services:
- redis_sentinel_master_1
ports:
- "10002:10002"
entrypoint: /docker-entrypoint.redis.sh
command: [
"redis-server",
"/redis.conf",
"/data/redis.conf",
"--daemonize no",
"--bind 0.0.0.0",
"--port 10002",
Expand Down Expand Up @@ -174,9 +180,10 @@ services:
- redis_sentinel_master_1
ports:
- "10003:10003"
entrypoint: /docker-entrypoint.redis.sh
command: [
"redis-server",
"/redis.conf",
"/data/redis.conf",
"--daemonize no",
"--bind 0.0.0.0",
"--port 10003",
Expand Down Expand Up @@ -217,9 +224,9 @@ services:
entrypoint: /docker-entrypoint.sentinel.sh
environment:
- SENTINEL_PORT=11000
- HOST_IP=192.168.199.100
- MASTER_IP=redis_sentinel_master_1
- MASTER_PORT=10000
- SENTINEL_HOST_IP=192.168.199.100
- SENTINEL_MASTER_IP=redis_sentinel_master_1
- SENTINEL_MASTER_PORT=10000
- SENTINEL_NUM=2
command: [
"--daemonize no",
Expand Down Expand Up @@ -261,9 +268,9 @@ services:
entrypoint: /docker-entrypoint.sentinel.sh
environment:
- SENTINEL_PORT=11001
- HOST_IP=192.168.199.100
- MASTER_IP=redis_sentinel_master_1
- MASTER_PORT=10000
- SENTINEL_HOST_IP=192.168.199.100
- SENTINEL_MASTER_IP=redis_sentinel_master_1
- SENTINEL_MASTER_PORT=10000
- SENTINEL_NUM=2
command: [
"--daemonize no",
Expand Down Expand Up @@ -325,6 +332,14 @@ secrets:
- "com.khs1994.lnmp.clusterkit.redis.sentinel=true"
- "com.khs1994.lnmp.app.env=clusterkit_redis_sentinel"

cluster_redis_entrypoint:
file: ./cluster/redis.sentinel/docker-entrypoint.redis.sh
labels:
- "com.khs1994.lnmp=true"
- "com.khs1994.lnmp.clusterkit=true"
- "com.khs1994.lnmp.clusterkit.redis.sentinel=true"
- "com.khs1994.lnmp.app.env=clusterkit_redis_sentinel"

volumes:
cluster_redis_sentinel_master_1-data:
labels:
Expand Down

0 comments on commit fbd2627

Please sign in to comment.