CentOS 6 uses Docker to deploy redis master-slave database operation example

CentOS 6 uses Docker to deploy redis master-slave database operation example

This article describes how to use docker to deploy redis master-slave database operations on centos6. Share with you for your reference, the details are as follows:

Directory structure:

/redis

/Dockerfile

/Readme

/redis-3.2.8.tar.gz

./start.sh

Dockerfile:

FROM centos
MAINTAINER qiongtao.li [email protected]
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

Test the installation and deployment

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

I hope this article will help you use Docker containers.

You may also be interested in:
  • Implementation of Redis master-slave cluster based on Docker
  • Detailed explanation of Redis master-slave replication practice using Docker
  • How to use docker to build redis master-slave
  • Use Docker to build a Redis master-slave replication cluster
  • Detailed explanation of the master-slave configuration tutorial of redis under Docker
  • Example practice of building Redis master-slave + sentinel based on Docker

<<:  Detailed explanation of Vue's monitoring method case

>>:  Detailed explanation of Vue's methods and properties

Recommend

MySQL encoding utf8 and utf8mb4 utf8mb4_unicode_ci and utf8mb4_general_ci

Reference: MySQL character set summary utf8mb4 ha...

HTML table tag tutorial (8): background image attribute BACKGROUND

Set a background image for the table. You can use...

Graphical explanation of the underlying principle of JavaScript scope chain

Table of contents Preface Scope 1. What is scope?...

How does MySQL connect to the corresponding client process?

question For a given MySQL connection, how can we...

Modify the boot time of grub in ubuntu

The online search to modify the grub startup time...

CocosCreator ScrollView optimization series: frame loading

Table of contents 1. Introduction 2. Analysis of ...

Vue+spring boot realizes the verification code function

This article example shares the specific code of ...

Use scripts to package and upload Docker images with one click

The author has been working on a micro-frontend p...

Detailed explanation of Angular component life cycle (I)

Table of contents Overview 1. Hook calling order ...

Summary of the differences between MySQL storage engines MyISAM and InnoDB

1. Changes in MySQL's default storage engine ...

Detailed tutorial on installing CUDA9.0 on Ubuntu16.04

Preface: This article is based on the experience ...

MySQL series multi-table join query 92 and 99 syntax examples detailed tutorial

Table of contents 1. Cartesian product phenomenon...