centos6使用docker部署redis主从数据库操作示例
本文实例讲述了centos6使用docker部署redis主从数据库操作。分享给大家供大家参考,具体如下:
目录结构:
/redis
/Dockerfile
/Readme
/redis-3.2.8.tar.gz
/start.sh
Dockerfile:
FROMcentos MAINTAINERqiongtao.lihnatao@126.com ADD./redis-3.2.8.tar.gz/opt ADD./start.sh/opt/start_redis.sh RUNecho"Asia/shanghai">/etc/timezone\ &&cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime\ &&yum-yinstallgccmake\ &&ln-s/opt/redis-3.2.8/opt/redis\ &&cd/opt/redis&&make&&makeinstall EXPOSE6379 ENTRYPOINT["sh","/opt/start_redis.sh"]
start.sh
role=$1 port=6379 password=Abc123 redis_conf=/opt/redis/redis.conf dir=/data/redis logfile=/data/redis/redis.log mkdir-p$dir sed-i"s|bind127.0.0.1|bind0.0.0.0|g"$redis_conf sed-i"s|#requirepassfoobared|requirepass${password}|g"$redis_conf sed-i"s|dir./|dir${dir}|g"$redis_conf sed-i"s|logfile\"\"|logfile${logfile}|g"$redis_conf if["$role"=="slave"];then echo"slave" sed-i"s|#slaveof|slaveofredis-master${port}|g"$redis_conf sed-i"s|#masterauth |masterauth${password}|g"$redis_conf else echo"master" fi redis-server$redis_conf
Readme
dockerrm-fredis-masterredis-slave-1redis-slave-2 dockerrmi-fredis dockerbuild-tredis. dockerrun-d--nameredis-masterredis dockerrun-d--nameredis-slave-1--linkredis-master:redis-masterredisslave dockerrun-d--nameredis-slave-2--linkredis-master:redis-masterredisslave dockerps-a dockerexecredis-masterredis-cli-aAbc123setnamehnatao dockerexecredis-masterredis-cli-aAbc123getname dockerexecredis-slave-1redis-cli-aAbc123getname dockerexecredis-slave-2redis-cli-aAbc123getname dockerexecredis-mastergrep-E"bind|dir|require|logfile|slaveof|masterauth"/opt/redis/redis.conf dockerexecredis-slave-1grep-E"bind|dir|require|logfile|slaveof|masterauth"/opt/redis/redis.conf dockerexecredis-slave-2grep-E"bind|dir|require|logfile|slaveof|masterauth"/opt/redis/redis.conf dockerexecredis-masterredis-cli-aAbc123info dockerexecredis-slave-1redis-cli-aAbc123info dockerexecredis-slave-2redis-cli-aAbc123info
测试安装部署
catReadme|whilereadline;do$line;done
希望本文所述对大家Docker容器使用有所帮助。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。