注意:本文档配置的为root用户集群操作脚本,如果要配置其他用户请修改相关配置。
Redis Cluster启动脚本(start-redis-cluster)
sudo su
cd /bin
vi start-redis-cluster
脚本内容如下:
#!/bin/bash
echo "start redis-cluster-------------------------------------------------"
for i in bigdata-node1
do
ssh $i "source /etc/profile;/usr/local/redis_cluster/6001/redis-server /usr/local/redis_cluster/6001/redis.conf"
ssh $i "source /etc/profile;/usr/local/redis_cluster/6002/redis-server /usr/local/redis_cluster/6002/redis.conf"
done
for i in bigdata-node2
do
ssh $i "source /etc/profile;/usr/local/redis_cluster/6003/redis-server /usr/local/redis_cluster/6003/redis.conf"
ssh $i "source /etc/profile;/usr/local/redis_cluster/6004/redis-server /usr/local/redis_cluster/6004/redis.conf"
done
for i in bigdata-node3
do
ssh $i "source /etc/profile;/usr/local/redis_cluster/6005/redis-server /usr/local/redis_cluster/6005/redis.conf"
ssh $i "source /etc/profile;/usr/local/redis_cluster/6006/redis-server /usr/local/redis_cluster/6006/redis.conf"
done
sleep 1s
echo "redis-cluster status------------------------------------------------"
for i in bigdata-node1
do
echo ------------------- $i --------------
ssh $i "source /etc/profile;ps -ef |grep redis"
done
for i in bigdata-node2
do
echo ------------------- $i --------------
ssh $i "source /etc/profile;ps -ef |grep redis"
done
for i in bigdata-node3
do
echo ------------------- $i --------------
ssh $i "source /etc/profile;ps -ef |grep redis"
done
exit 0
设置脚本执行权限:
chmod +x start-redis-cluster
Redis Cluster停止脚本(stop-redis-cluster)
sudo su
cd /bin
vi stop-redis-cluster
脚本内容如下:
#!/bin/bash
echo "stop redis-cluster-------------------------------------------------"
for i in bigdata-node1
do
ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.101 -p 6001 shutdown"
ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.101 -p 6002 shutdown"
ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.102 -p 6003 shutdown"
ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.102 -p 6004 shutdown"
ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.103 -p 6005 shutdown"
ssh $i "source /etc/profile;/usr/local/redis/bin/redis-cli -a hadoopredis -c -h 192.168.0.103 -p 6006 shutdown"
done
sleep 1s
echo "redis-cluster status------------------------------------------------"
for i in bigdata-node1
do
echo ------------------- $i --------------
ssh $i "source /etc/profile;ps -ef |grep redis"
done
for i in bigdata-node2
do
echo ------------------- $i --------------
ssh $i "source /etc/profile;ps -ef |grep redis"
done
for i in bigdata-node3
do
echo ------------------- $i --------------
ssh $i "source /etc/profile;ps -ef |grep redis"
done
exit 0
设置脚本执行权限:
chmod +x stop-redis-cluster
分发(选做):
# 使用root账户分发至其他节点
scp -r /bin/*-redis-cluster root@bigdata-node2:/bin/
scp -r /bin/*-redis-cluster root@bigdata-node3:/bin/