찾다
데이터 베이스RedisCentos7에서 redis5 클러스터를 구축하고 사용하는 방법

1. 간략한 설명

클러스터에는 노드가 3개 이상 있어야 하며, 각 노드에는 백업 노드가 있습니다. 6개의 서버가 필요합니다.

조건이 제한되면 의사 배포가 구축될 수 있습니다. 다음 단계는 Linux 서버에 6개의 노드가 있는 Redis 클러스터를 구축하는 것입니다.

2. 클러스터 생성 단계

2.1. 디렉터리 생성

새 디렉터리: mkdir /usr/local/redis-clustermkdir /usr/local/redis-cluster

2.2、下载源码并解压编译

wget http://download.redis.io/releases/redis-5.0.0.tar.gz
tar xzf redis-5.0.0.tar.gz
cd redis-5.0.0
make
make install prefix=/usr/local/redis

3、创建6个redis配置文件

    6个配置文件不能在同一个目录,此处我们定义如下:

/root/software/redis/redis-cluster-conf/7001/redis.conf
/root/software/redis/redis-cluster-conf/7002/redis.conf
/root/software/redis/redis-cluster-conf/7003/redis.conf
/root/software/redis/redis-cluster-conf/7004/redis.conf
/root/software/redis/redis-cluster-conf/7005/redis.conf
/root/software/redis/redis-cluster-conf/7006/redis.conf

一些操作命令仅供参考:

cp redis.conf /usr/local/redis/bin
cd /usr/local/redis/
cp -r bin ../redis-cluster/redis01
cd /usr/local/redis-cluster/redis01
rm dump.rdb #删除快照
vim redis.conf

配置文件的内容为:

port 7001 #端口
cluster-enabled yes #启用集群模式
cluster-config-file nodes.conf
cluster-node-timeout 5000 #超时时间
appendonly yes
daemonize yes #后台运行
protected-mode no #非保护模式
pidfile /var/run/redis_7001.pid
bind 172.20.10.7 #127.0.0.1改为本机ip地址,可用ifconfig查看ip

其中 port 和 pidfile 需要随着 文件夹的不同调增。

创建剩余5个实例:

[root@master redis-cluster]# cp -r redis01/ redis02
[root@master redis-cluster]# cp -r redis01/ redis03
[root@master redis-cluster]# cp -r redis01/ redis04
[root@master redis-cluster]# cp -r redis01/ redis05
[root@master redis-cluster]# cp -r redis01/ redis06

分别修改redis02 ~ redis06 的 redis.conf下的port 和 pidfile

4、启动节点

分别进入redis01、redis02、...redis06目录,执行: ./redis-server ./redis.conf

创建一个批处理文件,同时启动着六个redis

vim startall.sh

添加如下内容:

cd redis01
./redis-server redis.conf
cd ..
cd redis02
./redis-server redis.conf
cd ..
cd redis03
./redis-server redis.conf
cd ..
cd redis04
./redis-server redis.conf
cd ..
cd redis05
./redis-server redis.conf
cd ..
cd redis06
./redis-server redis.conf
cd ..

然后执行chmod u+x start-all.shstart-all.sh变成可执行文件

在当前目录下启动: ./startall.sh

查看:ps aux|grep redis

<img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/887/227/168559062896660.jpg?x-oss-process=image/resize,p_40" class="lazy" alt="Centos7에서 redis5 클러스터를 구축하고 사용하는 방법">

5、启动集群

因为我们使用的5.0.0的版本的redis搭建的集群只需要把编译后的redis目录中的这个redis-cli文件拷贝到redis-cluster目录过来即可。(redis版本5.0以后都是用c语言直接启动)

/usr/local/redis-cluster/redis-cli --cluster create 172.20.10.7:7001 172.20.10.7:7002 172.20.10.7:7003 172.20.10.7:7004 172.20.10.7:7005 172.20.10.7:7006 --cluster-replicas 1

启动后,可看到成功信息,如下:

>>> performing hash slots allocation on 6 nodes...
master[0] -> slots 0 - 5460
master[1] -> slots 5461 - 10922
master[2] -> slots 10923 - 16383
adding replica 172.20.10.7:7004 to 172.20.10.7:7001
adding replica 172.20.10.7:7005 to 172.20.10.7:7002
adding replica 172.20.10.7:7006 to 172.20.10.7:7003
>>> trying to optimize slaves allocation for anti-affinity
[warning] some slaves are in the same host as their master
m: a4128b5e581c3722acd9b093c5f29f5056f680b0 172.20.10.7:7001
 slots:[0-5460] (5461 slots) master
m: d6fed6f21269b8469a3076ac5fb168bd20f70c26 172.20.10.7:7002
 slots:[5461-10922] (5462 slots) master
m: 51a0f62dacead745ce5351cdbe0bdbae553ce413 172.20.10.7:7003
 slots:[10923-16383] (5461 slots) master
s: 45cc35740ac67f7988bb75325871ba12d08a76e4 172.20.10.7:7004
 replicates a4128b5e581c3722acd9b093c5f29f5056f680b0
s: 668054fe16cdf8741152cae863f5c636ed18b803 172.20.10.7:7005
 replicates d6fed6f21269b8469a3076ac5fb168bd20f70c26
s: ae39b7db285703f8c08412d6b04998c60a634295 172.20.10.7:7006
 replicates 51a0f62dacead745ce5351cdbe0bdbae553ce413
can i set the above configuration? (type &#39;yes&#39; to accept):yes

输入yes回车

>>> nodes configuration updated
>>> assign a different config epoch to each node
>>> sending cluster meet messages to join the cluster
waiting for the cluster to join
......
>>> performing cluster check (using node 172.20.10.7:7001)
m: a4128b5e581c3722acd9b093c5f29f5056f680b0 172.20.10.7:7001
 slots:[0-5460] (5461 slots) master
 1 additional replica(s)
m: d6fed6f21269b8469a3076ac5fb168bd20f70c26 172.20.10.7:7002
 slots:[5461-10922] (5462 slots) master
 1 additional replica(s)
s: 45cc35740ac67f7988bb75325871ba12d08a76e4 172.20.10.7:7004
 slots: (0 slots) slave
 replicates a4128b5e581c3722acd9b093c5f29f5056f680b0
m: 51a0f62dacead745ce5351cdbe0bdbae553ce413 172.20.10.7:7003
 slots:[10923-16383] (5461 slots) master
 1 additional replica(s)
s: 668054fe16cdf8741152cae863f5c636ed18b803 172.20.10.7:7005
 slots: (0 slots) slave
 replicates d6fed6f21269b8469a3076ac5fb168bd20f70c26
s: ae39b7db285703f8c08412d6b04998c60a634295 172.20.10.7:7006
 slots: (0 slots) slave
 replicates 51a0f62dacead745ce5351cdbe0bdbae553ce413
[ok] all nodes agree about slots configuration.
>>> check for open slots...
>>> check slots coverage...
[ok] all 16384 slots covered.

至此,reids5 集群搭建完成。

6、集群的操作

6.1、关闭集群

方法一:

  redis5 提供了关闭集群的工具,在如下目录:

/root/redis-5.0.0/utils/create-cluster

   打开此文件修改端口为我们自己的,如下所示:

Centos7에서 redis5 클러스터를 구축하고 사용하는 방법

端口prot设置为7000,nodes为6,工具会自动累加1 生成 7001-7006 六个节点 用于操作。

往下看再修改路径 和 添加 ip地址,如果不加会默认本地127.0.0.1

Centos7에서 redis5 클러스터를 구축하고 사용하는 방법

修改后,执行如下命令关闭集群:

/root/redis-5.0.0/utils/create-cluster/create-cluster stop

方法二:

create-cluster目录下编写脚本文件:vim shutdown.sh
内容如下:

/usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7001 shutdown
/usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7002 shutdown
/usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7003 shutdown
/usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7004 shutdown
/usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7005 shutdown
/usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7006 shutdown

然后执行chmod u+x shutdown.sh将shutdown.sh变成可执行文件

在当前目录下启动: ./shutdown.sh

查看:ps aux|grep redis

官方:/usr/local/redis-cluster/redis-cli -a xxx -c -h 192.168.5.100 -p 8001

提示:-a访问服务端密码,-c表示集群模式,-h指定ip地址,-p指定端口号

6.2、重新启动集群

/root/redis-5.0.0/utils/create-cluster/create-cluster start

6.3、使用脚本文件启动集群

vim startall.sh 追加如下内容:(记得改自己ip地址)

/usr/local/redis-cluster/redis-cli --cluster create 172.20.10.7:7001 172.20.10.7:7002 172.20.10.7:7003 172.20.10.7:7004 172.20.10.7:7005 172.20.10.7:7006 --cluster-replicas

 启动:./startall.sh

7、测试集群

redis-cluster目录下执行

redis01/redis-cli -h 192.168.25.153 -p 7002 -c

2.2. 소스 코드를 다운로드하고 압축을 풀고 컴파일합니다.

rrreee

3. 6개의 Redis 구성 파일 생성

6개의 구성 파일은 동일한 디렉터리에 있을 수 없습니다. 여기서는 다음과 같이 정의하세요: 🎜

/root/software/redis/redis-cluster-conf/7001/redis.conf
/root/software/redis/redis-cluster-conf/7002/redis .conf
/root/software/redis/redis-cluster-conf/7003/redis.conf
/root/software/redis/redis-cluster-conf/7004/redis.conf
/root/software/redis/ redis-cluster-conf/7005/redis.conf
/root/software/redis/redis-cluster-conf/7006/redis.conf🎜🎜일부 작업 명령은 다음과 같습니다. 참고용: 🎜rrreee🎜Configuration 파일 내용은 다음과 같습니다. 🎜rrreee🎜 포트와 pidfile은 다른 폴더에 따라 조정되어야 합니다. 🎜🎜나머지 5개의 인스턴스를 만듭니다. 🎜rrreee🎜redis02~redis06의 redis.conf에서 포트와 pidfile을 각각 수정합니다.🎜

🎜4 노드를 시작합니다🎜🎜🎜redis01, redis02를 입력합니다. ...redis06 디렉터리, 실행: ./redis-server ./redis.conf🎜🎜배치 파일을 생성하고 동시에 6개의 Redis를 시작하세요🎜🎜vim startall.sh🎜🎜다음을 추가하세요 내용 :🎜rrreee🎜그런 다음 chmod u+x start-all.sh를 실행하여 start-all.sh를 실행 파일로 바꿉니다🎜🎜현재 디렉터리에서 시작: ./startall.sh🎜🎜보기: ps aux|grep redis🎜🎜<img src="https://img.php.cn/upload/article%20/%20000/887/227/168559062896660.jpg?x-oss-process=image/resize,p_40" alt="Centos7에서 redis5 클러스터를 구축하고 사용하는 방법">🎜

🎜5. 클러스터 시작🎜🎜🎜 왜냐하면 Redis 5.0.0 버전을 사용하여 구축된 클러스터는 컴파일된 redis 디렉터리에 있는 redis-cli 파일을 redis-cluster 디렉터리에 복사하기만 하면 되기 때문입니다. (redis 버전 5.0 이후에는 C 언어로 바로 시작됩니다)🎜

/usr/local/redis-cluster/redis-cli --cluster create 172.20.10.7:7001 172.20.10.7:7002 172.20.10.7 : 7003 172.20.10.7:7004 172.20.10.7:7005 172.20.10.7:7006 --cluster-replicas 1🎜

🎜시작 후 다음과 같은 성공 메시지를 볼 수 있습니다: 🎜rrreee🎜yes를 입력하고 Enter를 누르세요. 🎜rrreee🎜이제 reids5 클러스터가 완성되었습니다. 🎜

🎜6. 클러스터 작업🎜🎜

🎜6.1. 클러스터 종료🎜🎜🎜방법 1:🎜🎜 redis5는 종료 도구를 제공합니다. 다음 디렉터리에 있습니다. 🎜🎜/root/redis-5.0.0/utils/create-cluster🎜🎜 이 파일을 열어 아래와 같이 포트를 자체적으로 수정합니다. 🎜🎜 Centos7에서 redis5 클러스터를 구축하고 사용하는 방법🎜🎜포트 prot는 7000으로 설정된 경우 노드는 6이며, 도구는 자동으로 1을 누적하여 작업을 위한 6개의 노드(7001-7006)를 생성합니다. 🎜🎜경로를 찾아 수정한 후 IP 주소를 추가하세요. 추가하지 않으면 기본값은 로컬 127.0.0.1🎜🎜Centos7에서 redis5 클러스터를 구축하고 사용하는 방법🎜🎜수정 후 다음 명령을 실행하여 클러스터를 종료합니다: 🎜🎜/root/ redis-5.0.0/utils/create-cluster/create -cluster stop🎜🎜방법 2: 🎜🎜create-cluster 디렉터리에 스크립트 파일 쓰기: vim shutdown.sh
내용은 다음과 같습니다. 다음: 🎜rrreee🎜그런 다음 chmod u+x shutdown.sh를 실행합니다. shutdown.sh를 실행 파일로 변환🎜🎜현재 디렉터리에서 시작합니다: ./shutdown.sh🎜🎜보기: ps aux| grep redis🎜🎜공식:/usr/local/redis-cluster/redis-cli -a xxx -c -h 192.168.5.100 -p 8001🎜🎜팁: -a 액세스 서버 비밀번호, -c는 클러스터 모드를 나타내고, -h는 지정합니다. IP 주소, -p는 포트 번호를 지정합니다🎜<h3 id="yisu3h-to199 ">🎜6.2, 클러스터 다시 시작🎜🎜🎜<code>/root/redis-5.0.0/utils/create-cluster/create-cluster start 🎜

🎜6.3 , 스크립트 파일을 사용하여 클러스터 🎜🎜🎜vim startall.sh를 시작하고 다음 콘텐츠를 추가하세요. (IP 주소 변경을 기억하세요) 🎜rrreee🎜 시작: ./startall.sh🎜

🎜7. 클러스터 테스트 🎜🎜🎜redis-cluster 디렉터리에서 실행🎜🎜redis01/redis-cli -h 192.168.25.153 -p 7002 -c🎜🎜여기서 -c는 클러스터 모드에서 redis에 연결하는 것을 의미하고, -h는 IP 주소를 지정하고, -p는 포트 번호를 지정합니다.🎜🎜클러스터 노드 클러스터 노드 정보 쿼리🎜🎜클러스터 정보 클러스터 상태 정보 쿼리 🎜

위 내용은 Centos7에서 redis5 클러스터를 구축하고 사용하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명
이 기사는 亿速云에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제
Redis : 데이터베이스 또는 서버? 역할을 시연합니다Redis : 데이터베이스 또는 서버? 역할을 시연합니다Apr 28, 2025 am 12:06 AM

redisisbothadatabaseandaserver.1) asadatabase, itusesin-memorystorageforfestaccess, 이상적인 우림-타이어 배제 및 캐치.

REDIS : NOSQL 접근법의 장점REDIS : NOSQL 접근법의 장점Apr 27, 2025 am 12:09 AM

Redis는 고성능과 유연성을 제공하는 NOSQL 데이터베이스입니다. 1) 대규모 데이터 및 높은 동시성을 처리하는 데 적합한 키 가치 쌍을 통해 데이터를 저장합니다. 2) 메모리 저장 및 단일 스레드 모델은 빠른 읽기 및 쓰기 및 원자력을 보장합니다. 3) RDB 및 AOF 메커니즘을 사용하여 데이터를 지속하여 고 가용성 및 스케일 아웃을 지원합니다.

REDIS : 건축과 목적을 이해합니다REDIS : 건축과 목적을 이해합니다Apr 26, 2025 am 12:11 AM

Redis는 주로 데이터베이스, 캐시 및 메시지 중개인으로 사용되는 메모리 데이터 구조 스토리지 시스템입니다. 핵심 기능에는 단일 스레드 모델, I/O 멀티플렉싱, 지속 메커니즘, 복제 및 클러스터링 기능이 포함됩니다. Redis는 일반적으로 캐싱, 세션 저장 및 메시지 대기열을위한 실제 응용 프로그램에 사용됩니다. 올바른 데이터 구조를 선택하고 파이프 라인 및 트랜잭션을 사용하여 모니터링 및 튜닝을 통해 성능을 크게 향상시킬 수 있습니다.

Redis vs. SQL 데이터베이스 : 주요 차이점Redis vs. SQL 데이터베이스 : 주요 차이점Apr 25, 2025 am 12:02 AM

Redis와 SQL 데이터베이스의 주요 차이점은 Redis가 고성능 및 유연성 요구 사항에 적합한 메모리 데이터베이스라는 것입니다. SQL 데이터베이스는 관계형 데이터베이스로 복잡한 쿼리 및 데이터 일관성 요구 사항에 적합합니다. 구체적으로, 1) Redis는 고속 데이터 액세스 및 캐싱 서비스를 제공하고 캐싱 및 실시간 데이터 처리에 적합한 여러 데이터 유형을 지원합니다. 2) SQL 데이터베이스는 테이블 구조를 통한 데이터를 관리하고 복잡한 쿼리 및 트랜잭션 처리를 지원하며 데이터 일관성이 필요한 전자 상거래 및 금융 시스템과 같은 시나리오에 적합합니다.

Redis : 데이터 저장소 및 서비스 역할을하는 방법Redis : 데이터 저장소 및 서비스 역할을하는 방법Apr 24, 2025 am 12:08 AM

redisactsasbothadatastoreandaservice.1) asadatastore, itusesin-memorystorageforfastoperations, 지원을 지원합니다

Redis 대 기타 데이터베이스 : 비교 분석Redis 대 기타 데이터베이스 : 비교 분석Apr 23, 2025 am 12:16 AM

redis 与其他数据库相比 与其他数据库相比, 与其他数据库相比 : 1) 速度极快 速度极快 速度极快, 读写操作通常在微秒级别; 2) 支持丰富的数据结构和操作; 3) 灵活的使用场景 3) 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 灵活的使用场景 3) redis 또는 기타 데이터베이스를 선택할 때 특정 요구 사항과 시나리오에 따라 다릅니다. Redis는 고성능 및 저도가 낮은 응용 프로그램에서 잘 수행됩니다.

Redis의 역할 : 데이터 저장 및 관리 기능 탐색Redis의 역할 : 데이터 저장 및 관리 기능 탐색Apr 22, 2025 am 12:10 AM

Redis는 데이터 저장 및 관리에서 핵심적인 역할을하며 여러 데이터 구조 및 지속 메커니즘을 통해 현대 애플리케이션의 핵심이되었습니다. 1) Redis는 문자열, 목록, 컬렉션, 주문 컬렉션 및 해시 테이블과 같은 데이터 구조를 지원하며 캐시 및 복잡한 비즈니스 로직에 적합합니다. 2) RDB와 AOF의 두 가지 지속 방법을 통해 Redis는 신뢰할 수있는 스토리지 및 데이터의 빠른 복구를 보장합니다.

REDIS : NOSQL 개념 이해REDIS : NOSQL 개념 이해Apr 21, 2025 am 12:04 AM

Redis는 대규모 데이터의 효율적인 저장 및 액세스에 적합한 NOSQL 데이터베이스입니다. 1.Redis는 여러 데이터 구조를 지원하는 오픈 소스 메모리 데이터 구조 스토리지 시스템입니다. 2. 캐싱, 세션 관리 등에 적합한 매우 빠른 읽기 및 쓰기 속도를 제공합니다. 3. REDIS는 RDB 및 AOF를 통해 지속성을 지원하고 데이터 보안을 보장합니다. 4. 사용 예제에는 기본 키 값 쌍 작업 및 고급 수집 중복 제거 기능이 포함됩니다. 5. 일반적인 오류에는 연결 문제, 데이터 유형 불일치 및 메모리 오버플로가 포함되므로 디버깅에주의를 기울여야합니다. 6. 성능 최적화 제안에는 적절한 데이터 구조 선택 및 메모리 제거 전략 설정이 포함됩니다.

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

mPDF

mPDF

mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

VSCode Windows 64비트 다운로드

VSCode Windows 64비트 다운로드

Microsoft에서 출시한 강력한 무료 IDE 편집기