Redis笔记-集群搭建
Redis单机版搭建上一篇已经基本介绍了,下面讨论Redis集群搭建方案和示例。
1、关于Redis常用的集群方案(三种):
a、一主多从,如一个Master、两个Slave
b、薪火相传,即集群中的从节点(Slave)同时也是主节点(Master),类似于链式传递一样
c、反客为主,主节点down掉后从节点升级为主节点,通过人工干预 或者 通过Sentinel 哨兵模式来实现(下篇介绍)
2、模拟测试(以一主多从为例)
模拟主机信息(在同一台主机通过不同端口模拟):
| 角色 | IP | 端口 |
| Master | 127.0.0.1 | 6379 |
| Salve | 127.0.0.1 | 6380 |
| Salve | 127.0.0.1 | 6381 |
进入Redis目录,复制redis配置文件,给Slave使用:
[root@VM_0_14_centos redis]# ls -lrt
total
-rwxr-xr-x root root Mar : redis-server
-rwxr-xr-x root root Mar : redis-cli
-rw-r--r-- root root Mar : redis.conf
[root@VM_0_14_centos redis]# cp redis.conf ./redis..conf
[root@VM_0_14_centos redis]# cp redis.conf ./redis..conf
[root@VM_0_14_centos redis]#
编辑Master配置文件redis.conf文件,主要配置以下参数:
daemonize yes #开启守护进程
pidfile /var/run/redis_6379.pid #开启守护进程后会将进程ID写入该文件
logfile "/var/log/redis.6379.log" #配置日志文件
masterauth funnyboy0128 #master验证密码
requirepass funnyboypass #Redis登录密码
编辑Slave配置文件redis.6380.conf 和redis.6381.conf ,修改pidfile和logfile的值,并在最后追加 slaveof 配置项,修改端口分贝为6380和6380
port 6380 和 port 6381
slaveof 127.0.0.1 6379 #Master的I配合端口
启动Master节点:
[root@VM_0_14_centos redis]#
[root@VM_0_14_centos redis]#
[root@VM_0_14_centos redis]#
[root@VM_0_14_centos redis]# ./redis-server ./redis.conf
启动Slave节点:
[root@VM_0_14_centos redis]#
[root@VM_0_14_centos redis]#
[root@VM_0_14_centos redis]# ./redis-server ./redis..conf
[root@VM_0_14_centos redis]# ./redis-server ./redis..conf
[root@VM_0_14_centos redis]#
客户端连接测试:
[root@VM_0_14_centos redis]#
[root@VM_0_14_centos redis]# ./redis-cli -h 127.0.0.1 -p -a funnyboypass
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:> keys *
(empty list or set)
127.0.0.1:> set name hello redis
(error) ERR syntax error
127.0.0.1:> set name "hello redis"
OK
127.0.0.1:>
127.0.0.1:>
127.0.0.1:> get name
"hello redis"
127.0.0.1:>
连接Master,set信息到Redis。然后连接Slave查看数据,
[root@VM_0_14_centos redis]#
[root@VM_0_14_centos redis]# ./redis-cli -h 127.0.0.1 -p -a funnyboypass
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:>
127.0.0.1:>
127.0.0.1:>
127.0.0.1:> get name
"hello redis"
127.0.0.1:>
6380 Slave节点数据OK。
[root@VM_0_14_centos redis]# ./redis-cli -h 127.0.0.1 -p -a funnyboypass
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:> get name
"hello redis"
127.0.0.1:>
127.0.0.1:>
测试Slave是否支持写入:
127.0.0.1:>
127.0.0.1:> set sname hello
(error) READONLY You can't write against a read only replica.
127.0.0.1:>
结果显示Slave值只支持读操作。
补充关于redis.conf相关的配置项:
1、daemonize 如果需要在后台运行,把该项改为yes
2、pidfile 配置多个pid的地址 默认在/var/run/redis.pid
3、bind 绑定ip,设置后只接受来自该ip的请求
4、port 监听端口,默认是6379
5、loglevel 分为4个等级:debug verbose notice warning
6、logfile 用于配置log文件地址
7、databases 设置数据库个数,默认使用的数据库为0
8、save 设置redis进行数据库镜像的频率。
9、rdbcompression 在进行镜像备份时,是否进行压缩
10、dbfilename 镜像备份文件的文件名
11、Dir 数据库镜像备份的文件放置路径
12、Slaveof 设置数据库为其他数据库的从数据库
13、Masterauth 主数据库连接需要的密码验证
14、Requriepass 设置 登陆时需要使用密码
15、Maxclients 限制同时使用的客户数量
16、Maxmemory 设置redis能够使用的最大内存
17、Appendonly 开启append only模式
18、Appendfsync 设置对appendonly.aof文件同步的频率(对数据进行备份的第二种方式)
19、vm-enabled 是否开启虚拟内存支持 (vm开头的参数都是配置虚拟内存的)
20、vm-swap-file 设置虚拟内存的交换文件路径
21、vm-max-memory 设置redis使用的最大物理内存大小
22、vm-page-size 设置虚拟内存的页大小
23、vm-pages 设置交换文件的总的page数量
24、vm-max-threads 设置VM IO同时使用的线程数量
25、Glueoutputbuf 把小的输出缓存存放在一起
26、hash-max-zipmap-entries 设置hash的临界值
27、Activerehashing 重新hash
Redis笔记-集群搭建的更多相关文章
- Redis本地集群搭建(5版本以上)
Redis本地集群搭建(5版本以上) 2019年11月3日10:05:48 步骤 1.下载安装Redis的安装包 2.复制5份,一共6份Redis的解压安装版,修改每个Redis节点的端口并开启节点 ...
- redis的集群搭建(很详细很详细)
说在前面的话 之前有一节说了redis单机版的搭建和使用jedis管理redis单机版和集群版, 本节主要讲一下redis的集群搭建. 跳转到jedis管理redis的使用 认识redis集群 首先我 ...
- linux环境下redis安装(redis伪集群搭建)
redis在linux环境下搭建 1.创建目录 [root@192 local]# mkdir /usr/local/redis 2.下载redis,并解压 [root@192 local]# wge ...
- Redis学习笔记(5)—— Redis的持久化方案&Redis的集群搭建
一.Redis的持久化方案 Redis的高性能是由于其将所有数据都存储在了内存中,为了使Redis在重启之后仍能保证数据不丢失,需要将数据从内存中同步到硬盘中,这一过程就是持久化. Redis支持两种 ...
- Redis Cluster集群搭建与应用
1.redis-cluster设计 Redis集群搭建的方式有多种,例如使用zookeeper,但从redis 3.0之后版本支持redis-cluster集群,redis-cluster采用无中心结 ...
- redis主从集群搭建及容灾部署(哨兵sentinel)
Redis也用了一段时间了,记录一下相关集群搭建及配置详解,方便后续使用查阅. 提纲 Redis安装 整体架构 Redis主从结构搭建 Redis容灾部署(哨兵sentinel) Redis常见问题 ...
- Redis Cluster集群搭建与配置
Redis Cluster是一种服务器sharding分片技术,关于Redis的集群方案应该怎么做,请参考我的另一篇博客http://www.cnblogs.com/xckk/p/6134655.ht ...
- Redis的搭建和Redis的集群搭建
1.Redis的官网:https://redis.io/ Redis的测试网站:http://try.redis.io/ 2.参考博客:https://www.cnblogs.com/maf ...
- 【Redis】Redis cluster集群搭建
Redis集群基本介绍 Redis 集群是一个可以在多个 Redis 节点之间进行数据共享的设施installation. Redis 集群不支持那些需要同时处理多个键的 Redis 命令, 因为执行 ...
随机推荐
- ef和mysql使用(一)
ef开发模式有3种:DateBase First(数据库优先).Model First(模型优先)和Code First(代码优先).这里我用的是code first 一个简单的例子: public ...
- 解决ruby安装后无法添加淘宝gem源------------学习记录
使用sass ,需要安装ruby,会建议移除gem源,添加淘宝的gem源,但是淘宝的镜像源已经停止维护啦!!用https://gems.ruby-china.com 代替即可. 操作如下: 1)删除原 ...
- openlayers4 入门开发系列之台风轨迹篇
前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...
- vue 对列表数组删除和增加
很重要,一定要好好研究 https://cn.vuejs.org/v2/guide/list.html#%E6%9B%BF%E6%8D%A2%E6%95%B0%E7%BB%84
- Win7 + CentOS7 双系统
记录一下更改系统启动菜单的方法. 前提: 1. 先安装 Win7 在硬盘第一分区,其它分区在 Win7 下处于未分配状态. 2. 再安装 CentOS 到上述未分配分区.(注意:手动分区时,可以留一定 ...
- 双因素认证(2FA)教程
所谓认证(authentication)就是确认用户的身份,是网站登录必不可少的步骤. 密码是最常见的认证方法,但是不安全,容易泄露和冒充. 越来越多的地方,要求启用 双因素认证(Two-factor ...
- 《深入理解 JVM 虚拟机》 --- 看书笔记
1.JVM 内存溢出 1.堆溢出:堆要不断的创建对象,如果避免了垃圾回收来清除这些对象,就会产生JVM内存溢出.一般手段是通过内存映像分析工具对Dump出来的堆转储快照进行分析,分清楚到底是内存泄露还 ...
- Entity Framework 查漏补缺 (二)
数据加载 如下这样的一个lamda查询语句,不会立马去查询数据库,只有当需要用时去调用(如取某行,取某个字段.聚合),才会去操作数据库,EF中本身的查询方法返回的都是IQueryable接口. 链接: ...
- c#多线程总结(纯干货)
线程基础 创建线程 static void Main(string[] args) { Thread t = new Thread(PrintNumbers); t.Start();//线程开始执行 ...
- Docker最全教程之使用Tencent Hub来完成CI(九)
使用Tencent Hub来完成CI 关于Tencent Hub Tencent Hub是腾讯出品的DevOps服务.主要提供多存储格式的版本管理,支持Docker Image.Binary.Helm ...