企业级NoSql数据库 --- Redis集群

news2024/9/26 1:23:47

什么是 redis ?

Redis是一个开源的、遵循BSD协议的、基于内存的而且目前比较流行的键值数据库(key-value database),是一个非关系型数据库,redis 提供将内存通过网络远程共享的一种服务,提供类似功能的还有memcached,但相比memcached,redis还提供了易扩展、高性能、具备数据持久性等功能。

Redis 在高并发、低延迟环境要求比较高的环境使用量非常广泛。

环境准备:

母盘:RHEL9 ---> 1G,1内核

克隆:redis-node1(172.25.254.10)、redis-node2(172.25.254.20)、redis-node3(172.25.254.30)

vmset.sh eth0 172.25.254.10 redis-node1.test.org

vmset.sh eth0 172.25.254.20 redis-node1.test.org

vmset.sh eth0 172.25.254.30 redis-node1.test.org

redis安装

[root@redis-node1 ~]# tar zxf redis-7.4.0.tar.gz

[root@redis-node1 ~]# cd redis-7.4.0/

[root@redis-node1 redis-7.4.0]# dnf install make -y
[root@redis-node1 redis-7.4.0]# dnf install initscripts -y

[root@redis-node1 redis-7.4.0]# ll /etc/init.d/
[root@redis-node1 redis-7.4.0]# dnf install gcc -y
[root@redis-node1 redis-7.4.0]# make && make install


[root@redis-node1 redis-7.4.0]# cd utils/
[root@redis-node1 utils]# vim install_server.sh 
[root@redis-node1 utils]# ./install_server.sh 
#一路回车
[root@redis-node1 utils]# vim /etc/redis/6379.conf
[root@redis-node1 utils]# /etc/init.d/redis_6379 restart

[root@redis-node1 utils]# cd
[root@redis-node1 ~]# scp -r redis-7.4.0 root@172.25.254.20:/root
[root@redis-node1 ~]# scp -r redis-7.4.0 root@172.25.254.30:/root

[root@redis-node1 ~]# cd /usr/local/bin/

#10~30:都需要安装rsync
[root@redis-node1 bin]# dnf install rsync -y

[root@redis-node1 bin]# rsync -al * root@172.25.254.20:/usr/local/bin
[root@redis-node1 bin]# rsync -al * root@172.25.254.30:/usr/local/bin
[root@redis-node2 ~]# dnf install initscripts -y
[root@redis-node2 ~]# dnf install rsync -y


[root@redis-node2 ~]# cd redis-7.4.0/
[root@redis-node2 redis-7.4.0]# cd utils/
[root@redis-node2 utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@redis-node2 utils]# 
[root@redis-node2 utils]# vim /etc/redis/6379.conf 
[root@redis-node2 utils]# /etc/init.d/redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...
[root@redis-node3 ~]# dnf install initscripts -y
[root@redis-node3 ~]# dnf install rsync -y


[root@redis-node3 ~]# cd redis-7.4.0/
[root@redis-node3 redis-7.4.0]# cd utils/
[root@redis-node3 utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@redis-node3 utils]# 
[root@redis-node3 utils]# vim /etc/redis/6379.conf
[root@redis-node3 utils]# /etc/init.d/redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...

redis的主从复制

[root@redis-node2 utils]# vim /etc/redis/6379.conf
[root@redis-node2 utils]# /etc/init.d/redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...
[root@redis-node2 utils]# 
[root@redis-node2 utils]# redis-cli 
127.0.0.1:6379> get name
"lee"
[root@redis-node3 utils]# vim /etc/redis/6379.conf 
[root@redis-node3 utils]# /etc/init.d/redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...
[root@redis-node3 utils]# 
[root@redis-node3 utils]# redis-cli 
127.0.0.1:6379> get name
"lee"

redis哨兵

[root@redis-node1 ~]# ls
anaconda-ks.cfg  redis-7.4.0  redis-7.4.0.tar.gz
[root@redis-node1 ~]# cd redis-7.4.0/
[root@redis-node1 redis-7.4.0]# ls
00-RELEASENOTES     INSTALL      redis.conf              runtest-sentinel  TLS.md
BUGS                LICENSE.txt  REDISCONTRIBUTIONS.txt  SECURITY.md       utils
CODE_OF_CONDUCT.md  Makefile     runtest                 sentinel.conf
CONTRIBUTING.md     MANIFESTO    runtest-cluster         src
deps                README.md    runtest-moduleapi       tests
[root@redis-node1 redis-7.4.0]# cp sentinel.conf /etc/redis/
[root@redis-node1 redis-7.4.0]# vim /etc/redis/sentinel.conf
[root@redis-node1 redis-7.4.0]# scp /etc/redis/sentinel.conf root@172.25.254.20:/etc/redis/sentinel.conf
root@172.25.254.20's password: 
sentinel.conf                                    100%   14KB  10.6MB/s   00:00    
[root@redis-node1 redis-7.4.0]# scp /etc/redis/sentinel.conf root@172.25.254.30:/etc/redis/sentinel.conf
root@172.25.254.30's password: 
sentinel.conf                                    100%   14KB  10.5MB/s   00:00    
[root@redis-node1 redis-7.4.0]# 
[root@redis-node1 redis-7.4.0]# cd /etc/redis/
[root@redis-node1 redis]# ls
6379.conf  sentinel.conf
[root@redis-node1 redis]# cp sentinel.conf sentinel.conf.bak

[root@redis-node1 redis]# redis-sentinel /etc/redis/sentinel.conf
[root@redis-node2 ~]# cd /etc/redis/
[root@redis-node2 redis]# ls
6379.conf  sentinel.conf
[root@redis-node2 redis]# cp sentinel.conf sentinel.conf.bak

[root@redis-node2 redis]# redis-sentinel /etc/redis/sentinel.conf
[root@redis-node3 ~]# cd /etc/redis/
[root@redis-node3 redis]# ls
6379.conf  sentinel.conf
[root@redis-node3 redis]# cp sentinel.conf sentinel.conf.bak

[root@redis-node3 redis]# redis-sentinel /etc/redis/sentinel.conf

测试:

redis cluster

克隆:redis-node110、redis-node120、redis-node130

vmset.sh eth0 172.25.254.110 redis-node110.test.org

vmset.sh eth0 172.25.254.120 redis-node120.test.org

vmset.sh eth0 172.25.254.130 redis-node130.test.org

[root@redis-node1 redis]# cd /root/redis-7.4.0/
[root@redis-node1 redis-7.4.0]# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped
[root@redis-node1 redis-7.4.0]# ps aux | grep redis
root        7666  0.0  0.3   6408  2296 pts/1    S+   18:42   0:00 grep --color=auto redis
[root@redis-node1 redis-7.4.0]# make uninstall
cd src && make uninstall
make[1]: Entering directory '/root/redis-7.4.0/src'
rm -f /usr/local/bin/{redis-server,redis-benchmark,redis-cli,redis-check-rdb,redis-check-aof,redis-sentinel}
make[1]: Leaving directory '/root/redis-7.4.0/src'
[root@redis-node1 redis-7.4.0]# 
[root@redis-node1 redis-7.4.0]# cd
[root@redis-node1 ~]# dnf install redis -y


[root@redis-node1 ~]# vim /etc/redis/redis.conf
[root@redis-node1 ~]# systemctl enable --now redis
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.
[root@redis-node1 ~]# systemctl restart redis.service
[root@redis-node1 ~]# netstat -antlupe | grep redis
tcp        0      0 0.0.0.0:16379           0.0.0.0:*               LISTEN      991        40761      7919/redis-server * 
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      991        40759      7919/redis-server * 
tcp6       0      0 :::16379                :::*                    LISTEN      991        40762      7919/redis-server * 
tcp6       0      0 :::6379                 :::*                    LISTEN      991        40760      7919/redis-server * 
[root@redis-node1 ~]# 
[root@redis-node1 ~]# redis-cli 
-bash: /usr/local/bin/redis-cli: No such file or directory
[root@redis-node1 ~]# exit


[root@redis-node1 ~]# redis-cli 
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> keys *
(empty array)



[root@redis-node1 ~]# for i in 20 30 110 120 130
> do
> scp /etc/redis/redis.conf root@172.25.254.$i:/etc/redis/redis.conf
> done
[root@redis-node2 redis-7.4.0]# cd
[root@redis-node2 ~]# dnf install redis -y


[root@redis-node2 ~]# vim /etc/hosts 
[root@redis-node2 ~]# systemctl enable --now redis

[root@redis-node2 ~]# exit
[root@redis-node2 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> set name lee
OK
[root@redis-node3 redis-7.4.0]# cd
[root@redis-node3 ~]# dnf install redis -y


[root@redis-node3 ~]# vim /etc/hosts 
[root@redis-node3 ~]# systemctl enable --now redis

[root@redis-node3 ~]# exit
[root@redis-node3 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> get name
(error) MOVED 5798 172.25.254.20:6379
[root@redis-node110 ~]# dnf install redis -y
[root@redis-node110 ~]# vim /etc/hosts 
[root@redis-node110 ~]# systemctl enable --now redis
[root@redis-node120 ~]# dnf install redis -y
[root@redis-node120 ~]# vim /etc/hosts 
[root@redis-node120 ~]# systemctl enable --now redis
[root@redis-node130 ~]# dnf install redis -y
[root@redis-node130 ~]# vim /etc/hosts 
[root@redis-node130 ~]# systemctl enable --now redis
[root@redis-node1 ~]# redis-cli --cluster create -a 123456 \
> 172.25.254.10:6379 172.25.254.20:6379 172.25.254.30:6379 \
> 172.25.254.110:6379 172.25.254.120:6379 172.25.254.130:6379 \
> --cluster-replicas 1
...
>>> Performing Cluster Check (using node 172.25.254.10:6379)
M: 51942ff68767525da5b43516d5a1ac6d3a4236c0 172.25.254.10:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: f775d5a125e9056a699f6ef324566e3024c8eba4 172.25.254.110:6379
   slots: (0 slots) slave
   replicates 53eaf5b37b8961c67beed67abe67a4fdb568ba06
S: 2a8f1dfd906a1638fdcfc771dc24f00a21b5e8bf 172.25.254.120:6379
   slots: (0 slots) slave
   replicates 51942ff68767525da5b43516d5a1ac6d3a4236c0
M: bd12ca08ea95bdc5abb1f52e35d6bb825611ba72 172.25.254.20:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 53eaf5b37b8961c67beed67abe67a4fdb568ba06 172.25.254.30:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: aafeaea3cf23aa110960219c8b000946d94dd8a8 172.25.254.130:6379
   slots: (0 slots) slave
   replicates bd12ca08ea95bdc5abb1f52e35d6bb825611ba72
...


#20被推选,所以10不能创建
[root@redis-node1 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> set name lee
(error) MOVED 5798 172.25.254.20:6379

集群扩容

克隆:redis50、redis150 #都是1G 1内核

vmset.sh eth0 172.25.254.50 redis50.silingchuan.org

vmset.sh eth0 172.25.254.150 redis150.silingchuan.org

50 150:

dnf install redis -y

[root@redis-node2 ~]# scp /etc/redis/redis.conf root@172.25.254.50:/etc/redis/redis.conf

[root@redis-node2 ~]# scp /etc/redis/redis.conf root@172.25.254.150:/etc/redis/redis.conf
[root@redis-node50 ~]# dnf install redis -y
[root@redis-node50 ~]# systemctl start redis
[root@redis-node150 ~]# dnf install redis -y
[root@redis-node150 ~]# systemctl start redis

新增50master

[root@redis-node2 ~]# redis-cli -a 123456 --cluster add-node 172.25.254.50:6379 172.25.254.20:6379

[root@redis-node2 ~]# redis-cli -a 123456 --cluster check 172.25.254.10:6379

共享槽位

[root@redis-node2 ~]# redis-cli -a 123456 --cluster reshard 172.25.254.20:6379

(4096 50-ID all yes)

新增150slave

[root@redis-node2 ~]# redis-cli -a 123456 --cluster add-node 172.25.254.150:6379 172.25.254.20:6379 --cluster-slave --cluster-master-id 2ce4bedb48252ca1c7030586d45d1b271490176a

移除150:

[root@redis-node2 ~]# redis-cli -a 123456 --cluster del-node  172.25.254.150:6379 6ab4d6ec8aab005c3934f6bfa272a6be77545cbb

清空槽位:

[root@redis-node2 ~]# redis-cli -a 123456 --cluster  reshard 172.25.254.20:6379

(4096 20-ID 50-ID done yes)

移除50:

[root@redis-node2 ~]# redis-cli -a 123456 --cluster del-node  172.25.254.50:6379 2ce4bedb48252ca1c7030586d45d1b271490176a

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2077532.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Day18_Netty

文章目录 NettyIO 模型Java有哪些数据类型零拷贝深拷贝和浅拷贝的区别是什么?BIO、NIO、AIO的区别是什么?Netty 是什么?Netty 基于 NIO,那为啥不直接用 NIO 呢? / 为什么要用 Netty?Netty 应用场景了解么?那些开源项目用到了 Netty?Netty的核心组件是什么?请解释Netty…

【LwIP源码学习笔记1】LwIP网络接口管理

netif结构体 netif是Lwip抽象出来的网卡,结构体的声明在Lwip/include/lwip/netif.h文件中。 Lwip将每个用netif描述的网卡连接成一个链表(单向链表)。 以下是在netif.h头文件中定义的一些netif的操作函数 struct netif *netif_add_noaddr(s…

SpringBoot整合策略模式之基于 ApplicationContextAware + 枚举类实现

文章目录 1、ILog2、LogType 枚举类3、DemoController4、application.properties5、DesignDemoApplication 1、ILog package com.atguigu.design.demo.spring; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; imp…

Nginx学习(第二天)

一.Nginx高级配置 1.1 Nginx状态页 基于nginx 模块 ngx_http_stub_status_module 实现, 在编译安装nginx的时候需要添加编译参数 --with-http_stub_status_module 否则配置完成之后监测会是提示法错误 注意: 状态页显示的是整个服务器的状态,而非虚拟主机的状态 …

PeriodWave: Multi-Period Flow Matching for High-Fidelity Waveform Generation

preprintKorea Seoul, Korea 文章目录 abstractmethodFlow Matching for Waveform GenerationHigh-frequency Information Modeling for Flow Matching demo page, PeriodWave 三者最好,而且能把原声中的噪声去掉,GAN一类声码器做不到的。 Pe…

vllm 部署GLM4模型进行 Zero-Shot 文本分类实验,让大模型给出分类原因,准确率可提高6%

文章目录 简介数据集实验设置数据集转换模型推理评估 简介 本文记录了使用 vllm 部署 GLM4-9B-Chat 模型进行 Zero-Shot 文本分类的实验过程与结果。通过对 AG_News 数据集的测试,研究发现大模型在直接进行分类时的准确率为 77%。然而,让模型给出分类原…

地理空间数据分析技巧:优化的热点分析与异常值分析的应用

热点分析作为一种常用的空间统计方法,能够帮助我们识别地理空间中的热点和冷点区域,即那些高值或低值集中出现的地方。而优化的热点分析进一步简化了这一过程,使用户无需手动调整参数即可获得可靠的结果。此外,异常值分析则专注于…

wooyu漏洞库YYDS!!!入门之道:重现乌云漏洞库

目录 wooyun乌云漏洞库搭建 1、搭建资料 文件结构分析: ​编辑2、搭建过程 2.1、搭建wooyun网站 2.2、配置数据库 2.2.1、修改数据库配置文件conn.php 2.2.2、创建wooyun数据库,并解压数据库文件 2.2.3、连接数据库(数据库默认连接密…

信号与系统——定义与分类(1)

一、信号与系统 信号:信号是信息的表现形式或传送载体,例如电磁波。信号可以用一个函数 yx (t) 来表示。 系统:是指若干相互关联的事物组合而成,具有特定功能的整体。换句话说就是,系统就是对输入信号进行加工和处理&#xff0c…

Nginx: 反向代理和动静分离概述

反向代理 反向代理服务器介于用户和真实服务器之间,提供请求和响应的中转服务对于用户而言,访问反向代理服务器就是访问真实服务器反向代理可以有效降低服务器的负载消耗,提升效率 1 )反向代理的模型 现在我们有一个用户和真实服…

新版cubemx生成CMake工程浮点数打印问题记录

问题现象 解决方案 set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --specsnano.specs -u _printf_float")参考Cortex-M4权威指南 重新下载和测试

[Algorithm][综合训练][打怪][判断是不是平衡二叉树][最大子矩阵]详细讲解

目录 1.打怪1.题目链接2.算法原理详解 && 代码实现 2.判断是不是平衡二叉树1.题目链接2.算法原理详解 && 代码实现 3.最大子矩阵1.题目链接2.算法原理详解 && 代码实现 1.打怪 1.题目链接 打怪 2.算法原理详解 && 代码实现 自己的版本&…

C++ 设计模式——代理模式

C 设计模式——代理模式 C 设计模式——代理模式1. 主要组成成分2. 逐步构建代理模式2.1 抽象主题类定义2.2 真实主题类实现2.3 代理类实现2.4 主函数 3. 代理模式 UML 图代理模式 UML 图解析 4. 代理模式的优点5. 代理模式的缺点6. 代理模式的分类7. 代理模式和装饰者模式比较…

MybatisPlus:实现分页效果并解决错误:cant found IPage for args

我们在做开发使用mybatisplus 做分页查询的时候遇到了个问题: 继承 IPage拦截没有作用会默认分页,这个时候报了cant found IPage for args 错误~~~ 我们分析了下,其实这个问题很简单,是因为没有给默认值赋值,因为查询…

日撸Java三百行(day35:图的m着色问题)

目录 一、问题描述 二、思路分析 三、代码实现 总结 一、问题描述 在高中学习排列组合的时候,有一个非常经典的问题,就是涂色问题,即用m种颜色给n块区域涂色,要求每块区域只能涂同一种颜色且相邻区域的颜色不能相同&#xff…

pyinstaller将python程序打包成exe文件

将python代码打包成exe文件可以在不安装python环境的情况下直接运行python代码,譬如自己在自己的电脑上写好了代码,想发给其他人使用,可以用下述方法将python程序打包成exe文件,其他人直接执行exe文件即可使用该程序。 1.安装pyi…

二叉搜索树:数据结构之美

目录 引言基础知识 定义性质操作详解 插入节点删除节点查找节点遍历 前序遍历中序遍历后序遍历高级主题 平衡问题AVL树简介应用案例总结 引言 二叉搜索树(Binary Search Tree, BST)是一种特殊的二叉树,它的每个节点具有以下性质:左子树上的所有节点的键…

Python数据采集与网络爬虫技术实训室解决方案

在大数据与人工智能时代,数据采集与分析已成为企业决策、市场洞察、产品创新等领域不可或缺的一环。而Python,作为一门高效、易学的编程语言,凭借其强大的库支持和广泛的应用场景,在数据采集与网络爬虫领域展现出了非凡的潜力。唯…

Mysql重要参数

1、是否开启慢SQL日志 show VARIABLES like slow_query_log%; 2、慢SQL日志保存位置 show VARIABLES like slow_query_log_file%; 3、慢SQL的阈值,超过则是慢SQL,单位秒,默认10s show VARIABLES like long_query_time%;

小阿轩yx-Kubernetes存储入门

小阿轩yx-Kubernetes存储入门 前言 数据是一个企业的发展核心,它涉及到数据存储和数据交换的内容。在生产环境中尤为重要的一部分在 Kubernetes 中另一个重要的概念就是数据持久化 Volume。 Volume 的概念 对多数项目而言 数据文件的存储是非常常见的 在 Kube…