Centos7上建立Redis5集群

2021-09-28 15:02:23 字數 4341 閱讀 2850

一. 基本安裝

1.安裝

cd /opt

wget wget

tar xzf redis-5.0.4.tar.gz

ln -s ./redis-5.0.4 ./redis

cd ./redis

make

2.測試

src/redis-server

src/redis-cli

redis> set foo bar

okredis> get foo

"bar"

3.集群建立

mkdir cluster

mkdir 7000 7001 7002 7003 7004 7005

cp ../redis.conf ./7000/

cp ../redis.conf ./7001/

cp ../redis.conf ./7002/

cp ../redis.conf ./7003/

cp ../redis.conf ./7004/

cp ../redis.conf ./7005/

sed -i 's/port 6379/port 7000/g' ./7000/redis.conf

sed -i 's/# cluster-enabled/cluster-enabled/g' ./7000/redis.conf

sed -i 's/# cluster-config-file nodes-6379.conf/cluster-config-file nodes.conf/g' ./7000/redis.conf

sed -i 's/# cluster-node-timeout 15000/cluster-node-timeout 5000/g' ./7000/redis.conf

sed -i 's/port 6379/port 7000/g' ./7001/redis.conf

sed -i 's/# cluster-enabled/cluster-enabled/g' ./7001/redis.conf

sed -i 's/# cluster-config-file nodes-6379.conf/cluster-config-file nodes.conf/g' ./7001/redis.conf

sed -i 's/# cluster-node-timeout 15000/cluster-node-timeout 5000/g' ./7001/redis.conf

sed -i 's/port 6379/port 7000/g' ./7002/redis.conf

sed -i 's/# cluster-enabled/cluster-enabled/g' ./7002/redis.conf

sed -i 's/# cluster-config-file nodes-6379.conf/cluster-config-file nodes.conf/g' ./7002/redis.conf

sed -i 's/# cluster-node-timeout 15000/cluster-node-timeout 5000/g' ./7002/redis.conf

sed -i 's/port 6379/port 7000/g' ./7003/redis.conf

sed -i 's/# cluster-enabled/cluster-enabled/g' ./7003/redis.conf

sed -i 's/# cluster-config-file nodes-6379.conf/cluster-config-file nodes.conf/g' ./7003/redis.conf

sed -i 's/# cluster-node-timeout 15000/cluster-node-timeout 5000/g' ./7003/redis.conf

sed -i 's/port 6379/port 7000/g' ./7004/redis.conf

sed -i 's/# cluster-enabled/cluster-enabled/g' ./7004/redis.conf

sed -i 's/# cluster-config-file nodes-6379.conf/cluster-config-file nodes.conf/g' ./7004/redis.conf

sed -i 's/# cluster-node-timeout 15000/cluster-node-timeout 5000/g' ./7004/redis.conf

sed -i 's/port 6379/port 7000/g' ./7005/redis.conf

sed -i 's/# cluster-enabled/cluster-enabled/g' ./7005/redis.conf

sed -i 's/# cluster-config-file nodes-6379.conf/cluster-config-file nodes.conf/g' ./7005/redis.conf

sed -i 's/# cluster-node-timeout 15000/cluster-node-timeout 5000/g' ./7005/redis.conf

二.集群   

1.啟動全部node指令碼   

$vi start_all_node.sh

#!/bin/bash

redis_bin_dir="/opt/redis/src"

redis_cluster_dir="/opt/redis/cluster"

cd $redis_cluster_dir/7000

nohup $redis_bin_dir/redis-server ./redis.conf > log.log 2>&1 &

cd $redis_cluster_dir/7001

nohup $redis_bin_dir/redis-server ./redis.conf > log.log 2>&1 &

cd $redis_cluster_dir/7002

nohup $redis_bin_dir/redis-server ./redis.conf > log.log 2>&1 &

cd $redis_cluster_dir/7003

nohup $redis_bin_dir/redis-server ./redis.conf > log.log 2>&1 &

cd $redis_cluster_dir/7004

nohup $redis_bin_dir/redis-server ./redis.conf > log.log 2>&1 &

cd $redis_cluster_dir/7005

nohup $redis_bin_dir/redis-server ./redis.conf > log.log 2>&1 &

2.關閉全部node指令碼

$vi stop_all_node.sh

#!/bin/bash

ps -wux | grep 'redis-server' | grep -v 'grep' | awk '' | xargs kill -9

3. 啟動集群

$chmod +x ./start_all_node.sh

#啟動全部node

./start_all_node.sh

#建立集群

/opt/redis/src/redis-cli --cluster create 192.168.0.180:7000 \

192.168.0.180:7001 192.168.0.180:7002 192.168.0.180:7003 192.168.0.180:7004 \

192.168.0.180:7005 --cluster-replicas 1

#檢視集群

$/opt/redis/src/redis-cli -p 7000 cluster nodes

關鍵配置

cluster-enabled yes     #(yes/no)是否可以作為集群的乙個node

requirepass test123 #使用者該節點時使用的密碼

masterauth test123 #作為從節點時使用該密碼連線主節點

daemonize no #(yes/no)啟動後是否作為服務在後台執行

protected-mode no #(yes/no)是否執行在保護模式,保護模式不允許從主機外的地方連線

port 7000 #監聽埠

bind 0.0.0.0 #監聽ip 不配置和配置 0.0.0.0 一樣

redis在centos7上安裝

wget解壓 現在我們要進行編譯make,但是我們在編譯之前要先檢查gcc的版本。centos7預設安裝的是4.8.5,而redis6.0只支援5.3以上版本 所以現在我們要進行公升級版本,在網上找了很多的教程,最中也是成功了 sudo yum install centos release scl ...

在centos7上安裝redis5 0 4

參考redis 5.0.5.tar.gz 安裝 tar zxvf redis 5.0.4.tar.gz,解壓會生成乙個redis 5.0.4的目錄 進入此目錄 安裝gcc依賴 yum install gcc gcc c 此時試圖用make命令安裝redis仍然出錯 參考zmalloc.h 50 31...

centos7 安裝redis和redis擴充套件

安裝redis make 如果make失敗,請安裝gcc yum install gcc 重新解壓安裝 使用 二進位制檔案是編譯完成後在src目錄下.執行如下 src redis server 你能使用redis的內建客戶端進行進行redis 的編寫 src redis cli redis setf...