Recently, the redis cluster deployment has been used. By the way, you can learn a lot about redis.
1. Download redis and support the deployment of redis cluster from 3.0. tar xzvf redis-5.0.5.tar.gz
#Download the source code and extract it through tar zxvf wget http://download.redis.io/releases/redis-5.0.5.tar.gz #Compile the source code through make, and redis cli redis server will be generated under src cd redis-5.0.5 make #Note that compilation failure may occur yum -y install gcc gcc-c++ libstdc++-devel #Due to the allocator problem, there may be errors. libc is not the default allocator, but jemalloc is the default #But if you don't have jemalloc and only libc, of course make is wrong #So make with parameters make MALLOC=libc
2. Here is a simple script to create a cluster, which is located in redis-5.0.5/utils/create-cluster/create-cluster. Through this script, you can deploy clusters of six nodes on a single server. If you need outside access, you can add the following commands. Note that the $${ip} $$in the script is the ip that can be accessed externally, and note that the - protected mode no in the start
#!/bin/bash # Settings PORT=30000 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 --port $PORT --protected-mode no --bind $${ip}$$ --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 $${ip}$$:$PORT" done ../../src/redis-cli --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 -p $PORT -h $${ip}$$ shutdown nosave done exit 0 fi if [ "$1" == "watch" ] then PORT=$((PORT+1)) while [ 1 ]; do clear date ../../src/redis-cli -p $PORT -h $${ip}$$ 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 -h $${ip}$$ $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."
Start 6 redis instances through simple command. / create cluster start, port 30001-30006
. / create cluster create and enter yes to create a redis cluster
. / create cluster stop
. / create cluster clean clean clean all log, dump, aof and conf files
. / create cluster watch can monitor slot information