我做了一个导航站(域名是挂路灯的全拼gualudeng.com),里面精选了各种影视,动漫,黑科技,实用工具,搞笑有趣的站点,动动大家可爱的小手,点进来看看吧,良心站点。
1.1.创建docker-compose.yml 文件。注意在yml文件中,image冒号后要有空格。(文件格式问题)。为了安全 不必为 redis 进行端口映射。
version: "3"
services:
redis1:
image: redis
volumes:
- /vagrant_data/redis_cluster:/usr/local/etc/redis
command: bash -c "redis-server /usr/local/etc/redis/redis1.conf"
redis2:
image: redis
volumes:
- /vagrant_data/redis_cluster:/usr/local/etc/redis
command: bash -c "redis-server /usr/local/etc/redis/redis2.conf"
redis3:
image: redis
volumes:
- /vagrant_data/redis_cluster:/usr/local/etc/redis
command: bash -c "redis-server /usr/local/etc/redis/redis3.conf"
redis4:
image: redis
volumes:
- /vagrant_data/redis_cluster:/usr/local/etc/redis
command: bash -c "redis-server /usr/local/etc/redis/redis4.conf"
1.2.修改各个redis配置文件
对于master节点
修改 bind 0.0.0.0 保证各个节点之间能互相通信
修改 protected_mode 为 no
设置密码 requirepass 123456
对于从节点还要添加
replicaof master 6379
masterauth 123456 组节点密码,自己不需要配置密码
设置密码 requirepass 123456 (从节点也可以设置密码,但是主节点需要设置masterauth 123456)
1.3.常用操作命令
进入redis-cli 后 查看节点信息 info replication
手动配置从节点 slaveof master 6379
docker logs container 查看docker 日志信息
2.1 redis主从复制的哨兵模式
version: "3"
services:
redis1:
image: redis
volumes:
- /vagrant_data/redis_cluster:/usr/local/etc/redis
command:
- sh
- -c
- |
redis-server /usr/local/etc/redis/redis1.conf &
redis-sentinel /usr/local/etc/redis/sential.conf
redis2:
image: redis
volumes:
- /vagrant_data/redis_cluster:/usr/local/etc/redis
command:
command:
- sh
- -c
- |
redis-server /usr/local/etc/redis/redis2.conf &
redis-sentinel /usr/local/etc/redis/sential.conf
redis3:
image: redis
volumes:
- /vagrant_data/redis_cluster:/usr/local/etc/redis
command:
- sh
- -c
- |
redis-server /usr/local/etc/redis/redis3.conf &
redis-sentinel /usr/local/etc/redis/sential.conf
redis4:
image: redis
volumes:
- /vagrant_data/redis_cluster:/usr/local/etc/redis
command:
- sh
- -c
- |
redis-server /usr/local/etc/redis/redis4.conf &
redis-sentinel /usr/local/etc/redis/sential.conf
2.2 sential.conf 配置文件
port 26379
sentinel monitor mymaster redis1 6379 1
#sentinel auth-pass mymaster 123456 (配置密码可能会出现宕机后从机连不上新主机)
protected-mode no