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..tar.gz
[root@localhost data]# cd redis-3.2.
[root@localhost data]# make
[root@localhost data]# mv redis-3.2. /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
127.0.0.1:> keys *
(empty list or set)
127.0.0.1:> set k1 v1
OK
127.0.0.1:> keys *
) "k1"
127.0.0.1:> get k1
"v1"
127.0.0.1:>
127.0.0.1:>

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/{,,}/{conf,db,log}
[root@localhost /]# cp /usr/local/redis/redis.conf /data/redis//conf/
[root@localhost /]# cp /usr/local/redis/redis.conf /data/redis//conf/
[root@localhost /]# cp /usr/local/redis/redis.conf /data/redis//conf/
[root@localhost /]#
[root@localhost /]# cd /data/redis
[root@localhost redis]# ls
[root@localhost redis]# tree
.
├──
│ ├── conf
│ │ └── redis.conf
│ ├── db
│ └── log
├──
│ ├── conf
│ │ └── redis.conf
│ ├── db
│ └── log
└──
├── conf
│ └── redis.conf
├── db
└── log
directories, files
[root@localhost redis]#
[root@localhost redis]#
修改配置文件:
将redis.conf修改为对应的实例参数,修改部分如下
[root@localhost redis]# grep "6380\|daemonize" /conf/redis.conf
daemonize yes <== daemon进程运行
pidfile /data/redis//redis.pid <== 进程id存放文件
port <== 端口
logfile /data/redis//log/redis.log <== 日志目录
dir /data/redis//db/ <== db目录
[root@localhost redis]#
[root@localhost redis]# grep "" /conf/redis.conf
daemonize yes
pidfile /data/redis//redis.pid
port
logfile /data/redis//log/redis.log
dir /data/redis//db/
[root@localhost redis]#
[root@localhost redis]# grep "" /conf/redis.conf
daemonize yes
pidfile /data/redis//redis.pid
port
logfile /data/redis//log/redis.log
dir /data/redis//db/
[root@localhost redis]#
[root@localhost redis]#
启动实例:
[root@localhost redis]# redis-server /data/redis//conf/redis.conf
[root@localhost redis]# redis-server /data/redis//conf/redis.conf
[root@localhost redis]# redis-server /data/redis//conf/redis.conf
[root@localhost redis]#
[root@localhost redis]# netstat -ntlp | grep -E ":6380|:6381|:6382"
tcp 127.0.0.1: 0.0.0.0:* LISTEN /redis-server
tcp 127.0.0.1: 0.0.0.0:* LISTEN /redis-server
tcp 127.0.0.1: 0.0.0.0:* LISTEN /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//conf/redis.conf
[root@localhost ~]# vim /data/redis//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.
#
# ) 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.
# ) 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.
# ) 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 # 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:
#
# ) 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.
#
# ) 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 ]# redis-cli -p "info"
.
.此处略去n行
.
# Replication
role:master <== 角色:master
connected_slaves: <== slave链接数
slave0:ip=127.0.0.1,port=,state=online,offset=,lag= <== slave 的信息
slave1:ip=127.0.0.1,port=,state=online,offset=,lag=
master_repl_offset:
repl_backlog_active:
repl_backlog_size:
repl_backlog_first_byte_offset:
repl_backlog_histlen:
看看从库
[root@localhost ]# redis-cli -p "info"
...
.此处略去n行
....
# Replication
role:slave <==角色 slave
master_host:127.0.0.1 <==master主机
master_port: <== master端口
master_link_status:up <== 链接状态 up
master_last_io_seconds_ago:
master_sync_in_progress:
slave_repl_offset:
slave_priority:
slave_read_only:
connected_slaves:
master_repl_offset:
repl_backlog_active:
repl_backlog_size:
repl_backlog_first_byte_offset:
repl_backlog_histlen:
[root@localhost ]# redis-cli -p "info"
...
.此处略去n行
....
# Replication
role:slave
master_host:127.0.0.1
master_port:
master_link_status:up
master_last_io_seconds_ago:
master_sync_in_progress:
slave_repl_offset:
slave_priority:
slave_read_only:
connected_slaves:
master_repl_offset:
repl_backlog_active:
repl_backlog_size:
repl_backlog_first_byte_offset:
repl_backlog_histlen:
在主库上写入数据:
[root@localhost ]# redis-cli -p
127.0.0.1:> set k1 v1
OK
127.0.0.1:> keys *
) "k1"
127.0.0.1:> get k1
"v1"
127.0.0.1:>
从库上查看是否已同步
[root@localhost ]# redis-cli -p
127.0.0.1:> keys *
) "k1"
127.0.0.1:> get k1
"v1"
127.0.0.1:>
127.0.0.1:> exit
[root@localhost ]# redis-cli -p
127.0.0.1:> keys *
) "k1"
127.0.0.1:> get k1
"v1"
127.0.0.1:>
主库删除数据:
[root@localhost ]# redis-cli -p
127.0.0.1:> keys *
) "k1"
127.0.0.1:> del k1
(integer)
127.0.0.1:> keys *
(empty list or set)
127.0.0.1:>
从库查看
[root@localhost ]# redis-cli -p
127.0.0.1:> keys *
(empty list or set)
127.0.0.1:> exit
[root@localhost ]# redis-cli -p
127.0.0.1:> keys *
(empty list or set)
127.0.0.1:>
127.0.0.1:> exit
[root@localhost ]#
END
本文转自:http://www.cnblogs.com/lgeng/p/6623336.html
Redis单机配置多实例,实现主从同步的更多相关文章
- redis master配置了密码进行主从同步
1.如果master不设置密码,那么直接在slave服务器配置slaveof即可 配置如下 #slaveof ip 端口 slaveof 配置好我们看下redis的日志 看是否同步成功 :S Jan ...
- redis多实例与主从同步及高级特性(数据过期机制,持久化存储)
redis多实例 创建redis的存储目录 vim /usr/local/redis/conf/redis.conf #修改redis的配置文件 dir /data/redis/ #将存储路径配置修改 ...
- redis配置文件详解及实现主从同步切换
原理:redis复制是怎么进行工作 如果设置了一个slave,不管是在第一次链接还是重新链接master的时候,slave会发送一个同步命令 然后master开始后台保存,收集所有对修改数据的命令.当 ...
- MySQL多实例,主从同步
由于背景原因,所做的主从同步还是要基于MySQL 5.1的版本,主从同步主要是一个数据库读写访问原来的数据库热度过大,需要做到使用从库对读分压. MySQL主从同步介绍 MySQL 支持单双向 ...
- Redis 单机和多实例部署
作者:北京运维 1. 安装环境说明 OS 版本:CentOS 7.5.1804 Redis 版本:redis-3.2.12 Redis 下载页面:http://download.redis.io/re ...
- mysql数据库的多实例与主从同步。
1.MySQL的多实例: 多实例的特点:能够有效地利用服务器的资源,节约服务器的资源 MySQL多实例的配置有两种,第一是使用一个配置文件,这种方法不推荐使用,容易出错:第二种是用多个配置文件,这种方 ...
- CentOS7安装配置MariaDB(mysql)数据主从同步
CentOS7安装MariaDB并配置主从同步 环境声明: 防火墙firewalld及SElinux均为关闭状态 主库节点:192.168.0.63 从库节点:192.168.0.64 配置主库节点: ...
- Linux centosVMware MySQL主从介绍、准备工作、配置主、配置从、测试主从同步
一.MySQL主从介绍 MySQL主从又叫做Replication.AB复制.简单讲就是A和B两台机器做主从后,在A上写数据,另外一台B也会跟着写数据,两者数据实时同步的 MySQL主从是基于binl ...
- Redis单机配置以及集群(sentinel、jediscluster)配置
最近一直在使用Redis作为缓存数据库,在使用当中,刚开始没有注意配置问题. 1.纯粹的注入单机模式 <bean id="jedisPoolConfig" class=&qu ...
随机推荐
- Selenium自动化 Xpath-元素定位
最近在教妹子做自动化测试,妹子基础差,于是想到很多初学自动化的朋友们学习的知识没有规范化,信息太过杂乱.所以,本文整理了一些自动化元素定位方式: 这次将讲Xpath定位! 什么是Xpath: Path ...
- 【Dojo 1.x】笔记2 使用服务器环境及使用模块
又开坑了.上次静态html页面完成本地module的引用,算是成功了,但是并不知道是怎么运作的,没关系慢慢来. 我用的环境是VSCode,这次因为官方说要在服务器环境下运行,所以就用上了VSCode的 ...
- arcgis api 3.x for js 入门开发系列二不同地图服务展示(附源码下载)
前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...
- Centos7 系统下搭建.NET Core2.0+Nginx+Supervisor+Mysql环境
好记性不如烂笔头! 一.简介 一直以来,微软只对自家平台提供.NET支持,这样等于让这个“理论上”可以跨平台的框架在Linux和macOS上的支持只能由第三方项目提供(比如Mono .NET).直到微 ...
- Android人脸识别App(带web上传注册信息)
人脸识别+本机Web后端人脸sdk采用虹软sdk,本机web采用AndServer:上传姓名+人脸图片即可实现注册源码地址:https://github.com/joetang1989/ArcFace ...
- 从零学习Fluter(三):Flutter的路由跳转以及state的生命周期
今天继续研究Flutter,我是在flutter1.0发布后,才玩flutter的,发现在此之前,许多人已经先发制人,玩起了flutter,不知不觉中,我已经被别人摔在了起跑线上,玩过flutter后 ...
- log4j详细配置
参考博客:https://blog.csdn.net/sinat_30185177/article/details/73550377 log4j..很简单好用的一个记录日志的东东,正因为好用,本人从来 ...
- SQL Server 数据库调整表中列的顺序操作
SQL Server 数据库中表一旦创建,我们不建议擅自调整列的顺序,特别是对应的应用系统已经上线,因为部分开发人员,不一定在代码中指明了列名.表是否可以调整列的顺序,其实可以自主设置,我们建议在安装 ...
- c# winform多线程实时更新控件
//创建委托 private delegate void SetTextCallback(string text); /// <summary> / ...
- C#-委托delegate
目录 委托的定义 委托的声明 委托的实例 委托的注意细节 泛型委托(详见<精通C#>--10.4泛型委托) 1.Action<>委托 3.Func<>委托 附录 委 ...