版权声明:本文为博主原创文章,欢迎转载,转载请保留或注明出处
本文转自: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单机配置多实例,实现主从同步的更多相关文章

  1. redis master配置了密码进行主从同步

    1.如果master不设置密码,那么直接在slave服务器配置slaveof即可 配置如下 #slaveof ip 端口 slaveof 配置好我们看下redis的日志 看是否同步成功 :S Jan ...

  2. redis多实例与主从同步及高级特性(数据过期机制,持久化存储)

    redis多实例 创建redis的存储目录 vim /usr/local/redis/conf/redis.conf #修改redis的配置文件 dir /data/redis/ #将存储路径配置修改 ...

  3. redis配置文件详解及实现主从同步切换

    原理:redis复制是怎么进行工作 如果设置了一个slave,不管是在第一次链接还是重新链接master的时候,slave会发送一个同步命令 然后master开始后台保存,收集所有对修改数据的命令.当 ...

  4. MySQL多实例,主从同步

    由于背景原因,所做的主从同步还是要基于MySQL 5.1的版本,主从同步主要是一个数据库读写访问原来的数据库热度过大,需要做到使用从库对读分压. MySQL主从同步介绍     MySQL 支持单双向 ...

  5. Redis 单机和多实例部署

    作者:北京运维 1. 安装环境说明 OS 版本:CentOS 7.5.1804 Redis 版本:redis-3.2.12 Redis 下载页面:http://download.redis.io/re ...

  6. mysql数据库的多实例与主从同步。

    1.MySQL的多实例: 多实例的特点:能够有效地利用服务器的资源,节约服务器的资源 MySQL多实例的配置有两种,第一是使用一个配置文件,这种方法不推荐使用,容易出错:第二种是用多个配置文件,这种方 ...

  7. CentOS7安装配置MariaDB(mysql)数据主从同步

    CentOS7安装MariaDB并配置主从同步 环境声明: 防火墙firewalld及SElinux均为关闭状态 主库节点:192.168.0.63 从库节点:192.168.0.64 配置主库节点: ...

  8. Linux centosVMware MySQL主从介绍、准备工作、配置主、配置从、测试主从同步

    一.MySQL主从介绍 MySQL主从又叫做Replication.AB复制.简单讲就是A和B两台机器做主从后,在A上写数据,另外一台B也会跟着写数据,两者数据实时同步的 MySQL主从是基于binl ...

  9. Redis单机配置以及集群(sentinel、jediscluster)配置

    最近一直在使用Redis作为缓存数据库,在使用当中,刚开始没有注意配置问题. 1.纯粹的注入单机模式 <bean id="jedisPoolConfig" class=&qu ...

随机推荐

  1. Java开发笔记(二十二)神奇的冒号

    Java中的标点符号主要有两类用途,一类是运算符,包括加号+.减号-.乘号*.除号/.取余号%.等号=.大于号>.小于号<.与号&.或号|.非号!.异或号^等等,另一类则是分隔符, ...

  2. Linux文件系统的基本结构

    Linux文件系统结构 通过下面两张图片来认识一下Linux文件系统的结构. 当前工作目录 实践: 文件名称 这些规则不仅适用于文件,也适用于文件夹. 实践: ls命令 ls命令表示列出当前工作目录的 ...

  3. Laravel5中通过SimpleQrCode扩展包生成二维码实例

    Simple Qrcode是基于强大的Bacon/BaconQrCode库开发的针对Laravel框架的封装版本,用于在Laravel中为生成二维码提供接口. 安装SimpleQrCode扩展包 在项 ...

  4. jsp基础语言-jsp表达式

    1.jsp表达式作用:将动态信息显示在页面中. 2.jsp表达式语法:<%=变量或表达式%> 变量:要在页面显示的值的变量名 表达式:其值由服务器计算,计算结果以字符串的形式发送到客户端 ...

  5. ifram 局部刷新,不刷新父级

    function loadIframe(url) { //获取url链接 var u = window.location.href; //因为每次获取的链接中都有之前的旧锚点, //所以需要把#之后的 ...

  6. thymeleaf的配置

    1.在springboto项目中使用thymeleaf标签,必须先添加依赖,如下. <dependency> <groupId>org.springframework.boot ...

  7. android view 转Bitmap 生成截图

    文章链接:https://mp.weixin.qq.com/s/FQmYfT-KYiDbp-0HzK_Hpw 项目中经常会用到分享的功能,有分享链接也有分享图片,其中分享图片有的需要移动端对屏幕内容进 ...

  8. MTK Android O1平台预置apk

    在MTK Android O1平台预置apk为可卸载时.预置到旧的路径system/vendor/operator/app会编译报错,"You cannot install files to ...

  9. Spark SQL,如何将 DataFrame 转为 json 格式

    今天主要介绍一下如何将 Spark dataframe 的数据转成 json 数据.用到的是 scala 提供的 json 处理的 api. 用过 Spark SQL 应该知道,Spark dataf ...

  10. 网上都没有提到的教程:python捕获异常后,怎么输出错误文件和行号

    1.假设输出不存在的变量 a try: print(a) except NameError as e: print('发生错误的文件:', e.__traceback__.tb_frame.f_glo ...