安装 docker
安装 docker-compose
基于 docker-compose 安装 redis-cluster
安装docker1
- 导入
sudo rpm --import "https://sks-keyservers.net/pks/lookup?op=get&search=0xee6d536cf7dc86e2d7d56f59a178ac6c6238f52e"
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://packages.docker.com/1.10/yum/repo/main/centos/7
yum install -y docker-engine
service docker start
安装 docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
如果提示docker-compose 没找到,说明 /usr/local/bin/没有添加到环境变量中2
export PATH=/usr/local/bin/:$PATH
安装 redis-cluster 3
docker-compose.yml
version: '3.4'
x-image:
&default-image
publicisworldwide/redis-cluster
x-restart:
&default-restart
always
x-netmode:
&default-netmode
host
services:
redis1:
image: *default-image
network_mode: *default-netmode
restart: *default-restart
volumes:
- /data/redis/7001/data:/data
environment:
- REDIS_PORT=7001
redis2:
image: *default-image
network_mode: *default-netmode
restart: *default-restart
volumes:
- /data/redis/7002/data:/data
environment:
- REDIS_PORT=7002
redis3:
image: *default-image
network_mode: *default-netmode
restart: *default-restart
volumes:
- /data/redis/7003/data:/data
environment:
- REDIS_PORT=7003
redis4:
image: *default-image
network_mode: *default-netmode
restart: *default-restart
volumes:
- /data/redis/7004/data:/data
environment:
- REDIS_PORT=7004
redis5:
image: *default-image
network_mode: *default-netmode
restart: *default-restart
volumes:
- /data/redis/7005/data:/data
environment:
- REDIS_PORT=7005
redis6:
image: *default-image
network_mode: *default-netmode
restart: *default-restart
volumes:
- /data/redis/7006/data:/data
environment:
- REDIS_PORT=7006
查看镜像
docker ps,如下图
连接redis(redis_redis1_1_1b9166488b28 表示在docker容器中,某一个redis节点ID)
docker exec -it redis_redis1_1_1b9166488b28 redis-cli -c -h 127.0.0.1 -p 7001