Redis哨兵集群及容器搭建

下面是podman的容器搭建脚本:

VOL_HOME=/data/volumes;
mkdir -p $VOL_HOME/redis-server-1/conf/;
mkdir -p $VOL_HOME/redis-server-1/data;
echo "port 17001" > $VOL_HOME/redis-server-1/conf/redis.conf;
podman run --name redis-server-1 \
-d \
-p 17001:17001 \
-v $VOL_HOME/redis-server-1:/usr/local/etc/redis \
-v $VOL_HOME/redis-server-1/data:/data \
redis:7.0.7 redis-server /usr/local/etc/redis/conf/redis.conf \
--appendonly yes;


VOL_HOME=/data/volumes;
mkdir -p $VOL_HOME/redis-server-2/conf/;
mkdir -p $VOL_HOME/redis-server-2/data;
CONF_FILE=$VOL_HOME/redis-server-2/conf/redis.conf;
echo "port 17002" > $CONF_FILE;
echo "slaveof 192.168.56.100 17001" >> $CONF_FILE;
echo "replica-announce-ip 192.168.56.100" >> $CONF_FILE;
echo "replica-announce-port 17002" >> $CONF_FILE;
podman run --name redis-server-2 \
-d \
-p 17002:17002 \
-v $VOL_HOME/redis-server-2:/usr/local/etc/redis \
-v $VOL_HOME/redis-server-2/data:/data \
redis:7.0.7 redis-server /usr/local/etc/redis/conf/redis.conf \
 --appendonly yes;

VOL_HOME=/data/volumes;
mkdir -p $VOL_HOME/redis-server-3/conf/;
mkdir -p $VOL_HOME/redis-server-3/data;
echo "port 17003" > $VOL_HOME/redis-server-3/conf/redis.conf;
echo "slaveof 192.168.56.100 17001" >> $VOL_HOME/redis-server-3/conf/redis.conf;
podman run --name redis-server-3 \
-d \
-p 17003:17003 \
-v $VOL_HOME/redis-server-3:/usr/local/etc/redis \
-v $VOL_HOME/redis-server-3/data:/data \
redis:7.0.7 redis-server /usr/local/etc/redis/conf/redis.conf \
 --appendonly yes;

VOL_HOME=/data/volumes;
mkdir -p $VOL_HOME/redis-sentinel-1/conf/;
mkdir -p $VOL_HOME/redis-sentinel-1/data;
echo "port 18001" > $VOL_HOME/redis-sentinel-1/conf/sentinel.conf;
echo "sentinel monitor master 192.168.56.100 17001 2" >> $VOL_HOME/redis-sentinel-1/conf/sentinel.conf;
podman run --name redis-sentinel-1 \
-d \
-p 18001:18001 \
-v $VOL_HOME/redis-sentinel-1:/usr/local/etc/redis \
-v $VOL_HOME/redis-sentinel-1/data:/data \
redis:7.0.7 redis-sentinel /usr/local/etc/redis/conf/sentinel.conf \
 --appendonly yes;

VOL_HOME=/data/volumes;
mkdir -p $VOL_HOME/redis-sentinel-2/conf/;
mkdir -p $VOL_HOME/redis-sentinel-2/data;
echo "port 18002" > $VOL_HOME/redis-sentinel-2/conf/sentinel.conf;
echo "sentinel monitor master 192.168.56.100 17001 2" >> $VOL_HOME/redis-sentinel-2/conf/sentinel.conf;
podman run --name redis-sentinel-2 \
-d \
-p 18002:18002 \
-v $VOL_HOME/redis-sentinel-2:/usr/local/etc/redis \
-v $VOL_HOME/redis-sentinel-2/data:/data \
redis:7.0.7 redis-sentinel /usr/local/etc/redis/conf/sentinel.conf \
 --appendonly yes;

VOL_HOME=/data/volumes;
mkdir -p $VOL_HOME/redis-sentinel-3/conf/;
mkdir -p $VOL_HOME/redis-sentinel-3/data;
echo "port 18003" > $VOL_HOME/redis-sentinel-3/conf/sentinel.conf;
echo "sentinel monitor master 192.168.56.100 17001 2" >> $VOL_HOME/redis-sentinel-3/conf/sentinel.conf;
podman run --name redis-sentinel-3 \
-d \
-p 18003:18003 \
-v $VOL_HOME/redis-sentinel-3:/usr/local/etc/redis \
-v $VOL_HOME/redis-sentinel-3/data:/data \
redis:7.0.7 redis-sentinel /usr/local/etc/redis/conf/sentinel.conf \
 --appendonly yes;

使用窗口内的客户端连接:

 podman exec -it redis-server-1 redis-cli -h 192.168.56.100 -p 17001

参考:

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享