Redis 拓展连接
此例简单介绍基于docker的redis安装与集群搭建
一:安装
1.获取redis镜像
docker pull redis
2.写服务配置文件redis.conf
daemonize no
pidfile "/var/run/redis.pid"
port 6379
timeout 300
loglevel warning
logfile "redis.log"
databases 16
rdbcompression yes
dbfilename "redis.rdb"
dir "/data"
requirepass password
maxclients 10000
maxmemory 1000mb
maxmemory-policy allkeys-lru
appendonly no
appendfsync always
3.写哨兵配置文件sentinel.conf
daemonize no
port 26379
dir "/tmp"
sentinel monitor mymaster *.*.*.* 6379 1
sentinel down-after-milliseconds mymaster 60000
sentinel auth-pass mymaster password
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
4.启动redis服务
docker run --name redis -p 6379:6379 -v /showcase/redis/redis.conf:/data/redis.conf --restart=always -d redis:latest redis-server redis.conf
5.启动sentinel服务
docker run --name sentinel -p 26379:26379 -v /showcase/redis/sentinel.conf:/data/sentinel.conf --restart=always -d redis:latest redis-sentinel sentinel.conf
二:集群搭建
1.写主服务配置文件redis_master.conf
daemonize no
pidfile "/var/run/redis.pid"
port 6379
timeout 300
loglevel warning
logfile "redis.log"
databases 16
rdbcompression yes
dbfilename "redis.rdb"
dir "/data"
requirepass password
masterauth password
maxclients 10000
maxmemory 1000mb
maxmemory-policy allkeys-lru
appendonly no
appendfsync always
2.写从服务配置文件redis_slave.conf
daemonize no
pidfile "/var/run/redis.pid"
port 6379
timeout 300
loglevel warning
logfile "redis.log"
databases 16
rdbcompression yes
dbfilename "redis.rdb"
dir "/data"
requirepass password
masterauth password
maxclients 10000
maxmemory 1000mb
maxmemory-policy allkeys-lru
appendonly no
appendfsync always
slaveof *.*.*.* 6379
3.写哨兵集群配置文件sentinel.conf
daemonize no
port 26379
dir "/tmp"
sentinel monitor mymaster *.*.*.* 6379 2
sentinel down-after-milliseconds mymaster 60000
sentinel auth-pass mymaster password
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
4.启动主redis服务
docker run --name redis_master -p 6379:6379 -v /showcase/redis/redis_master.conf:/data/redis_master.conf --restart=always -d redis:latest redis-server redis_master.conf
5.启动从redis服务
docker run --name redis_slave -p 6379:6379 -v /showcase/redis/redis_slave.conf:/data/redis_slave.conf --restart=always -d redis:latest redis-server redis_slave.conf
6.启动sentinel服务
docker run --name sentinel -p 26379:26379 -v /showcase/redis/sentinel.conf:/data/sentinel.conf --restart=always -d redis:latest redis-sentinel sentinel.conf