注意:本文档配置的为root用户集群操作脚本,如果要配置其他用户请修改相关配置。

Redis Cluster启动脚本(start-redis-cluster)

  1. sudo su
  2. cd /bin
  3. vi start-redis-cluster

脚本内容如下:

  1. #!/bin/bash
  2. echo "start redis-cluster-------------------------------------------------"
  3. for i in bigdata-node1
  4. do
  5. ssh $i "source /etc/profile;/usr/local/redis_cluster/6001/redis-server /usr/local/redis_cluster/6001/redis.conf"
  6. ssh $i "source /etc/profile;/usr/local/redis_cluster/6002/redis-server /usr/local/redis_cluster/6002/redis.conf"
  7. done
  8. for i in bigdata-node2
  9. do
  10. ssh $i "source /etc/profile;/usr/local/redis_cluster/6003/redis-server /usr/local/redis_cluster/6003/redis.conf"
  11. ssh $i "source /etc/profile;/usr/local/redis_cluster/6004/redis-server /usr/local/redis_cluster/6004/redis.conf"
  12. done
  13. for i in bigdata-node3
  14. do
  15. ssh $i "source /etc/profile;/usr/local/redis_cluster/6005/redis-server /usr/local/redis_cluster/6005/redis.conf"
  16. ssh $i "source /etc/profile;/usr/local/redis_cluster/6006/redis-server /usr/local/redis_cluster/6006/redis.conf"
  17. done
  18. sleep 1s
  19. echo "redis-cluster status------------------------------------------------"
  20. for i in bigdata-node1
  21. do
  22. echo ------------------- $i --------------
  23. ssh $i "source /etc/profile;ps -ef |grep redis"
  24. done
  25. for i in bigdata-node2
  26. do
  27. echo ------------------- $i --------------
  28. ssh $i "source /etc/profile;ps -ef |grep redis"
  29. done
  30. for i in bigdata-node3
  31. do
  32. echo ------------------- $i --------------
  33. ssh $i "source /etc/profile;ps -ef |grep redis"
  34. done
  35. exit 0

设置脚本执行权限:

  1. chmod +x start-redis-cluster

Redis Cluster停止脚本(stop-redis-cluster)

  1. sudo su
  2. cd /bin
  3. vi stop-redis-cluster

脚本内容如下:

  1. #!/bin/bash
  2. echo "stop redis-cluster-------------------------------------------------"
  3. for i in bigdata-node1
  4. do
  5. ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.101 -p 6001 shutdown"
  6. ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.101 -p 6002 shutdown"
  7. ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.102 -p 6003 shutdown"
  8. ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.102 -p 6004 shutdown"
  9. ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.103 -p 6005 shutdown"
  10. ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.103 -p 6006 shutdown"
  11. done
  12. sleep 1s
  13. echo "redis-cluster status------------------------------------------------"
  14. for i in bigdata-node1
  15. do
  16. echo ------------------- $i --------------
  17. ssh $i "source /etc/profile;ps -ef |grep redis"
  18. done
  19. for i in bigdata-node2
  20. do
  21. echo ------------------- $i --------------
  22. ssh $i "source /etc/profile;ps -ef |grep redis"
  23. done
  24. for i in bigdata-node3
  25. do
  26. echo ------------------- $i --------------
  27. ssh $i "source /etc/profile;ps -ef |grep redis"
  28. done
  29. exit 0

设置脚本执行权限:

  1. chmod +x stop-redis-cluster

分发(选做):

  1. # 使用root账户分发至其他节点
  2. scp -r /bin/*-redis-cluster root@bigdata-node2:/bin/
  3. scp -r /bin/*-redis-cluster root@bigdata-node3:/bin/