create-cluster 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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-trib.rb create --replicas $REPLICAS $HOSTS
  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. 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. 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. echo "Usage: $0 [start|create|stop|watch|tail|clean]"
  78. echo "start -- Launch Redis Cluster instances."
  79. echo "create -- Create a cluster using redis-trib create."
  80. echo "stop -- Stop Redis Cluster instances."
  81. echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node."
  82. echo "tail <id> -- Run tail -f of instance at base port + ID."
  83. echo "clean -- Remove all instances data, logs, configs."