create-cluster 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. # Settings
  3. PORT=30000
  4. TIMEOUT=2000
  5. NODES=6
  6. REPLICAS=1
  7. # You may want to put the above config parameters into config.sh in order to
  8. # override the defaults without modifying this script.
  9. if [ -a config.sh ]
  10. then
  11. source "config.sh"
  12. fi
  13. # Computed vars
  14. ENDPORT=$((PORT+NODES))
  15. if [ "$1" == "start" ]
  16. then
  17. while [ $((PORT < ENDPORT)) != "0" ]; do
  18. PORT=$((PORT+1))
  19. echo "Starting $PORT"
  20. ../../src/redis-server --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
  21. done
  22. exit 0
  23. fi
  24. if [ "$1" == "create" ]
  25. then
  26. HOSTS=""
  27. while [ $((PORT < ENDPORT)) != "0" ]; do
  28. PORT=$((PORT+1))
  29. HOSTS="$HOSTS 127.0.0.1:$PORT"
  30. done
  31. ../../src/redis-cli --cluster create $HOSTS --cluster-replicas $REPLICAS
  32. exit 0
  33. fi
  34. if [ "$1" == "stop" ]
  35. then
  36. while [ $((PORT < ENDPORT)) != "0" ]; do
  37. PORT=$((PORT+1))
  38. echo "Stopping $PORT"
  39. ../../src/redis-cli -p $PORT shutdown nosave
  40. done
  41. exit 0
  42. fi
  43. if [ "$1" == "watch" ]
  44. then
  45. PORT=$((PORT+1))
  46. while [ 1 ]; do
  47. clear
  48. date
  49. ../../src/redis-cli -p $PORT cluster nodes | head -30
  50. sleep 1
  51. done
  52. exit 0
  53. fi
  54. if [ "$1" == "tail" ]
  55. then
  56. INSTANCE=$2
  57. PORT=$((PORT+INSTANCE))
  58. tail -f ${PORT}.log
  59. exit 0
  60. fi
  61. if [ "$1" == "call" ]
  62. then
  63. while [ $((PORT < ENDPORT)) != "0" ]; do
  64. PORT=$((PORT+1))
  65. ../../src/redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9
  66. done
  67. exit 0
  68. fi
  69. if [ "$1" == "clean" ]
  70. then
  71. rm -rf *.log
  72. rm -rf appendonly*.aof
  73. rm -rf dump*.rdb
  74. rm -rf nodes*.conf
  75. exit 0
  76. fi
  77. if [ "$1" == "clean-logs" ]
  78. then
  79. rm -rf *.log
  80. exit 0
  81. fi
  82. echo "Usage: $0 [start|create|stop|watch|tail|clean]"
  83. echo "start -- Launch Redis Cluster instances."
  84. echo "create -- Create a cluster using redis-cli --cluster create."
  85. echo "stop -- Stop Redis Cluster instances."
  86. echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node."
  87. echo "tail <id> -- Run tail -f of instance at base port + ID."
  88. echo "clean -- Remove all instances data, logs, configs."
  89. echo "clean-logs -- Remove just instances logs."