docker安装
1、下载镜像
docker pull redis
2、运行容器
docker run -d --name redis -p 6379:6379 \
-v /data/docker/redis/data:/data \
-v /data/docker/redis/conf/redis.conf:/etc/redis/redis.conf \
--privileged=true redis:latest --appendonly yes --requirepass "123456"
注意:/etc/redis/redis.conf 是个目录
创建目录:
mkdir /data/docker/redis/data
mkdir /data/docker/redis/conf
创建 /data/docker/redis/conf/redis.conf
bind 0.0.0.0
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
3、查看容器
docker ps
4、开发端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
5、进入容器
docker exec -it redis redis-cli -h 192.168.56.100 -p 6379 -a '123456'
docker-compose安装
单节点安装:
version: '3.1'
services:
db:
image: redis
container_name: redis
restart: always
command: redis-server /etc/redis/redis.conf --requirepass 123456
ports:
- 6379:6379
volumes:
- /data/docker/redis/data:/data
- /data/docker/redis/conf/redis.conf:/etc/redis/redis.conf
集群安装:
version: '3.1'
services:
master:
image: redis
container_name: redis-master
ports:
- 6379:6379
slave1:
image: redis
container_name: redis-slave-1
ports:
- 6380:6379
command: redis-server --slaveof redis-master 6379
slave2:
image: redis
container_name: redis-slave-2
ports:
- 6381:6379
command: redis-server --slaveof redis-master 6379
sentinel1:
image: redis
container_name: redis-sentinel-1
ports:
- 26379:26379
command: redis-sentinel /data/docker/redis/conf/sentinel.conf
volumes:
- /data/docker/redis/conf/sentinel1.conf:/usr/local/etc/redis/sentinel.conf
sentinel2:
image: redis
container_name: redis-sentinel-2
ports:
- 26380:26379
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
volumes:
- /data/docker/redis/conf/sentinel2.conf:/usr/local/etc/redis/sentinel.conf
sentinel3:
image: redis
container_name: redis-sentinel-3
ports:
- 26381:26379
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
volumes:
- /data/docker/redis/conf/sentinel3.conf:/usr/local/etc/redis/sentinel.conf
sentinel.conf
port 26379
dir /tmp
# 自定义集群名,其中 127.0.0.1 为 redis-master 的 ip,6379 为 redis-master 的端口,2 为最小投票数(因为有 3 台 Sentinel 所以可以设置成 2)
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes