版权声明:本文为博主原创文章,欢迎转载,转载请保留或注明出处
本文转自: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. nginx系列1:认识nginx

    nginx介绍 nginx是什么呢?可以看下官方网站的定义: nginx [engine x] is an HTTP and reverse proxy server, a mail proxy se ...

  2. Flask 系列之 Migration

    说明 操作系统:Windows 10 Python 版本:3.7x 虚拟环境管理器:virtualenv 代码编辑器:VS Code 实验目标 通过使用 flask-migrate 实现数据库的迁移操 ...

  3. vue结合axios使用入门

    Vue官方推荐的网络通信库不再是vue-resource了,推荐使用axios axios安装 npm: $ npm install axios bower: $ bower install axio ...

  4. webpack 4 简单介绍

    webpack是什么? webpack是一个现代JavaScript应用程序的静态模块打包器(module bundler). 为什么要使用webpack呢? 随着web技术的发展,前端开发不再仅仅是 ...

  5. SAP MM盘点流程里如何处理事务代码MI11 Recount过的盘点凭证?

    SAP MM盘点流程里如何处理事务代码MI11 Recount过的盘点凭证? 1, MI01 create a physical inventory document, 2, MI04 to inpu ...

  6. 【Dojo 1.x】笔记7 配置对象dojoConfig的内容1:has属性、加载器的属性

    说完了出身,即出身自dojo/_base/目录下的config模块,那就要好好讲讲这对象有什么可以写的属性了. 1. has属性 官方说是用于更好的特征检测的,具体有什么用现在还不得知. 例如: &l ...

  7. react基础语法二

    这里只是对自己的学习进行一次总结,也是为了让自己以后如果长时间不使用快速记忆起来的笔记,如果想要学习,还是去官网看文档比较好一些.. 注意 下面的代码的 script标签的type类型都为 “text ...

  8. SQL Server -- 回忆笔记(三):ADO.NET之C#操作数据库

    SQL Server知识点回忆篇(三):ADO.NET之C#操作数据库 1.连接数据库 (1)创建连接字符串: 使用windows身份验证时的连接字符串: private string conStr= ...

  9. Python运算符之翩若惊鸿,婉若游龙

    python中的运算符算术运算符:主要用于两个对象算数计算(加减乘除等运算)比较运算符:用于两个对象比较(判断是否相等.大于等运算)赋值运算符:用于对象的赋值,将运算符右边的值(或计算结果)赋给运算符 ...

  10. local_irq_disable和disable_irq的区别

    local_irq_disable: local_irq_disable的功能是屏蔽当前CPU上的所有中断,通过操作arm核心中的寄存器来屏蔽到达CPU上的中断,此时中断控制器中所有送往该CPU上的中 ...