当前位置:网站首页>在不同的服务器上基于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查看
边栏推荐
猜你喜欢

【文献阅读】Age Progress/Regression by Conditional Adversarial Autoencoder 基于条件对抗自编码器(CAAE)的老化/去龄化方案

Solution to TypeError The view function did not return a valid response. The function either returned None

uni-app: about custom components, easycom specs, uni_modules, etc.

关于浅拷贝和深拷贝,草稿闲了写

jsonpath

五月份比赛WP

2022CISCNmisc

Arrays工具类的使用

Powerhouse Cup Preliminary WP
![[MATLAB]图像处理——交通标志的识别](/img/45/1a5797a17ebf6db965a64c85e0f037.png)
[MATLAB]图像处理——交通标志的识别
随机推荐
FastAPI 快速入门
用h1~h5标题时候,但是如果不要加粗的效果,处理方法如下
典型线程问题综合演示
中间件cors三行代码解决跨域问题GET,POST跨域访问解决
php-fpm
Blind injection, error injection, wide byte injection, stack injection study notes
Misc-traffic analysis of CTF
sqli-labs less3/4打靶笔记
FastAPI 快速入门
运算符和交互基础
js 实现自定义签名
npm安装和npm安装——保存
js基础 判断数据类型
CTF之misc-图片隐写
3 minutes to tell you how to become a hacker | Zero foundation to hacker introductory guide, you only need to master these five skills
The operations engineer interview experience
DVWA installation tutorial (understand what you don't understand · in detail)
MySQL storage engine
uni-app installs components using npm commands
Art-template 中文文档[详细篇]