redis学习
创建网络
docker network create redis --subnet 172.38.0.0/16
创建配置文件
for port in $(seq 1 6); \
do \
mkdir -p /mydata/redis/node-${port}/conf
touch /mydata/redis/node-${port}/conf/redis.conf
cat << EOF >> /mydata/redis/node-${port}/conf/redis.conf
port 6379
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 172.38.0.1${port}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly yes
EOF
done
docker run -p 6371:6379 -p 16371:16379 --name redis-1-v /mydata/redis/node-1/data:/data
-V /mydata/redis/node-1/conf/redis.conf:/etc/redis/redis.conf-d --net redis --ip 172.38.0.11 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
修改配置文件,改成后台启动
启动
redis-server redis.conf
测试
redis-cli -p 6379 -h 10.5.1.235
切换数据库
select 3
清空数据库
flushdb