1

I am trying to build a simple redis sentinel demo by docker and swarm.

There are two nodes: node1(swarm manager), node2. Node1 will run a redis master and a sentinel, Node2 will run a redis slave.

This is my docker-compose file(control the allocation of containers with labels):

version: "3.3"
services:
        master:
           image: "redis:5.0.7"
           deploy:
                mode: global
                placement:
                        constraints: [node.labels.redismaster == true]
           networks:
                myredisnet:
           command: redis-server /etc/redis.conf
           volumes:
                - "~/redis.conf:/etc/redis.conf"
        salve:
           image: "redis:5.0.7"
           deploy:
                mode: global
                placement:
                        constraints: [node.labels.redisslave1 == true]
           networks:
                myredisnet:
           command: redis-server /etc/redis-slave.conf
           volumes:
                - "~/redis-slave.conf:/etc/redis-slave.conf"
        sentinel:
           image: "redis:5.0.7"
           ports:
                - "26379:26379"
           volumes:
                - "~/sentinel.conf:/usr/local/bin/sentinel.conf"
           deploy:
                mode: global
                placement:
                        constraints: [node.labels.redismaster == true]
           networks:
                myredisnet:
           command: redis-sentinel /usr/local/bin/sentinel.conf
networks:
        myredisnet:
                driver: overlay

And my redis conf file and redis-slave conf file are similar except slaveof master 6379 in redis-slave file.(master is service name in docker-compose file):

bind 0.0.0.0
protected-mode yes
masterauth redispass
requirepass redispass

And this is my sentinel conf file:

port 26379
logfile "/var/log/sentinel.log"
protected-mode no
dir "/root"
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster master 6379 1
sentinel auth-pass mymaster redispass

After I user docker stack deploy -c docker-compose.yml redis to deploy these services, everything seems normal and redis master slave is built correctly.

But the sentinel seemed to have a problem. When I enter sentinel container terminal(docker exec -it) and check sentinel log:

root@d2fe4dc7ffa4:/data# cat /var/log/sentinel.log 
1:X 23 Feb 2020 11:22:25.114 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:X 23 Feb 2020 11:22:25.114 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=1, just started
1:X 23 Feb 2020 11:22:25.114 # Configuration loaded
1:X 23 Feb 2020 11:22:25.115 * Running mode=sentinel, port=26379.
1:X 23 Feb 2020 11:22:25.115 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:X 23 Feb 2020 11:22:25.116 # Sentinel ID is 1f9c8c8f688f0a9925dad749fea86c196781f6bf
1:X 23 Feb 2020 11:22:25.116 # +monitor master mymaster 10.0.9.2 6379 quorum 1
1:X 23 Feb 2020 11:22:25.118 * +slave slave 10.0.9.7:6379 10.0.9.7 6379 @ mymaster 10.0.9.2 6379
1:X 23 Feb 2020 11:22:55.168 # +sdown slave 10.0.9.7:6379 10.0.9.7 6379 @ mymaster 10.0.9.2 6379

As you can see, sentinel thinks the slave node is not available. What puzzles me is sentinel detected that the slave's IP was 10.0.9.7. On node2. I found by command that the salve container's IP should be 10.0.9.6:

on node2:
[root@node02 ~]# docker inspect 4ba57e6fd395
...
"Networks": {
                "redis_myredisnet": {
                    "IPAMConfig": {
                        "IPv4Address": "10.0.9.6"
                    },
                    "Links": null,
                    "Aliases": [
                        "4ba57e6fd395"
                    ],
                    "NetworkID": "ziry6mb6fkz5ido2cg9j86t6a",
                    "EndpointID": "771da42d9d7dc03ecb3892d2c3cdf83be97268625b0ee24f0fa3ffb6c2377b6d",
                    "Gateway": "",
                    "IPAddress": "10.0.9.6",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:0a:00:09:06",
                    "DriverOpts": null
                }
            }


And when I enter redis master container terminal(docker exec -it) and execute redis-cli,auth redispass,info to check replication info on node1:

# Replication
role:master
connected_slaves:1
slave0:ip=10.0.9.7,port=6379,state=online,offset=224628,lag=1
master_replid:f4bf3ba64df96919b6e9cd4e0935ace6d31b0ba6
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:224759
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:224759

As you can see, slave ip is also slave0:ip=10.0.9.7. So I did a little experiment, I use apt-get update; apt-get install telnet and try to telnet 10.0.9.7 6379 in my redis master container:

root@d2fe4dc7ffa4:/data# telnet 10.0.9.7 6379
Trying 10.0.9.7...
telnet: Unable to connect to remote host: Connection refused

And I also test telnet 10.0.9.6 6379:

root@d2fe4dc7ffa4:/data# telnet 10.0.9.6 6379
Trying 10.0.9.6...
Connected to 10.0.9.6.
Escape character is '^]'.
auth redispass
+OK

Also, I execute docker inspect (slave service name) and this is slave service vip:

[root@node03 ~]# docker inspect redis_salve
...
 "Endpoint": {
            "Spec": {
                "Mode": "vip"
            },
            "VirtualIPs": [
                {
                    "NetworkID": "ziry6mb6fkz5ido2cg9j86t6a",
                    "Addr": "10.0.9.5/24"
                }
            ]
        }


So where does this IP 10.0.9.7 come from ? And It seems, I have a problem with my sentinel service as well. When I pause my redis master container, sentinel cannot switch to slave node.

Besides, this is my sentinel conf file after sentinel service running:

[root@node03 ~]# cat sentinel.conf 
port 26379
logfile "/var/log/sentinel.log"
protected-mode no
dir "/root"
sentinel myid 1f9c8c8f688f0a9925dad749fea86c196781f6bf
sentinel deny-scripts-reconfig yes
# Generated by CONFIG REWRITE
sentinel monitor mymaster 10.0.9.2 6379 1
sentinel auth-pass mymaster redispass
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-replica mymaster 10.0.9.7 6379
sentinel current-epoch 0

Any help would be appreciated!!!!!!!!!

ppbb
  • 129
  • 8
  • I dont really know what is the issue but i want to ask, you have master and slave having `volumes:` in a swarm, which means you should make sure this volumes exists in node1 node2 and node3, and as a testing i can advice you to deploy all 3 containers in the swarm in the manager node, have a test to see if all containers on the same node makes a difference. – Batchen Regev Feb 23 '20 at 17:46
  • I am seeing the exact same thing. Were you ever able to resolve it? Master Slave Replication works. But as soon as I introduce sentinel I get a sdown status for the slave @ppbb – Snowball Jun 03 '20 at 21:04
  • This one works for me: https://github.com/antirez/redis/issues/6218#issuecomment-569863582 – Snowball Jun 04 '20 at 19:02
  • Sorry for the slow response. Actually I gave up this way to build redis sentine, but I am glad you found a solution.@Snowball – ppbb Jun 12 '20 at 06:12

0 Answers0