Docker 部署 Redis 集群 VS 正常部署 Redis 集群
程序员的成长之路
共 4387字,需浏览 9分钟
·
2020-09-07 12:49
阅读本文大概需要 4 分钟。
前言
yum -y install wget
安装。wget http://download.redis.io/releases/redis-6.0.7.tar.gz
yum -y install gcc-c++
tar xzf redis-6.0.7.tar.gz
cd redis-6.0.7
make
# 1、安装gcc全家桶
yum install cpp
yum install binutils
yum install glibc
yum install glibc-kernheaders
yum install glibc-common
yum install glibc-devel
yum install gcc
yum install make
# 2、升级gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
# 3、设置永久生效
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
make install
redis-server redis.conf
# 通过脚本创建6个redis配置
for port in $(seq 1 6); \
do \
mkdir -p /root/redis/node-${port}/conf
touch /root/redis/node-${port}/conf/redis.conf
cat << EOF >/root/redis/node-${port}/conf/redis.conf
port 637${port}
bind 0.0.0.0
cluster-enabled yes
cluster-config-file /root/redis/node-${port}/conf/nodes.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
EOF
done
for port in $(seq 1 6); \
do \
redis-server /root/redis/node-${port}/conf/redis.conf
done
redis-cli --cluster create 127.0.0.1:6371 127.0.0.1:6372 127.0.0.1:6373 127.0.0.1:6374 127.0.0.1:6375 127.0.0.1:6376 --cluster-replicas 1
#1、卸载旧的版本
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
#2、需要的安装包
sudo yum install -y yum-utils
#3、安装镜像仓库
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo # 默认是国外的
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # 建议使用阿里云的,十分快速
# 配置下加速
# >移动到下述目录:
cd /etc/docker
# >找到daemon.json文件,如果没有就新建一个,填入如下信息:
["https://almtd3fa.mirror.aliyuncs.com"]} :
# >重启下docker
service docker restart
# 更新yum软件包索引
yum makecache fast
#4、安装docker相关的依赖 docker-ce 社区版 ee 企业版
sudo yum install docker-ce docker-ce-cli containerd.io
#5、启动Docker
sudo systemctl start docker
#6、检测是否安装成功
docker version
#7、测试hello-world
docker run hello-world
#8、查看一下下载的这个 hello-world 镜像
~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
latest bf756fb1ae65 7 months ago 13.3kB
docker network create redis --subnet 172.38.0.0/16
# 通过脚本创建6个redis配置
for port in $(seq 1 6); \
do \
mkdir -p /root/redis/node-${port}/conf
touch /root/redis/node-${port}/conf/redis.conf
cat << EOF >/root/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
for port in $(seq 1 6); \
do \
docker run -p 637${port}:6379 -p 1637${port}:16379 --name redis-${port} \
-v /root/redis/node-${port}/data:/data \
-v /root/redis/node-${port}/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.1${port} redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf; \
done
[ ]
/data
redis-cli -h 127.0.0.1 -c -p 3679
[ ]
[root@localhost ~]# docker exec -it redis-2 /bin/sh
/data #
/data # redis-cli -h 127.0.0.1 -c -p 3679
搞定,收工!!
别忘记点个再看,咱们下篇见!
每天进步一点点
慢一点才能更快
推荐阅读:
只需4步,自己搞个 Spring Boot Starter !
为什么 Java 中“1000==1000”为false,而”100==100“为true?
微信扫描二维码,关注我的公众号
朕已阅
评论