阿里云redis5.0.6集群搭建

1446 篇文章 13 订阅
1446 篇文章 7 订阅

一、引言:

去年买的阿里云上周到期了,昨晚看到双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 集群
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值