您好,登錄后才能下訂單哦!
本文實例講述了centos6使用docker部署redis主從數據庫操作。分享給大家供大家參考,具體如下:
目錄結構:
/redis
/Dockerfile
/Readme
/redis-3.2.8.tar.gz
/start.sh
Dockerfile:
FROM centos MAINTAINER qiongtao.li hnatao@126.com ADD ./redis-3.2.8.tar.gz /opt ADD ./start.sh /opt/start_redis.sh RUN 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 install EXPOSE 6379 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|bind 127.0.0.1|bind 0.0.0.0|g" $redis_conf sed -i "s|# requirepass foobared|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 <masterip> <masterport>|slaveof redis-master ${port}|g" $redis_conf sed -i "s|# masterauth <master-password>|masterauth ${password}|g" $redis_conf else echo "master" fi redis-server $redis_conf
Readme
docker rm -f redis-master redis-slave-1 redis-slave-2 docker rmi -f redis docker build -t redis . docker run -d --name redis-master redis docker run -d --name redis-slave-1 --link redis-master:redis-master redis slave docker run -d --name redis-slave-2 --link redis-master:redis-master redis slave docker ps -a docker exec redis-master redis-cli -a Abc123 set name hnatao docker exec redis-master redis-cli -a Abc123 get name docker exec redis-slave-1 redis-cli -a Abc123 get name docker exec redis-slave-2 redis-cli -a Abc123 get name docker exec redis-master grep -E "bind|dir|require|logfile|slaveof|masterauth" /opt/redis/redis.conf docker exec redis-slave-1 grep -E "bind|dir|require|logfile|slaveof|masterauth" /opt/redis/redis.conf docker exec redis-slave-2 grep -E "bind|dir|require|logfile|slaveof|masterauth" /opt/redis/redis.conf docker exec redis-master redis-cli -a Abc123 info docker exec redis-slave-1 redis-cli -a Abc123 info docker exec redis-slave-2 redis-cli -a Abc123 info
測試安裝部署
cat Readme|while read line; do $line; done
希望本文所述對大家Docker容器使用有所幫助。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。