千家信息网

centos6使用docker部署redis主从数据库操作示例

发表于:2025-01-31 作者:千家信息网编辑
千家信息网最后更新 2025年01月31日,本文实例讲述了centos6使用docker部署redis主从数据库操作。分享给大家供大家参考,具体如下:目录结构:/redis/Dockerfile/Readme/redis-3.2.8.tar.g
千家信息网最后更新 2025年01月31日centos6使用docker部署redis主从数据库操作示例

本文实例讲述了centos6使用docker部署redis主从数据库操作。分享给大家供大家参考,具体如下:

目录结构:

/redis

/Dockerfile

/Readme

/redis-3.2.8.tar.gz

/start.sh

Dockerfile:

FROM centosMAINTAINER qiongtao.li hnatao@126.comADD ./redis-3.2.8.tar.gz /optADD ./start.sh /opt/start_redis.shRUN echo "Asia/shanghai" > /etc/timezone \ && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && yum -y install gcc make \ && ln -s /opt/redis-3.2.8 /opt/redis \ && cd /opt/redis && make && make installEXPOSE 6379ENTRYPOINT ["sh", "/opt/start_redis.sh"]

start.sh

role=$1port=6379password=Abc123redis_conf=/opt/redis/redis.confdir=/data/redislogfile=/data/redis/redis.logmkdir -p $dirsed -i "s|bind 127.0.0.1|bind 0.0.0.0|g" $redis_confsed -i "s|# requirepass foobared|requirepass ${password}|g" $redis_confsed -i "s|dir ./|dir ${dir}|g" $redis_confsed -i "s|logfile \"\"|logfile ${logfile}|g" $redis_confif [ "$role" == "slave" ]; then echo "slave" sed -i "s|# slaveof  |slaveof redis-master ${port}|g" $redis_conf sed -i "s|# masterauth |masterauth ${password}|g" $redis_confelse echo "master"firedis-server $redis_conf

Readme

docker rm -f redis-master redis-slave-1 redis-slave-2docker rmi -f redisdocker build -t redis .docker run -d --name redis-master redisdocker run -d --name redis-slave-1 --link redis-master:redis-master redis slavedocker run -d --name redis-slave-2 --link redis-master:redis-master redis slavedocker ps -adocker exec redis-master redis-cli -a Abc123 set name hnataodocker exec redis-master redis-cli -a Abc123 get namedocker exec redis-slave-1 redis-cli -a Abc123 get namedocker exec redis-slave-2 redis-cli -a Abc123 get namedocker exec redis-master grep -E "bind|dir|require|logfile|slaveof|masterauth" /opt/redis/redis.confdocker exec redis-slave-1 grep -E "bind|dir|require|logfile|slaveof|masterauth" /opt/redis/redis.confdocker exec redis-slave-2 grep -E "bind|dir|require|logfile|slaveof|masterauth" /opt/redis/redis.confdocker exec redis-master redis-cli -a Abc123 infodocker exec redis-slave-1 redis-cli -a Abc123 infodocker exec redis-slave-2 redis-cli -a Abc123 info

测试安装部署

cat Readme|while read line; do $line; done

希望本文所述对大家Docker容器使用有所帮助。

0