-
目录
配置三台虚拟器(网点分别为192.168.20.110、111、112)相关内容见linux学习笔记
复制redis官网下载链接,并利用wget命令,将redis下载到每个linux虚拟机之中
使用make语句进行编译(在redis-6.2.7的目录下进行)
使用make install将编译好的文件安装到指定目录(在redis-6.2.7的目录下进行)
接在redis-6.2.7进行make的报错与解决方法(在redis-6.2.7的目录下进行)
先进入后查询再进入配置文件(若无vim可用vi编写,建议使用vim(进行安装即可))
输入/prot进行快速查找,再按n进行查找(在命令模式下进行)
修改后:(在指定位置按i进入插入模式后进行端口的修改)(修改后按exc进入命令模式继续下一内容的查找)
输入/daemonize进行快速查找,再按n进行查找(在命令模式下进行)
输入/pidfile进行快速查找,再按n进行查找(在命令模式下进行)
修改dir(指定数据文件的存放位置 必须要指定不同的目录位置 不然会丢失数据)
输入/dir进行快速查找,再按n进行查找(在命令模式下进行)
输入/cluster-enabled进行快速查找,再按n进行查找(在命令模式下进行)
打开集群节点信息文件(这里的nodes-后最好与端口对应上)
输入/cluster-config-file进行快速查找,再按n进行查找(在命令模式下进行)
输入/cluster-node-timeout进行快速查找,再按n进行查找(在命令模式下进行)
输入/bin进行快速查找,再按n进行查找(在命令模式下进行)
输入/protected-mode进行快速查找,再按n进行查找(在命令模式下进行)
输入/appendonly进行快速查找,再按n进行查找(在命令模式下进行)
输入/requirepass进行快速查找,再按n进行查找(在命令模式下进行)
复制8001的配置文件到8002目录下(在8001目录下进行)
-
创建虚拟网点:环境准备
-
配置三台虚拟器(网点分别为192.168.20.110、111、112)相关内容见linux学习笔记
-
最终效果:
- 相关解释:一个master代表一个虚拟机,master,slave,slave组成一台虚拟机的主从效果,分别配置端口号并修改配置文件,以此实现环境的最终搭建
-
为每一个虚拟器安装redis程序
-
打开shell工具中的发送到所有对话
-
安装wget
-
yum -y install wget
-
-
复制redis官网下载链接,并利用wget命令,将redis下载到每个linux虚拟机之中
-
wget https://download.redis.io/releases/redis-6.2.7.tar.gz
-
-
将压缩包解压到/usr/local/目录之下
-
tar -zxvf redis-6.2.7.tar.gz -C /usr/local/
-
-
使用make语句进行编译(在redis-6.2.7的目录下进行)
-
make
-
-
使用make install将编译好的文件安装到指定目录(在redis-6.2.7的目录下进行)
-
make install
-
-
在src目录下查看是否安装成功(在src目录下进行)
-
redis-server
-
-
为虚拟机创设三个端口的配置文件
- 第一步:在redis-6.2.7目录创建目录redis-cluster
-
mkdir redis-cluster
-
- 第二步:进入redis-cluster后创建两个以端口命名的目录
-
cd redis-cluster mkdir 8001 mkdir 8002
-
- 第三步:将redis-6.2.7的redis.conf配置文件复制到8001目录之中
- 先进入redis-6.2.7目录后再进行复制(之后进入第二大标题进行更为细节的配置文件修改)
-
cd .. cp redis.conf redis-cluster/8001
-
- 先进入redis-6.2.7目录后再进行复制(之后进入第二大标题进行更为细节的配置文件修改)
- 第一步:在redis-6.2.7目录创建目录redis-cluster
-
接在redis-6.2.7进行make的报错与解决方法(在redis-6.2.7的目录下进行)
- 报错1:
- make[1]: *** [adlist.o] Error 127 make[1]: Leaving directory `/usr/local/redis-6.2.7/src' make: *** [all] Error 2
- 原因1:
-
因为Redis是C实现的,需要gcc来进行编译,所以原因是系统未安装gcc
-
- 解决办法1:
- 安装gcc
-
yum install gcc
- 报错2:
- cd src && make all
make[1]: Entering directory `/root/redis-3.0.3/src'
CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
#include <jemalloc/jemalloc.h>
^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/root/redis-3.0.3/src'
make: *** [all] Error 2
- cd src && make all
- 原因2:
- 默认的是 jemalloc,但是没有初始机器并没有安装jemalloc。libc是自带的,所以在使用分配器allocator时会出现问题。所以需要指定分配器
- 解决方法2:
-
make MALLOC=libc
-
- 报错1:
-
-
-
修改端口8001与8002的配置文件内容
-
进入8001的配置文件之中
-
先进入后查询再进入配置文件(若无vim可用vi编写,建议使用vim(进行安装即可))
-
cd redis-cluster/8001 #进入 ll #查看是否显示:total 92 -rw-r--r--. 1 root root 93849 Sep 5 05:23 redis.conf yum -y install vim #安装vim vim redis.conf #进入8001的配置文件之中
-
-
-
修改端口号(使用/port进行快速查找)
-
输入/prot进行快速查找,再按n进行查找(在命令模式下进行)
-
/port
-
-
修改前:
- # If port 0 is specified Redis will not listen on a TCP socket.
port 6379
- # If port 0 is specified Redis will not listen on a TCP socket.
-
修改后:(在指定位置按i进入插入模式后进行端口的修改)(修改后按exc进入命令模式继续下一内容的查找)
- # If port 0 is specified Redis will not listen on a TCP socket.
port 8001
- # If port 0 is specified Redis will not listen on a TCP socket.
-
-
开启保护进程
-
输入/daemonize进行快速查找,再按n进行查找(在命令模式下进行)
-
/daemonize
-
-
修改前:
- # When Redis is supervised by upstart or systemd, this parameter has no impact.
daemonize no
- # When Redis is supervised by upstart or systemd, this parameter has no impact.
-
修改后:
- # When Redis is supervised by upstart or systemd, this parameter has no impact.
daemonize yes
- # When Redis is supervised by upstart or systemd, this parameter has no impact.
-
-
修改pidfile
-
输入/pidfile进行快速查找,再按n进行查找(在命令模式下进行)
-
/pidfile
-
-
修改前:
-
# Note that on modern Linux systems "/run/redis.pid" is more conforming # and should be used instead. pidfile /var/run/redis_6379.pid
-
-
修改后:
-
# Note that on modern Linux systems "/run/redis.pid" is more conforming # and should be used instead. pidfile /var/run/redis_8001.pid
-
-
-
修改dir(指定数据文件的存放位置 必须要指定不同的目录位置 不然会丢失数据)
-
输入/dir进行快速查找,再按n进行查找(在命令模式下进行)
-
/dir
-
-
修改前:
- #
# Note that you must specify a directory here, not a file name.
dir ./
- #
-
修改后:
- # Note that you must specify a directory here, not a file name.
dir /usr/local/redis-6.2.7/redis-cluster/8001/
- # Note that you must specify a directory here, not a file name.
-
-
启动集群模式
-
输入/cluster-enabled进行快速查找,再按n进行查找(在命令模式下进行)
-
/cluster-enabled
-
-
修改前:
- # cluster node enable the cluster support uncommenting the following:
#
# cluster-enabled yes
- # cluster node enable the cluster support uncommenting the following:
-
修改后:
- # cluster node enable the cluster support uncommenting the following:
#
cluster-enabled yes
- # cluster node enable the cluster support uncommenting the following:
-
-
打开集群节点信息文件(这里的nodes-后最好与端口对应上)
-
输入/cluster-config-file进行快速查找,再按n进行查找(在命令模式下进行)
-
/cluster-config-file
-
-
修改前:
- # overlapping cluster configuration file names.
#
# cluster-config-file nodes-6379.conf
- # overlapping cluster configuration file names.
-
修改后:
- # overlapping cluster configuration file names.
#
cluster-config-file nodes-8001.conf
- # overlapping cluster configuration file names.
-
-
修改节点的离线超时时间
-
输入/cluster-node-timeout进行快速查找,再按n进行查找(在命令模式下进行)
-
/cluster-node-timeout
-
-
修改前:
- #
# cluster-node-timeout 15000
- #
-
修改后:
- #
cluster-node-timeout 5000
- #
-
-
修改bind
-
输入/bin进行快速查找,再按n进行查找(在命令模式下进行)
-
/bin
-
-
修改前:
- # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1 -::1
- # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
-
修改后:
- # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1 -::1
- # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
-
-
关闭保护模式
-
输入/protected-mode进行快速查找,再按n进行查找(在命令模式下进行)
-
/protected-mode
-
-
修改前:
- # even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode yes
- # even if no authentication is configured, nor a specific set of interfaces
-
修改后:
- # even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no
- # even if no authentication is configured, nor a specific set of interfaces
-
-
开启appendonly
-
输入/appendonly进行快速查找,再按n进行查找(在命令模式下进行)
-
/appendonly
-
-
修改前:
-
# Please check https://redis.io/topics/persistence for more information.
appendonly no
-
-
修改后:
-
# Please check https://redis.io/topics/persistence for more information.
appendonly yes
-
-
若想设置密码(不设置也行)
-
输入/requirepass进行快速查找,再按n进行查找(在命令模式下进行)
-
/requirepass
-
-
修改前:
- # The requirepass is not compatable with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.
#
# requirepass foobared
- # The requirepass is not compatable with aclfile option and the ACL LOAD
-
修改后:
- # The requirepass is not compatable with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.
#
requirepass 123
masterauth 123
- # The requirepass is not compatable with aclfile option and the ACL LOAD
-
-
vim退出不了的问题与解决方法
-
问题
- E45: 'readonly' option is set (add ! to override)
-
解决方法
-
一、第一种方法:如果有root权限,可以输入 :wq!强行保存退出。
二、第二种方法:
(1)按ESC
(2)输入 :set noreadonly
(3)输入 :wq就可保存退出
-
-
-
快捷修改8002的配置文件
-
复制8001的配置文件到8002目录下(在8001目录下进行)
-
cp redis.conf ../8002
-
-
进入8002目录查看是否成功
-
cd ../8002 #进入8002目录 ll #查看是否显示:total 92 -rw-r--r--. 1 root root 93892 Sep 5 06:27 redis.conf
-
-
进入8002的配置文件进行快速修改
-
vim redis.conf
-
在命令模式输入以下命令进行快速修改
-
:%s/8001/8002/g
-
-
-
-
-
集群搭建的后续工作
-
关闭防火墙
-
systemctl stop firewalld.service
-
-
启动服务(src目录下进行)
-
启动8001端口的配置文件
-
./redis-server ../redis-cluster/8001/redis.conf
-
-
启动8002端口的配置文件
-
./redis-server ../redis-cluster/8002/redis.conf
-
-
-
查看是否启动成功
-
ps -ef |grep redis
-
-
-
创建集群的后续工作
-
关闭shell工具中的发送到所有对话(再次点击即可关闭)
-
创建集群(有密码用上-a 密码,注意为网点:端口)
-
./redis-cli --cluster create --cluster-replicas 1 192.168.20.110:8001 192.168.20.110:8002 192.168.20.111:8001 192.168.20.111:8002 192.168.20.112:8001 192.168.20.112:8002
- 语句解释:
- --cluster create ——表示创建
- --cluster -replicas ——表示链接
- 链接后的1 ——表示一个master后有一个slaver
- 显示以下效果:表示创建成功,期间需要输入yes进行确认
- [OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered
- 语句解释:
-
-
尝试进入集群
-
redis-cli -c -h 192.168.20.111 -p 8001
- 相关解释:
- -c ——表示集群
- -h ——表示引用什么网点
- -p ——表示引用什么端口
- 相关解释:
-
-
-
py系统学习笔记:第六阶段:数据库编程基础:第四章:Redis的使用:135.Redis集群_Cluster模式搭建
![](https://img-home.csdnimg.cn/images/20240711042549.png)