Redis单机配置多实例,实现主从同步
版权声明:本文为博主原创文章,欢迎转载,转载请保留或注明出处
本文转自:http://www.cnblogs.com/lgeng/p/6623336.html
一,单机多实例:
Redis官网: https://redis.io/
1,安装:
yum -y install gcc gcc-c++ #安装编译工具[root@localhost data]# wget http://download.redis.io/releases/redis-3.2.8.tar.gz [root@localhost data]# tar xzf redis-3.2.8.tar.gz [root@localhost data]# cd redis-3.2.8 [root@localhost data]# make [root@localhost data]# mv redis-3.2.8 /usr/local/redis注意:可直接 yum install redis -y 安装
启动:(默认启动6379端口)[root@localhost redis]# /usr/local/redis/src/redis-server
2,验证:使用 redis-cli命令验证 (注意路径)
[root@localhost src]# /usr/local/redis/src/redis-cli -p 6379 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> set k1 v1 OK 127.0.0.1:6379> keys * 1) "k1" 127.0.0.1:6379> get k1 "v1" 127.0.0.1:6379> 127.0.0.1:6379>
3,配置环境变量
输入redis-server和redis-cli命令,每次输入完整的路径
将路径添加到PATH变量中
echo 'PATH=${PATH}:/usr/local/redis/src/' >> /etc/profile source /etc/profile #<== 重新加载配置文件
二,单机多实例
创建不同实例的数据存放目录 分别创建6380,6381,6382 三个实例
每个实例目录中分别创建 conf,db,log目录,并拷贝配置文件到conf中
[root@localhost /]# mkdir -p /data/redis/{6380,6381,6382}/{conf,db,log} [root@localhost /]# cp /usr/local/redis/redis.conf /data/redis/6380/conf/ [root@localhost /]# cp /usr/local/redis/redis.conf /data/redis/6381/conf/ [root@localhost /]# cp /usr/local/redis/redis.conf /data/redis/6382/conf/ [root@localhost /]# [root@localhost /]# cd /data/redis [root@localhost redis]# ls 6380 6381 6382 [root@localhost redis]# tree . ├── 6380 │ ├── conf │ │ └── redis.conf │ ├── db │ └── log ├── 6381 │ ├── conf │ │ └── redis.conf │ ├── db │ └── log └── 6382├── conf│ └── redis.conf├── db└── log12 directories, 3 files [root@localhost redis]# [root@localhost redis]#
修改配置文件:
将redis.conf修改为对应的实例参数,修改部分如下
[root@localhost redis]# grep "6380\|daemonize" 6380/conf/redis.conf daemonize yes <== daemon进程运行 pidfile /data/redis/6380/redis.pid <== 进程id存放文件 port 6380 <== 端口 logfile /data/redis/6380/log/redis.log <== 日志目录 dir /data/redis/6380/db/ <== db目录 [root@localhost redis]# [root@localhost redis]# grep "6381" 6381/conf/redis.conf daemonize yes pidfile /data/redis/6381/redis.pid port 6381 logfile /data/redis/6381/log/redis.log dir /data/redis/6381/db/ [root@localhost redis]# [root@localhost redis]# grep "6382" 6382/conf/redis.conf daemonize yes pidfile /data/redis/6382/redis.pid port 6382 logfile /data/redis/6382/log/redis.log dir /data/redis/6382/db/ [root@localhost redis]# [root@localhost redis]#
启动实例:
[root@localhost redis]# redis-server /data/redis/6380/conf/redis.conf [root@localhost redis]# redis-server /data/redis/6381/conf/redis.conf [root@localhost redis]# redis-server /data/redis/6382/conf/redis.conf [root@localhost redis]# [root@localhost redis]# netstat -ntlp | grep -E ":6380|:6381|:6382" tcp 0 0 127.0.0.1:6380 0.0.0.0:* LISTEN 14301/redis-server tcp 0 0 127.0.0.1:6381 0.0.0.0:* LISTEN 14305/redis-server tcp 0 0 127.0.0.1:6382 0.0.0.0:* LISTEN 14309/redis-server [root@localhost redis]# [root@localhost redis]#
验证(略) redis-cli -p 6380 ; redi-cli -p 6381 ; redis-cli -p 6382
三,配置主从同步
修改从库配置,6380实例为主库, 从库为 6381,6382
[root@localhost ~]# vim /data/redis/6381/conf/redis.conf [root@localhost ~]# vim /data/redis/6382/conf/redis.conf################################# REPLICATION ################################## Master-Slave replication. Use slaveof to make a Redis instance a copy of # another Redis server. A few things to understand ASAP about Redis replication. # # 1) Redis replication is asynchronous, but you can configure a master to # stop accepting writes if it appears to be not connected with at least # a given number of slaves. # 2) Redis slaves are able to perform a partial resynchronization with the # master if the replication link is lost for a relatively small amount of # time. You may want to configure the replication backlog size (see the next # sections of this file) with a sensible value depending on your needs. # 3) Replication is automatic and does not need user intervention. After a # network partition slaves automatically try to reconnect to masters # and resynchronize with them. # # slaveof <masterip> <masterport> slaveof 127.0.0.1 6380# If the master is password protected (using the "requirepass" configuration # directive below) it is possible to tell the slave to authenticate before # starting the replication synchronization process, otherwise the master will # refuse the slave request. # # masterauth <master-password># When a slave loses its connection with the master, or when the replication # is still in progress, the slave can act in two different ways: # # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will # still reply to client requests, possibly with out of date data, or the # data set may just be empty if this is the first synchronization. # # 2) if slave-serve-stale-data is set to 'no' the slave will reply with # an error "SYNC with master in progress" to all the kind of commands
验证:
先在主库上info一下
[root@localhost 6380]# redis-cli -p 6380 "info" . .此处略去n行 . # Replication role:master <== 角色:master connected_slaves:2 <== slave链接数 2 slave0:ip=127.0.0.1,port=6381,state=online,offset=141,lag=1 <== slave 的信息 slave1:ip=127.0.0.1,port=6382,state=online,offset=141,lag=1 master_repl_offset:141 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:2 repl_backlog_histlen:140
看看从库
[root@localhost 6381]# redis-cli -p 6381 "info" ... .此处略去n行 .... # Replication role:slave <==角色 slave master_host:127.0.0.1 <==master主机 master_port:6380 <== master端口 master_link_status:up <== 链接状态 up master_last_io_seconds_ago:5 master_sync_in_progress:0 slave_repl_offset:673 slave_priority:100 slave_read_only:1 connected_slaves:0 master_repl_offset:0 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0
[root@localhost 6382]# redis-cli -p 6382 "info" ... .此处略去n行 .... # Replication role:slave master_host:127.0.0.1 master_port:6380 master_link_status:up master_last_io_seconds_ago:4 master_sync_in_progress:0 slave_repl_offset:911 slave_priority:100 slave_read_only:1 connected_slaves:0 master_repl_offset:0 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0
在主库上写入数据:
[root@localhost 6380]# redis-cli -p 6380 127.0.0.1:6380> set k1 v1 OK 127.0.0.1:6380> keys * 1) "k1" 127.0.0.1:6380> get k1 "v1" 127.0.0.1:6380>
从库上查看是否已同步
[root@localhost 6381]# redis-cli -p 6381 127.0.0.1:6381> keys * 1) "k1" 127.0.0.1:6381> get k1 "v1" 127.0.0.1:6381> 127.0.0.1:6381> exit [root@localhost 6381]# redis-cli -p 6382 127.0.0.1:6382> keys * 1) "k1" 127.0.0.1:6382> get k1 "v1" 127.0.0.1:6382>
主库删除数据:
[root@localhost 6380]# redis-cli -p 6380 127.0.0.1:6380> keys * 1) "k1" 127.0.0.1:6380> del k1 (integer) 1 127.0.0.1:6380> keys * (empty list or set) 127.0.0.1:6380>
从库查看
[root@localhost 6381]# redis-cli -p 6381 127.0.0.1:6381> keys * (empty list or set) 127.0.0.1:6381> exit [root@localhost 6381]# redis-cli -p 6382 127.0.0.1:6382> keys * (empty list or set) 127.0.0.1:6382> 127.0.0.1:6382> exit [root@localhost 6381]#
END
本文转自:http://www.cnblogs.com/lgeng/p/6623336.html
转载于:https://www.cnblogs.com/lgeng/p/6623336.html
Redis单机配置多实例,实现主从同步相关推荐
- mysql主从三个线程工作顺序_MySQL主从介绍、准备工作、配置主、配置从、测试主从同步...
MySQL主从介绍 MySQL主从又叫做Replication.AB复制.简单讲就是A和B两台机器做主从后,在A上写数据,另外一台B也会跟着写数据,两者数据实时同步.MySQL主从是基于binlog的 ...
- RedHat 6配置DNS服务实现主从同步与正反向解析
本文介绍RedHat 6简单配置DNS服务器,主要包括主从同步与正反向解析. 一.测试环境 主DNS服务器:DNS01:192.168.10.1 从DNS服务器:DNS02:192.168.10.2 ...
- MySQL主从介绍、准备工作、配置主、配置从、测试主从同步、断电后恢复主从...
MySQL主从介绍 MySQL主从又叫做Replication.AB复制.简单讲就是A和B两台机器做主从后,在A上写数据,另外一台B也会跟着写数据,两者数据实时同步.MySQL主从是基于binlog的 ...
- mysql主从同步配置超详细_MySQL主从同步配置
一. 理论部分 MySQL主从同步 主从同步使得数据可以从一个数据库服务器复制到其他的服务器上.在复制数据时,一个服务器充当主服务器(master),其余的服务器充当从服务器(slave). 因为复制 ...
- mariadb mysql同步_CentOS7安装配置MariaDB(mysql)数据主从同步
CentOS7安装MariaDB并配置主从同步 环境声明: 防火墙firewalld及SElinux均为关闭状态 主库节点:192.168.0.63 从库节点:192.168.0.64 配置主库节点: ...
- yum方式安装mysql多实例_centos7下yum安装mysql5.6.30及单机配置多实例
1.在mysql官网上载tar包 MySQL-5.6.30-1.el6.i686.rpm-bundle.tar 进目录cd /home/fuyouling/ 解压tar -xvf MySQL-5.6. ...
- mysql多实例主从_window 下 mysql 单机多实例以及主从同步
主MySQL my.ini 配置 # mysql server 的唯一id server_id = 3306 log-bin=log # 需要同步的数据库 binlog-do-db=faner # 不 ...
- mysql 5.6 主从同步配置_Mysql 5.6主从同步配置
特别提示:本方法适用于mysql5.6版本,5.6以前的版本配置方法不同,我没有做测试 由于一主多从和一主一从的配置方法一样,所以本文仅测试一主一从,可自主扩展到多从 环境: server1 mast ...
- linux mysql主从配置_Linux下Mysql主从同步配置
实现MySQL主从复制配置 准备两台有MySQL的服务器 1 主master:192.168.0.55 2 从slave : 192.168.0.56 01 THE FIRST 主库授权给从数据库服务 ...
最新文章
- Java虚拟机规范阅读(二)IEEE754简介以及Java虚拟机中的浮点算法
- 一周焦点 | 最强AI芯片麒麟980发布;前端开发者将被取代?
- 邮件客户端WebMail Pro v7.7.5发布,在线订购限时75折优惠!
- 如何评价马云和马斯克在世界人工智能大会的对话?
- 树的子结构 (剑指offer)
- 未安装在此服务器场中,无法添加到该范围
- 呼叫中心团队管理浅谈
- DC-DC电源输出纹波测量的方法
- 64位操作系统的原理
- laravel-admin配置安装完新手使用
- 宝骏530中控屏怎么安装软件_试驾2020款宝骏530:大屏加六座,就这么直接
- kafka可靠数据传递
- 快速上手Tomcat
- javascript函数的声明,及返回值
- for循环的一个复制算法(Java)
- 6to5 – 让你即刻体验 ECMAScript 6 编程
- vs2005下使用ASPNetPage分页的例子1
- 微信小程序引入阿里矢量图标库
- VB的阶乘和伽马函数
- MATLAB角度转换
热门文章
- echarts热力背景图_Echarts 图表中设置背景图片
- PHP面试题:简述Linux下安装PHP的过程?
- 常见Java面试题 抽象类能使用 final 修饰吗?
- npm——安装教程、安装vue脚手架(ASP.NET Core微服务(五)——【vue脚手架解析接口】过度章节)
- AVG杀毒软件添加信任程序
- ORACLE TEXT FILTER PREFERENCE(二)
- 常见的社会潜规则有哪些?
- (二十九)、Java字符串中去除空格
- “每日 4 +1 问”理念之体重记录
- 一封电子邮件的发送和接收的主要步骤