当前位置:网站首页>在不同的服务器上基于docker部署redis主从同步
在不同的服务器上基于docker部署redis主从同步
2022-07-30 05:42:00 【就是叫这个名字】
服务器信息:centos7
安装redis版本:7.0.4(最新版)
1.下载redis.conf
# 如果没有安装yum,需要先安装yum
yum -y install wget
# 下载redis.conf
wget http://download.redis.io/redis-stable/redis.conf
2.配置
配置主的redis.conf
(1)注释 # bind 127.0.0.1
(2)关闭保护模式 protected-mode no
(3)允许在后台执行 daemonize yes
(4)(可选)设定密码 requirepass yourpwd
(5)配置日志路径,为了便于排查问题 logfile “/var/log/redis/redis.log”
# bind 127.0.0.1
protected-mode no
daemonize yes
requirepass yourpwd
logfile "/var/log/redis/redis.log"
redis.conf里的配置详解,可参考这篇文章:
https://zhuanlan.zhihu.com/p/73719360
配置从的redis.conf
(1)注释 # bind 127.0.0.1
(2)关闭保护模式 protected-mode no
(3)允许在后台执行 daemonize yes
(4)(可选)设定密码 requirepass yourpwd
(5)配置日志路径,为了便于排查问题 logfile “/var/log/redis/redis.log”
(6)配置主库的ip和端口 replicaof 192.xxx.xxx.xxx 6379
192.xxx.xxx.xxx 是主库所在服务器的ip,6379 是主库redis端口
(7)(视情况而定)如果主库配置了密码,那么这里就填写主库密码;如果主库没设定密码,就不用配 masterauth 主库密码
# bind 127.0.0.1
protected-mode no
daemonize yes
requirepass yourpwd
logfile "/var/log/redis/redis.log"
replicaof 192.xxx.xxx.xxx 6379 # 这里记得替换ip
masterauth 主库密码
部署
(1)在主服务器上执行
# 注意,这里的/root/redis.conf是我存放redis.conf的路径,如果路径不同,这里需要把路径替换一下
# 最后的redis是指redis镜像,默认安装最新版redis,如果想指定版本,在redis后面加”:版本“即可
docker run --name redis_master -v /root/redis.conf:/usr/local/etc/redis/redis.conf -d -p 6379:6379 redis
# 进入容器
docker exec -it redis_master /bin/bash
# 因为上面在redis.conf中配置了日志文件路径logfile "/var/log/redis/redis.log"
# 但容器中实际没有这个路径,所以需要创建
mkdir -p /var/log/redis/
touch /var/log/redis/redis.log
# 在容器里启动一个redis服务端
redis-server /usr/local/etc/redis/redis.conf
# 在容器里启动一个redis客户端
redis-cli
# 如果想要退出容器的话,执行exit即可
在从服务器上执行
# 注意,这里的/root/redis.conf是我存放redis.conf的路径,如果路径不同,这里需要把路径替换一下
# 最后的redis是指redis镜像,默认安装最新版redis,如果想指定版本,在redis后面加”:版本“即可
docker run --name redis-slave -v /root/redis.conf:/usr/local/etc/redis/redis.conf -d -p 6379:6379 redis
# 进入容器
docker exec -it redis_master /bin/bash
# 因为上面在redis.conf中配置了日志文件路径logfile "/var/log/redis/redis.log"
# 但容器中实际没有这个路径,所以需要创建
mkdir -p /var/log/redis/
touch /var/log/redis/redis.log
# 在容器里启动一个redis服务端
redis-server /usr/local/etc/redis/redis.conf
# 在容器里启动一个redis客户端
redis-cli
# 执行info,查看redis信息
info
如果从redis配置了requirepass,那么输入info后会提示没有权限:NOAUTH Authentication required.
输入:auth yourpwd 即可
再输入info
可以看到配置的主redis的信息,master_link_status是up的话代表主从连接正常
去主服务器上用info查看
边栏推荐
猜你喜欢
随机推荐
记一次流量分析实战——安恒科技(八月ctf)
[Net Ding Cup 2020 Qinglong Group] AreUSerialz
Communication middleware Fast DDS basic concepts and communication examples
Operators and Interaction Basics
POI工具类
CTF之misc-内存分析(Volatility)
信息安全必备神器之kali
mysql处理insert冲突的解决方案
awd总结
C# WPF中监听窗口大小变化事件
FastAPI 快速入门
史上超强最常用SQL语句大全
使用Nodejs搭建Web Server(入门教程)
npm安装和npm安装——保存
uni-app: The use of uni-icons and how to customize icons
Competition WP in May
sqli-labs less3/4打靶笔记
3 minutes to tell you how to become a hacker | Zero foundation to hacker introductory guide, you only need to master these five skills
torch分布式训练
npm run serve starts error npm ERR Missing script "serve"





