rubyangxg 4 жил өмнө
parent
commit
3adb4d11d2

+ 21 - 0
docker-redis-sentinel-master/LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2019 xavier
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 47 - 0
docker-redis-sentinel-master/README.md

@@ -0,0 +1,47 @@
+# Redis sentinel via docker-compose
+
+This is useful for local development and CI , you have 1 master, 1 slave and 1 sentinel with docker containers.
+
+*Note*: The sentinel Dockerfile is heavily borrowed and inspired by [redis-cluster-with-sentinel](https://github.com/mustafaileri/redis-cluster-with-sentinel).
+
+
+## How to start
+
+```
+> ./start.sh`
+```
+
+If you see the console output as follows, you have set up the sentinel!
+
+```
+docker-compose ps
+     Name                   Command               State                 Ports
+--------------------------------------------------------------------------------------------
+redis_master     docker-entrypoint.sh redis ...   Up      0.0.0.0:6379->6379/tcp
+redis_sentinel   sentinel-entrypoint.sh           Up      0.0.0.0:26379->26379/tcp, 6379/tcp
+redis_slave      docker-entrypoint.sh redis ...   Up      6379/tcp, 0.0.0.0:6380->6380/tcp
+
+```
+
+## How to verify
+
+```
+> redis-cli -p 26379
+127.0.0.1:26379> sentinel master mysentinel
+ 1) "name"
+ 2) "mysentinel"
+ 3) "ip"
+ 4) "192.168.1.5"
+ 5) "port"
+ 6) "6379"
+ 7) "runid"
+ 8) ""
+ ...
+```
+
+`192.168.1.5` is my IP but you should find your local en0 IP.
+
+
+## License
+
+[MIT](./LICENSE)

+ 21 - 0
docker-redis-sentinel-master/docker-compose.yml

@@ -0,0 +1,21 @@
+version: '2.2'
+services:
+  redis_master:
+    image: redis:5
+    container_name: redis_master
+    ports:
+      - '6479:6379'
+  redis_slave:
+    image: redis:5
+    container_name: redis_slave
+    command: redis-server --port 6380 --slaveof "${EXTERNAL_HOST}" 6479 --slave-announce-ip "${EXTERNAL_HOST}"
+    ports:
+      - '6480:6380'
+  sentinel:
+    build: ./sentinel
+    container_name: redis_sentinel
+    ports:
+      - '26379:26379'
+    environment:
+      - SENTINEL_NAME=mysentinel
+      - HOST_IP="${EXTERNAL_HOST}"

+ 11 - 0
docker-redis-sentinel-master/sentinel/Dockerfile

@@ -0,0 +1,11 @@
+FROM redis:3
+
+EXPOSE 26379
+COPY sentinel.conf /etc/redis/sentinel.conf
+RUN chown redis:redis /etc/redis/sentinel.conf
+ENV SENTINEL_QUORUM 2
+ENV SENTINEL_NAME mysentinel
+ENV SENTINEL_DOWN_AFTER 30000
+ENV SENTINEL_FAILOVER 180000
+COPY sentinel-entrypoint.sh /usr/local/bin/
+ENTRYPOINT ["sentinel-entrypoint.sh"]

+ 9 - 0
docker-redis-sentinel-master/sentinel/sentinel-entrypoint.sh

@@ -0,0 +1,9 @@
+#!/bin/sh
+
+sed -i "s/\$SENTINEL_QUORUM/$SENTINEL_QUORUM/g" /etc/redis/sentinel.conf
+sed -i "s/\$SENTINEL_DOWN_AFTER/$SENTINEL_DOWN_AFTER/g" /etc/redis/sentinel.conf
+sed -i "s/\$SENTINEL_FAILOVER/$SENTINEL_FAILOVER/g" /etc/redis/sentinel.conf
+sed -i "s/\$SENTINEL_NAME/$SENTINEL_NAME/g" /etc/redis/sentinel.conf
+sed -i "s/\$HOST_IP/$HOST_IP/g" /etc/redis/sentinel.conf
+
+exec docker-entrypoint.sh redis-server /etc/redis/sentinel.conf --sentinel

+ 11 - 0
docker-redis-sentinel-master/sentinel/sentinel.conf

@@ -0,0 +1,11 @@
+port 26379
+
+dir /tmp
+
+sentinel monitor $SENTINEL_NAME $HOST_IP 6479 $SENTINEL_QUORUM
+
+sentinel down-after-milliseconds $SENTINEL_NAME $SENTINEL_DOWN_AFTER
+
+sentinel parallel-syncs $SENTINEL_NAME 1
+
+sentinel failover-timeout $SENTINEL_NAME $SENTINEL_FAILOVER

+ 14 - 0
docker-redis-sentinel-master/start.sh

@@ -0,0 +1,14 @@
+#!/bin/bash
+set -ev
+
+IP=`ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'`
+# echo $IP
+pushd `dirname $0`
+
+echo "EXTERNAL_HOST=$IP" > .env
+
+# Start the services and wait for it.
+docker-compose up -d --build
+docker-compose ps
+
+popd