关于云服务:阿里云redis506集群搭建

3次阅读

共计 2902 个字符,预计需要花费 8 分钟才能阅读完成。

一、引言:

去年买的阿里云上周到期了,昨晚看到双 11 新用户有优惠活动,连忙偷摸的用媳妇手机,花 800 块买了 3 年阿里云(2 核 4G),好了,搭建新环境吧!

注:须要 关上阿里云的平安组端口(https://oneinstack.com/docs/securitygroup/

二、redis 集群搭建:

1.​​​​CentOs 命令如下:​

wget http://download.redis.io/releases/redis-5.0.6.tar.gz tar xzf redis-5.0.6.tar.gz cd redis-5.0.6 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 qiang123    

                            敞开平安模式(公网能够连贯到 redis)    –protected-mode no

2.2.create 命令:将 127.0.0.1 批改为阿里云公网的 ip 地址(138.156.224.5 这是假 ip)

                            退出 redis 明码                                       -a qiang123 

2.3.stop 命令:

                            退出 redis 明码                                       -a qiang123 

2.4. 关上阿里云端口

#!/bin/bash # SettingsPORT=7000TIMEOUT=2000NODES=6REPLICAS=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 varsENDPORT=$((PORT+NODES)) if ["$1" == "start"]then    while [$((PORT < ENDPORT)) != "0" ]; do        PORT=$((PORT+1))        echo "Starting $PORT"        ../../src/redis-server --requirepass qiang123 --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 0fi if ["$1" == "create"]then    HOSTS=""while [$((PORT < ENDPORT)) !="0"]; do        PORT=$((PORT+1))        HOSTS="$HOSTS 138.156.224.5:$PORT"done    ../../src/redis-cli -a qiang123 --cluster create $HOSTS --cluster-replicas $REPLICAS    exit 0fi if ["$1"=="stop"]then    while [$((PORT < ENDPORT)) !="0"]; do        PORT=$((PORT+1))        echo"Stopping $PORT"../../src/redis-cli -p $PORT shutdown nosave    done    exit 0fi 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 0fi if ["$1"=="tail"]then    INSTANCE=$2    PORT=$((PORT+INSTANCE))    tail -f ${PORT}.log    exit 0fi 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 0fi if ["$1"=="clean"]then    rm -rf *.log    rm -rf appendonly*.aof    rm -rf dump*.rdb    rm -rf nodes*.conf    exit 0fi if ["$1"=="clean-logs"]then    rm -rf *.log    exit 0fi 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.6/utils/create-cluster/create-cluster start#2. 建设集群间分割 sh /root/javaxiaobang/redis-5.0.6/utils/create-cluster/create-cluster create#3. 进行集群 sh /root/javaxiaobang/redis-5.0.6/utils/create-cluster/create-cluster stop#4. 革除集群 sh /root/javaxiaobang/redis-5.0.6/utils/create-cluster/create-cluster clean

      4. 连贯 redis

 redis-cli -h 127.0.0.1 -p 7001 -c -a 明码  -h ip 地址 -p 端口号 -a 明码 -c 集群
正文完
 0