redis5.0.5集羣

 參考https://blog.csdn.net/sunrisetg/article/details/102884488

正常搭建集羣后,使用時發現ip變成內網。

解決方案:

1.殺死節點(不是停止集羣,否則不生效)

2.找到所有節點的nodes.conf文件,把內網地址改成你的ip

3.重啓節點 ./redis-server redis.conf

 

二、redis集羣搭建:
1.​​​​CentOs命令如下:​

wget http://download.redis.io/releases/redis-5.0.5.tar.gz
 
tar xzf redis-5.0.5.tar.gz
 
cd redis-5.0.5
 
yum install gcc
 
make MALLOC=libc
 
cd src && make install
 
cd ../utils/create-cluster/
 
ps -ef|grep redis
 
vim create-cluster
2.修改create-cluster配置文件:

注:(以下這幾點必須弄,否則阿里雲公網節點間切換不正常)

2.1. start命令:   加入redis密碼        --requirepass 88888888    

                 關閉安全模式(公網可以連接到redis)    --protected-mode no

2.2.create命令: 將127.0.0.1修改爲阿里雲公網的ip地址 (123.456.200這是假ip)

                 加入redis密碼  -a 88888888

2.3.stop命令:加入redis密碼       -a 88888888 

2.4.打開阿里雲端口

2.4.打開阿里雲端口

 

#!/bin/bash

# Settings
PORT=7000
TIMEOUT=2000
NODES=6
REPLICAS=1

# You may want to put the above config parameters into config.sh in order to
# override the defaults without modifying this script.

if [ -a config.sh ]
then
    source "config.sh"
fi

# Computed vars
ENDPORT=$((PORT+NODES))

if [ "$1" == "start" ]
then
    while [ $((PORT < ENDPORT)) != "0" ]; do
        PORT=$((PORT+1))
        echo "Starting $PORT"
        ../../src/redis-server --requirepass 88888888 --protected-mode no  --port $PORT --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes
    done
    exit 0
fi

if [ "$1" == "create" ]
then
    HOSTS=""
    while [ $((PORT < ENDPORT)) != "0" ]; do
        PORT=$((PORT+1))
        HOSTS="$HOSTS 123.456.200:$PORT"
    done
    ../../src/redis-cli -a 88888888  --cluster create $HOSTS --cluster-replicas $REPLICAS
    exit 0
fi

if [ "$1" == "stop" ]
then
    while [ $((PORT < ENDPORT)) != "0" ]; do
        PORT=$((PORT+1))
        echo "Stopping $PORT"
        ../../src/redis-cli -a 88888888  -p $PORT shutdown nosave
    done
    exit 0
fi

if [ "$1" == "watch" ]
then
    PORT=$((PORT+1))
    while [ 1 ]; do
        clear
        date
        ../../src/redis-cli -p $PORT cluster nodes | head -30
        sleep 1
    done
    exit 0
fi

if [ "$1" == "tail" ]
then
    INSTANCE=$2
    PORT=$((PORT+INSTANCE))
    tail -f ${PORT}.log
    exit 0
fi

if [ "$1" == "call" ]
then
    while [ $((PORT < ENDPORT)) != "0" ]; do
        PORT=$((PORT+1))
        ../../src/redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9
    done
    exit 0
fi

if [ "$1" == "clean" ]
then
    rm -rf *.log
    rm -rf appendonly*.aof
    rm -rf dump*.rdb
    rm -rf nodes*.conf
    exit 0
fi

if [ "$1" == "clean-logs" ]
then
    rm -rf *.log
    exit 0
fi

echo "Usage: $0 [start|create|stop|watch|tail|clean]"
echo "start       -- Launch Redis Cluster instances."
echo "create      -- Create a cluster using redis-cli --cluster create."
echo "stop        -- Stop Redis Cluster instances."
echo "watch       -- Show CLUSTER NODES output (first 30 lines) of first node."
echo "tail <id>   -- Run tail -f of instance at base port + ID."
echo "clean       -- Remove all instances data, logs, configs."
echo "clean-logs  -- Remove just instances logs."


3.啓動集羣

#1.啓動集羣
sh /root/javaxiaobang/redis-5.0.5/utils/create-cluster/create-cluster start
#2.建立集羣間聯繫
sh /root/javaxiaobang/redis-5.0.5/utils/create-cluster/create-cluster create
#3.停止集羣
sh /root/javaxiaobang/redis-5.0.5/utils/create-cluster/create-cluster stop
#4.清除集羣
sh /root/javaxiaobang/redis-5.0.5/utils/create-cluster/create-cluster clean
      4.連接redis

 redis-cli -h 127.0.0.1 -p 7001 -c -a 密碼
 
 -h ip地址
 -p 端口號
 -a 密碼
 -c 集羣
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章