docker软件安装-redis

 

 

  1. redis安装

参考rabbitMQ

1、进入docker hub镜像仓库地址:https://hub.docker.com/

2、搜索redis,进入官方的镜像,可以看到以下几种类型的镜像;

3、拉取镜像:docker pull redis:6.0.4

4、单结点启动,根据下载的镜像创建和启动容器

docker images 查看所有镜像

docker run -d --name redis6.0.4 -p 6379:6379 --restart always 36304d3b4540 --requirepass "Chushang831"

5、集群模式

创建共享网络:

docker network rm  redisnet

docker network create --driver bridge --subnet=172.19.0.0/16 --gateway=172.19.0.1  redisnet

通过docker network inspect redisnet,可以看到网关信息

创建配置文件和数据目录

/home/chually/99_dockerData/redisCluster/7001~7006,端口依次7001~7002,ip依次为172.19.0.11~172.19.0.16

mkdir -p /home/chually/99_dockerData/redisCluster/7001/data

mkdir -p /home/chually/99_dockerData/redisCluster/7002/data

mkdir -p /home/chually/99_dockerData/redisCluster/7003/data

mkdir -p /home/chually/99_dockerData/redisCluster/7004/data

mkdir -p /home/chually/99_dockerData/redisCluster/7005/data

mkdir -p /home/chually/99_dockerData/redisCluster/7006/data

cd /home/chually/99_dockerData/redisCluster/7001/data

vi redis.conf

port 7001

#启用集群

cluster-enabled yes

#集群配置文件名,可自定义,将在data目录中生成集群配置文件

cluster-config-file nodes.conf

#超时时间

cluster-node-timeout 5000

#节点ip地址

cluster-announce-ip 172.19.0.11

#节点端口

cluster-announce-port 7001

#节点总线端口

cluster-announce-bus-port 17001

#开启持久化

appendonly yes

#开启密码登陆

protected-mode yes

#密码

requirepass Chushang831

运行容器

docker run -d --name redis7001 -p 7001:7001 -p 17001:17001 --restart always --net redisnet --ip 172.19.0.11 --privileged=true -v /home/chually/99_dockerData/redisCluster/7001/redis.conf:/etc/redis/redis.conf -v /home/chually/99_dockerData/redisCluster/7001/data:/data 36304d3b4540 redis-server /etc/redis/redis.conf

 

docker run -d --name redis7002 -p 7002:7002 -p 17002:17002 --restart always --net redisnet --ip 172.19.0.12 --privileged=true -v /home/chually/99_dockerData/redisCluster/7002/redis.conf:/etc/redis/redis.conf -v /home/chually/99_dockerData/redisCluster/7002/data:/data 36304d3b4540 redis-server /etc/redis/redis.conf

 

docker run -d --name redis7003 -p 7003:7003 -p 17003:17003 --restart always --net redisnet --ip 172.19.0.13 --privileged=true -v /home/chually/99_dockerData/redisCluster/7003/redis.conf:/etc/redis/redis.conf -v /home/chually/99_dockerData/redisCluster/7003/data:/data 36304d3b4540 redis-server /etc/redis/redis.conf

 

docker run -d --name redis7004 -p 7004:7004 -p 17004:17004 --restart always --net redisnet --ip 172.19.0.14 --privileged=true -v /home/chually/99_dockerData/redisCluster/7004/redis.conf:/etc/redis/redis.conf -v /home/chually/99_dockerData/redisCluster/7004/data:/data 36304d3b4540 redis-server /etc/redis/redis.conf

 

docker run -d --name redis7005 -p 7005:7005 -p 17005:17005 --restart always --net redisnet --ip 172.19.0.15 --privileged=true -v /home/chually/99_dockerData/redisCluster/7005/redis.conf:/etc/redis/redis.conf -v /home/chually/99_dockerData/redisCluster/7005/data:/data 36304d3b4540 redis-server /etc/redis/redis.conf

 

docker run -d --name redis7006 -p 7006:7006 -p 17006:17006 --restart always --net redisnet --ip 172.19.0.16 --privileged=true -v /home/chually/99_dockerData/redisCluster/7006/redis.conf:/etc/redis/redis.conf -v /home/chually/99_dockerData/redisCluster/7006/data:/data 36304d3b4540 redis-server /etc/redis/redis.conf

 

docker network inspect redisnet

快速停止并删除

docker stop redis7001

docker stop redis7002

docker stop redis7003

docker stop redis7004

docker stop redis7005

docker stop redis7006

docker rm redis7001

docker rm redis7002

docker rm redis7003

docker rm redis7004

docker rm redis7005

docker rm redis7006

rm -Rf /home/chually/99_dockerData/redisCluster/7001/data/*

rm -Rf /home/chually/99_dockerData/redisCluster/7002/data/*

rm -Rf /home/chually/99_dockerData/redisCluster/7003/data/*

rm -Rf /home/chually/99_dockerData/redisCluster/7004/data/*

rm -Rf /home/chually/99_dockerData/redisCluster/7005/data/*

rm -Rf /home/chually/99_dockerData/redisCluster/7006/data/*

建立集群关系

docker exec -it redis7001 /bin/bash

redis-cli -h 172.19.0.11 -p 7001 -a Chushang831 --cluster create 172.19.0.11:7001 172.19.0.12:7002 172.19.0.13:7003 172.19.0.14:7004 172.19.0.15:7005 172.19.0.16:7006 --cluster-replicas 1 --no-auth-warning

注意客户端连接时去下方的的“在集群重定向时改变主机地址”

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值