• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
⁰¹.₂₂梁℘࿐的博客
博客园    首页    新随笔    联系   管理    订阅  订阅

安装部署:Redis主从复制

基础环境:redis已编译安装好,正常运行:

# cp /usr/local/src/redisxxx.xx/redis.conf  /etc/redis.conf

主redis的配置文件如下:

# vim /etc/redis.conf

从redis的配置文件名为:

# cp /etc/redis.conf /etc/redis-slave.conf 
# vim /etc/redis-slave.conf
    daemonize yes
    port 6380 #从redis的端口设为6380
    slaveof 192.168.5.110 6379 #指定主redis的ip及端口
修改:
    bind 127.0.0.1(删掉) 改成 bind 192.168.152.130 (本机IP)
保存退出

启动主、从redis:

# ./redis-server /etc/redis.conf #用默认的/etc/redis.conf启动redis,作为主
# ./redis-server /etc/redis-slave.conf #用从配置的/etc/redis-slave.conf再启动一个redis,作为从

验证:

# netstat -ntulp|grep 63

完成后在从上查看redis信息:

10.30.36.11:6380> info

测试主从redis的数据同步:

方法一:
telnet 127.0.0.1 6379   #登上主redis
set name 1409e   #写入一个键值对 name:1409e
+OK
get name   #取出name键的值
$5
1409e
quit   #退出主redis
telnet 127.0.0.1 6380   #登上从redis
slaveof 127.0.0.1 6379   # 同步一下主
get name   #取出name键值
$5
1409e   #可以取出说明主从redis的数据已同步
Quit
方法二:
redis-cli -h 192.168.152.135  -p 6379 set cobe 39   #主redis中写入键值
redis-cli  -h 192.168.152.135 -p 6380 get cobe   #从redis中获取该键值

停止reids:
redis-cli -h 127.0.0.1 -p 6379 shutdown
删除从库:
在从上执行以下命令即可:
slaveof  no  one
posted @ 2020-10-07 08:56  ⁰¹.₂₂梁℘࿐  阅读(26)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3