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 命令, 因为执行 ...
随机推荐
- DRUID连接池配置详情
DRUID介绍 DRUID是阿里巴巴开源平台上一个数据库连接池实现,它结合了C3P0.DBCP.PROXOOL等DB池的优点,同时加入了日志监控,可以很好的监控DB池连接和SQL的执行情况,可以说是针 ...
- CSS关联选择器的大致类型总结
1.包含选择符(A F) 选择所有被A元素包含的F元素,中间用空格隔开 2.子选择符(A>F) 选择所有作为A元素的直接子元素F,对更深一层的元素不起作用,用大括号表示. 3.相邻选择符(A+F ...
- 什么是CSS
CSS是Cascading Style Sheet的缩写.译作”层叠样式表单“.是用于(增强)控制网页样式并允许将样式信息与网页内容分离的一种标记性语言.使用CSS样式可以控制许多仅使用HTML无法控 ...
- 安卓开发笔记(十一):SharedPrefences储存
一.利用SharedPrefences将数据储存于data.txt当中 package com.example.lenovo.studyittwo; import android.content.Br ...
- 300+ Manual Testing and Selenium Interview Questions and Answers
Manual testing is a logical approach and automation testing complements it. So both are mandatory an ...
- 数据库之redis篇(3)—— Python操作redis
虽然前面两篇已经说了redis的一些配置安装什么的,篇幅有点长,可能看完了也不知道怎么操作,这里再浓缩一下: 什么是redis redis完全开源免费的,遵守BSD协议,是一个高性能的非关系型key- ...
- 【原】无脑操作:Gitblit服务器搭建及IDEA整合Git使用
背景:虽然有GitHub.GitLab这样强大的Git仓库,但是涉及私有Git库要收费,所以自己动手搭建免费的用用 环境:windows 7 旗舰版.JDK 1.8.IDEA 2017 ------- ...
- 跨域405(Method Not Allowed)问题
zepot post没有问题,用plupload上传出现了这个错误,options过不去.显示Response for preflight has invalid http status code 4 ...
- cxf 整合 spring 时 java.lang.VerifyError异常
异常信息主要有两个,Falling off the end of the code 和 illegal instruction found at offset 1: java.lang.VerifyE ...
- Spring 对Controller异常的统一处理
对于Controller的异常处理,分为两种,一种是对已知的异常处理,一种是未知的异常处理 1.定义自定义异常类 /** * @author hzc * */ public class UserNot ...