docker系列-03.docker搭建redis集群

docker搭建redis集群

1.下载redis镜像

docker pull redis

2.准备配置文件 redis.conf

mkdir /home/docker/redis/  
wget https://raw.githubusercontent.com/antirez/redis/3.0/redis.conf -O /home/docker/redis/redis.conf
cd /home/docker/redis/  
sed -i 's/# slaveof  /slaveof redis-master 6379/g' redis.conf  

3.启动redis容器

docker run --name redis-master -p 6379:6379 -d redis
docker run --link redis-master:redis-master -v /home/docker/redis/redis.conf:/usr/local/etc/redis/redis.conf --name redis-slave1 -d redis redis-server /usr/local/etc/redis/redis.conf
docker run --link redis-master:redis-master -v /home/docker/redis/redis.conf:/usr/local/etc/redis/redis.conf --name redis-slave2 -d redis redis-server /usr/local/etc/redis/redis.conf
docker run --link redis-master:redis-master -v /home/docker/redis/redis.conf:/usr/local/etc/redis/redis.conf --name redis-slave3 -d redis redis-server /usr/local/etc/redis/redis.conf 

4.通过一下命令查看redis集群是否成功

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
e1b229de3a36        redis               "docker-entrypoint.sh"   About an hour ago   Up 31 minutes       6379/tcp                 redis-slave3
169d7295d138        redis               "docker-entrypoint.sh"   About an hour ago   Up 31 minutes       6379/tcp                 redis-slave2
ebb4e5414b9f        redis               "docker-entrypoint.sh"   About an hour ago   Up 31 minutes       6379/tcp                 redis-slave1
763c9cca29d4        redis               "docker-entrypoint.sh"   About an hour ago   Up 31 minutes       0.0.0.0:6379->6379/tcp   redis-master

如果出现上述信息说明已经成功搭建完成。
PS:可以通过【docker logs -f 容器id或者容器name】查看日志,
本人在搭建过程中遇到了can’t open config file /usr/local/etc/redis/redis.conf 的错误
第一感觉是redis.conf没有读写权限,赋权777后仍然报此错误,很是郁闷。
后来关掉了selinux才一切正常。

本文参考:https://segmentfault.com/a/1190000004353368,感谢前辈的积累。

你可能感兴趣的:(docker,docker化运维)