广告
返回顶部
首页 > 资讯 > 数据库 >Redis集群实战
  • 298
分享到

Redis集群实战

2024-04-02 19:04:59 298人浏览 安东尼
摘要

                   Redis基础到集群实战笔记   &n

                   Redis基础到集群实战笔记

                                                                              

 

 

持久化存储

redis介绍

redis是基于key-value的持久化数据库存储系统,redis和memcached服务很想,但是redis支持的数据存储类型

服务更丰富

memcached支持value

redis支持string(字符)list(链表)  set(集合)  push、pop

redis比memcached服务性能好,但是比相对性的关系数据库(如Mysql) 相对差

 

redis支持各种不同方式的排序,与memcached一样,为了保存效率,数据都是缓存在内存中提供服务,但是redis会定时的将

数据存储在磁盘当中,而且redis支持master-slave(主从)同步,这很类似mysql

 

 

redis优点

可以持久化存储数据

性能很高:redis支持超过100k+秒的读写频率。

丰富的数据类型:strings lists,hashes,Sets数据类型操作

redis支持主从复制

 

 

redis应用场景

传统的MYsql+MEMCACHED架构遇到的问题

MYSQL数据库是适合进行海量数据存储的,加上通过Memcached热点数据放在内存cache中,随着访问量增长,就会出现

问题。

1需要不断的对MYSQL拆库拆表,Memcached也需要不断地扩充,占据大量的运维时间

2Memcached和MYSQL数据一致性问题

3Memcached数据库命中率低或当机,导致大量的访问直接穿透数据库,导致mysql无法支持访问

4跨级方cache同步一致性问题

 

 

redis最佳应用场景

1Redis最佳使用场景全部数据是in-memory(内存)

2Redis更多的场景作为Memcached替代

3当需要除key/value之外的更多数据类型支持的时候,使用Redis更合适

4支持持久化

5需要负载均衡的场景(redis主从同步)

 

 

 

 

redis部署搭建

MASTER 192.168.2.1

SLAVE  192.168.2.4

 

 

MASTER:

[root@localhost ~]# ls

anaconda-ks.cfg  bbs  boke  install.log  install.log.syslog  mysql-5.5.32-linux2.6-x86_64.tar.gz  redis-3.0.2.tar.gz  test.sh  www

[root@localhost ~]# tar zxf redis-3.0.2.tar.gz

[root@localhost ~]# cd redis-3.0.2

[root@localhost redis-3.0.2]# make  MALLOC=jemalloc

[root@localhost redis-3.0.2]# make PREFIX=/application/redis install  指定安装路径

 

 

 

SLAVE

[root@localhost ~]# ls

anaconda-ks.cfg  bbs  boke  install.log  install.log.syslog  mysql-5.5.32-linux2.6-x86_64.tar.gz  redis-3.0.2.tar.gz  test.sh  www

[root@localhost ~]# tar zxf redis-3.0.2.tar.gz

[root@localhost ~]# cd redis-3.0.2

[root@localhost redis-3.0.2]# make  MALLOC=jemalloc

[root@localhost redis-3.0.2]# make PREFIX=/application/redis install  指定安装路径

装完后bin有5个命令

[root@localhost bin]# ls

redis-benchmark  redis-check-aof  redis-check-dump  redis-cli  redis-sentinel  redis-server

 

redis-benchmark redis性能测试工具

redis-check-aof 更新日志检查

redis-check-dump

redis-cli Redis命令操作工具

redis-sentinel 用于本地数据库检查

redis-server Redis服务的启动程序

 

 

要想启动Redis要做环境变量

[root@localhost redis]# export PATH=/application/redis/bin/:$PATH

[root@localhost redis]# which  redis-server

/application/redis/bin/redis-server

永久生效修改文件

[root@localhost redis]# vim /etc/profile

export PATH=/application/redis/bin/:$PATH

[root@localhost redis]# . /etc/profile

redis配置

[root@localhost redis-3.0.2]# mkdir /application/redis/conf

[root@localhost redis-3.0.2]# cp redis.conf  /application/redis/conf/

 

启动Redis

[root@localhost redis-3.0.2]# redis-server  /application/redis/conf/redis.conf

5522:M 18 Feb 05:02:08.448 * Increased maximum number of open files to 10032 (it was originally set to 1024).

                _._                                                  

           _.-``__ ''-._                                             

      _.-``    `.  `_.  ''-._           Redis 3.0.2 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._                                   

 (    '      ,       .-`  | `,    )     Running in standalone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379

 |    `-._   `._    /     _.-'    |     PID: 5522

  `-._    `-._  `-./  _.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |           Http://redis.io        

  `-._    `-._`-.__.-'_.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |                                  

  `-._    `-._`-.__.-'_.-'    _.-'                                   

      `-._    `-.__.-'    _.-'                                       

          `-._        _.-'                                           

              `-.__.-'                                               

 

5522:M 18 Feb 05:02:08.463 # Server started, Redis version 3.0.2

5522:M 18 Feb 05:02:08.464 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

5522:M 18 Feb 05:02:08.470 # WARNING: The tcp backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

5522:M 18 Feb 05:02:08.470 * The server is now ready to accept connections on port 6379

 

vm.overcommit_memory = 1提示这个错误

解决

[root@localhost redis-3.0.2]# sysctl  vm.overcommit_memory=1

vm.overcommit_memory = 1

 

[root@localhost redis-3.0.2]# redis-server  /application/redis/conf/redis.conf

5560:M 18 Feb 05:05:23.085 * Increased maximum number of open files to 10032 (it was originally set to 1024).

                _._                                                  

           _.-``__ ''-._                                             

      _.-``    `.  `_.  ''-._           Redis 3.0.2 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._                                   

 (    '      ,       .-`  | `,    )     Running in standalone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379

 |    `-._   `._    /     _.-'    |     PID: 5560

  `-._    `-._  `-./  _.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |           http://redis.io        

  `-._    `-._`-.__.-'_.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |                                  

  `-._    `-._`-.__.-'_.-'    _.-'                                   

      `-._    `-.__.-'    _.-'                                       

          `-._        _.-'                                           

              `-.__.-'                                               

 

5560:M 18 Feb 05:05:23.087 # Server started, Redis version 3.0.2

5560:M 18 Feb 05:05:23.088 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

5560:M 18 Feb 05:05:23.088 * DB loaded from disk: 0.001 seconds

5560:M 18 Feb 05:05:23.088 * The server is now ready to accept connections on port 6379

 

成功!

 

 

测试redis

[root@localhost ~]# redis-cli

127.0.0.1:6379>

 

创建库查看库

127.0.0.1:6379> set  no002 xiaohu

OK

127.0.0.1:6379> get no002

"xiaohu"

 

不在命令行创建库

[root@localhost ~]# redis-cli  -h 192.168.2.1 -p 6379 set no001 qi

OK

[root@localhost ~]# redis-cli  -h 192.168.2.1 -p 6379 get no001

"qi"

 

删除数据库

[root@localhost ~]# redis-cli   del no001

(integer) 1

[root@localhost ~]# redis-cli   get  no001

(nil)

 

 

redis类型

字符串类型

列表类型 列表是数组  对应

[root@localhost ~]# redis-cli  rpush messages "hello"

(integer) 1

[root@localhost ~]# redis-cli  rpush messages "hell"

(integer) 2

显示

[root@localhost ~]# redis-cli  lrange messages 0 2

1) "hello"

2) "hell"

 

 

redis集合  这种将3个值集合在一个变量值上  对应标签功能

127.0.0.1:6379> sadd myset a

(integer) 1

127.0.0.1:6379> sadd myset b

(integer) 1

127.0.0.1:6379> sadd myset c

(integer) 1

127.0.0.1:6379> smembers myset

1) "c"

2) "b"

3) "a"

 

 

 

redis 主从同步

MASTER 192.168.2.1

SLAVE  192.168.2.4

编辑slave的redis.conf

vim /application/redis/conf/redis.conf

在slaveof下面添加:

slaveof  192.168.2.1  6379 主库地址和端口号

slave查看

[root@localhost redis-3.0.2]# redis-server  /application/redis/conf/redis.conf

6631:S 24 Mar 06:21:26.599 * Increased maximum number of open files to 10032 (it was originally set to 1024).

                _._                                                  

           _.-``__ ''-._                                             

      _.-``    `.  `_.  ''-._           Redis 3.0.2 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._                                   

 (    '      ,       .-`  | `,    )     Running in standalone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379

 |    `-._   `._    /     _.-'    |     PID: 6631

  `-._    `-._  `-./  _.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |           http://redis.io        

  `-._    `-._`-.__.-'_.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |                                  

  `-._    `-._`-.__.-'_.-'    _.-'                                   

      `-._    `-.__.-'    _.-'                                       

          `-._        _.-'                                           

              `-.__.-'                                               

 

6631:S 24 Mar 06:21:26.611 # Server started, Redis version 3.0.2

6631:S 24 Mar 06:21:26.613 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

6631:S 24 Mar 06:21:26.613 * DB loaded from disk: 0.000 seconds

6631:S 24 Mar 06:21:26.613 * The server is now ready to accept connections on port 6379

6631:S 24 Mar 06:21:27.602 * Connecting to MASTER 192.168.2.1:6379

6631:S 24 Mar 06:21:27.602 * MASTER <-> SLAVE sync started  已经成功

6631:S 24 Mar 06:21:27.603 * Non blocking connect for SYNC fired the event.

6631:S 24 Mar 06:21:27.604 * Master replied to PING, replication can continue...

6631:S 24 Mar 06:21:27.606 * Partial resynchronization not possible (no cached master)

6631:S 24 Mar 06:21:27.611 * Full resync from master: 7a09e0f69c3888561658ec8a480d250d219c2444:1

6631:S 24 Mar 06:21:27.671 * MASTER <-> SLAVE sync: receiving 83 bytes from master

6631:S 24 Mar 06:21:27.671 * MASTER <-> SLAVE sync: Flushing old data

6631:S 24 Mar 06:21:27.671 * MASTER <-> SLAVE sync: Loading DB in memory

6631:S 24 Mar 06:21:27.672 * MASTER <-> SLAVE sync: Finished with success

 

 

MASTER查看

[root@localhost ~]# redis-server  /application/redis/conf/redis.conf

2178:M 19 Feb 03:22:56.204 * Increased maximum number of open files to 10032 (it was originally set to 1024).

                _._                                                  

           _.-``__ ''-._                                             

      _.-``    `.  `_.  ''-._           Redis 3.0.2 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._                                   

 (    '      ,       .-`  | `,    )     Running in standalone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379

 |    `-._   `._    /     _.-'    |     PID: 2178

  `-._    `-._  `-./  _.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |           http://redis.io        

  `-._    `-._`-.__.-'_.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |                                  

  `-._    `-._`-.__.-'_.-'    _.-'                                   

      `-._    `-.__.-'    _.-'                                       

          `-._        _.-'                                           

              `-.__.-'                                               

 

2178:M 19 Feb 03:22:56.224 # Server started, Redis version 3.0.2

2178:M 19 Feb 03:22:56.224 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

2178:M 19 Feb 03:22:56.224 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

2178:M 19 Feb 03:22:56.224 * DB loaded from disk: 0.000 seconds

2178:M 19 Feb 03:22:56.224 * The server is now ready to accept connections on port 6379

2178:M 19 Feb 03:37:57.011 * 1 changes in 900 seconds. Saving...

2178:M 19 Feb 03:37:57.014 * Background saving started by pid 2374

2374:C 19 Feb 03:37:57.046 * DB saved on disk

2374:C 19 Feb 03:37:57.046 * RDB: 6 MB of memory used by copy-on-write

2178:M 19 Feb 03:37:57.120 * Background saving terminated with success

2178:M 19 Feb 03:52:58.020 * 1 changes in 900 seconds. Saving...

2178:M 19 Feb 03:52:58.031 * Background saving started by pid 2546

2546:C 19 Feb 03:52:58.049 * DB saved on disk

2546:C 19 Feb 03:52:58.049 * RDB: 6 MB of memory used by copy-on-write

2178:M 19 Feb 03:52:58.138 * Background saving terminated with success

2178:M 19 Feb 04:09:04.556 * Slave 192.168.2.4:6379 asks for synchronization

2178:M 19 Feb 04:09:04.556 * Full resync requested by slave 192.168.2.4:6379

2178:M 19 Feb 04:09:04.556 * Starting BGSAVE for SYNC with target: disk

2178:M 19 Feb 04:09:04.557 * Background saving started by pid 2773

2773:C 19 Feb 04:09:04.580 * DB saved on disk

2773:C 19 Feb 04:09:04.581 * RDB: 6 MB of memory used by copy-on-write 主库也接受到了

2178:M 19 Feb 04:09:04.620 * Background saving terminated with success

2178:M 19 Feb 04:09:04.620 * Synchronization with slave 192.168.2.4:6379 succeeded

 

 

 

 

 

在从库做个监控,主库写数据验证

[root@localhost ~]# redis-cli  主库创建数据库

127.0.0.1:6379> set t1 xiaohu01

OK

127.0.0.1:6379> get t1

"xiaohu01"

查看从库同步

[root@localhost ~]# redis-cli  -h 192.168.2.4 get t1

"xiaohu01"

远程连接到从库查看数据同步了

 

 

[root@localhost ~]# redis-cli  -h localhost -p 6379 monitor 从库开启监控数据库写入

OK

1458772016.182626 [0 192.168.2.1:6379] "PING"

 

 

 

 

 


您可能感兴趣的文档:

--结束END--

本文标题: Redis集群实战

本文链接: https://www.lsjlt.com/news/42350.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Redis集群实战
                       Redis基础到集群实战笔记   &n...
    99+
    2022-10-18
  • 【Redis】集群NetCore实战
    介绍NetCore如何使用Redis集群 环境准备  Redis集群(Windows集群搭建) 启动Redis集群,给每个节点加上Title start "Redis - 6379" /min re...
    99+
    2017-02-19
    【Redis】集群NetCore实战
  • Docker中redis集群部署实战
    目录环境准备安装gcc-c++查看版本创建Redis网卡创建6个redis服务在/var目录下创建脚本文件create_redis_script.sh编写脚本内容查看脚本文件赋予create_redis_script.s...
    99+
    2022-11-27
    Docker中redis集群部署 docker搭建redis集群 docker安装redis集群
  • redis集群
    Redis集群基本介绍Redis 集群是一个可以在多个 Redis 节点之间进行数据共享的设施installation。Redis 集群不支持那些需要同时处理多个键的...
    99+
    2022-10-18
  • Redis5.x 集群部署实战
    实验环境主机名IP地址Redis端口划分备注node171172.20.20.17116001,16002node172172.20.20.17216001,16002node173172.20.20.17...
    99+
    2022-10-18
  • redis如何实现集群
    这篇文章给大家分享的是有关redis如何实现集群的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。1.主从复制主从复制原理:从服务器连接主服务器,发送SYNC命令;主服务器接收到SY...
    99+
    2022-10-18
  • Redis集群(Cluster)
    Redis集群 集群解决的问题代理主机和无中心化集群Redis集群的特点Redis集群环境搭建slots(插槽)在集群中录入值查询集群中的值故障恢复Redis集群的优缺点 集群解决的问...
    99+
    2023-08-31
    redis 数据库 服务器
  • 实战Mariadb galera Cluster集群架构
    Mariadb galera Cluster安装:操作系统:Centos7.4版本集群数量:3个节点主机信息: 192.168.153.142 node1 selinux=disabled fire...
    99+
    2022-10-18
  • Google Kubernetes Engine 集群实战详解
    目录GKE 集群介绍K8s 带来的好处使用 GKE 编排集群GKE 集群介绍 Google Kubernetes Engine (GKE) 集群由 Kubernetes 开源集群管理...
    99+
    2022-11-13
  • Redis 哨兵集群的实现
    目录1、Sentinel 哨兵2、Redis 主从分离一、配置Master二、配置Slave  1、在配置文件中配置从服务  2、在服务启动后设置  3、总结3、Sentinel 哨...
    99+
    2022-11-12
  • Redis分片集群的实现
    目录1 搭建分片集群1.1 集群结构1.2 准备实例和配置1.3 启动1.4 创建集群1.5 测试2 散列插槽3 集群伸缩3.1 创建节点并添加到集群3.2 转移插槽4 故障转移4....
    99+
    2023-01-30
    Redis 分片集群 Redis 分片
  • Redis 分片集群的实现
    目录1 搭建分片集群1.1 集群结构1.2 准备实例和配置1.3 启动1.4 创建集群1.5 测试2 散列插槽3 集群伸缩3.1 创建节点并添加到集群3.2 转移插槽4 故障转移4.1.自动故障转移4.2 手动故障转移5...
    99+
    2023-01-30
    Redis分片集群 Redis分片
  • redis集群操作
    Redis集群 1 集群2 集群架构图3 集群细节4 集群搭建4.1.创建集群4.2.查看集群状态4.3.添加主节点4.4.添加从节点4.5.删除副本节点4.6.集群在线分片 ...
    99+
    2023-09-15
    redis 数据库 java
  • Redis集群模式
    1、常见的三种数据的集群存储模式 full-mirror:全量镜像模式,单纯备份模式,各个节点数据相同,都包含了全量数据,仅主节点可写,保证了数据冗余和读的负载均衡。数据安全性高,横向扩展能力差,资源利用率不高。 pure-sh...
    99+
    2016-08-18
    Redis集群模式
  • redis集群搭建
    Redis 5.0之后版本的高可用集群搭建 Redis系统介绍: Redis的基础介绍与安装使用步骤:https://www.jianshu.com/p/2a23257af57b Redis的基础数据结构与使用:https...
    99+
    2019-03-23
    redis集群搭建
  • redis集群安装
    本文 redis版本3.2.9介绍 IP 端口 角色 127.0.0.1 7000 Master 127.0.0.1 7001 Master 127.0.0.1 7002 Maste...
    99+
    2022-10-18
  • Redis 哨兵集群
    哨兵集群介绍Redis的哨兵(sentinel) 常用于管理多个 Redis 服务器,它主要会执行以下三个任务:        监控(M...
    99+
    2022-10-18
  • redis 3.0 cluster 集群
    周氏一族,整理技术文档,给下一代留点教程......redis 3.0 cluster 安装篇,请看 http://zhoushouby.blog.51cto.com/9150272/1560400 本篇,是在 "redis 3.0 clu...
    99+
    2023-01-31
    集群 redis cluster
  • 【Redis】用python操作redis集群
    https://blog.csdn.net/bitcarmanlee/article/details/51852126  密码不能写到列表中去: 有密...
    99+
    2022-10-18
  • LVS负载均衡群集——实战篇
    LVS负载均衡群集 环境准备: CentOS 7-1:调度器,网关(需要两块网卡)外:12.0.0.1 内:192.168.200.1 CentOS 7-2:网站服务器(Apache)192.168.20...
    99+
    2022-10-18
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作