HDFS启动脚本(非HA)(_start-hdfs-cluster)_

  1. cd /usr/local/bin
  2. sudo vi start-hdfs-cluster

脚本内容如下:_

  1. #!/bin/bash
  2. HADOOP_HOME=/home/vagrant/modules/hadoop-2.7.2
  3. echo "start hdfs-----------------------------------------------------"
  4. for i in bigdata-node1
  5. do
  6. ssh $i "source /etc/profile;${HADOOP_HOME}/sbin/start-dfs.sh"
  7. done
  8. sleep 3s
  9. echo "start done..."
  10. echo "cluster jps status------------------------------------------------"
  11. jpsx
  12. exit 0

设置脚本执行权限:_

  1. sudo chmod +x start-hdfs-cluster
  2. sudo chown vagrant:vagrant start-hdfs-cluster

HDFS停止脚本(非HA)(stop-_hdfs-cluster)_

  1. cd /usr/local/bin
  2. sudo vi stop-hdfs-cluster

脚本内容如下:_

  1. #!/bin/bash
  2. HADOOP_HOME=/home/vagrant/modules/hadoop-2.7.2
  3. echo "stop hdfs-----------------------------------------------------"
  4. for i in bigdata-node1
  5. do
  6. ssh $i "source /etc/profile;${HADOOP_HOME}/sbin/stop-dfs.sh"
  7. done
  8. sleep 3s
  9. echo "stop done..."
  10. echo "cluster jps status------------------------------------------------"
  11. jpsx
  12. exit 0

设置脚本执行权限:_

  1. sudo chmod +x stop-hdfs-cluster
  2. sudo chown vagrant:vagrant stop-hdfs-cluster

YARN启动脚本(非HA)(_start-yarn-cluster)_

  1. cd /usr/local/bin
  2. sudo vi start-yarn-cluster

脚本内容如下:_

  1. #!/bin/bash
  2. HADOOP_HOME=/home/vagrant/modules/hadoop-2.7.2
  3. echo "start yarn-----------------------------------------------------"
  4. for i in bigdata-node1
  5. do
  6. ssh $i "source /etc/profile;${HADOOP_HOME}/sbin/start-yarn.sh"
  7. done
  8. sleep 3s
  9. echo "start mr-jobhistory-----------------------------------------------------"
  10. for i in bigdata-node1
  11. do
  12. ssh $i "source /etc/profile;${HADOOP_HOME}/sbin/mr-jobhistory-daemon.sh start historyserver"
  13. ssh $i "source /etc/profile;${HADOOP_HOME}/sbin/yarn-daemon.sh start timelineserver"
  14. done
  15. sleep 3s
  16. echo "start done..."
  17. echo "cluster jps status------------------------------------------------"
  18. jpsx
  19. exit 0

设置脚本执行权限:_

  1. sudo chmod +x start-yarn-cluster
  2. sudo chown vagrant:vagrant start-yarn-cluster

YARN停止脚本(非HA)(_stop-yarn-cluster)_

  1. cd /usr/local/bin
  2. sudo vi stop-yarn-cluster

脚本内容如下:_

  1. #!/bin/bash
  2. HADOOP_HOME=/home/vagrant/modules/hadoop-2.7.2
  3. # 关闭mr-jobhistory
  4. echo "stop mr-jobhistory"
  5. for i in bigdata-node1
  6. do
  7. ssh $i "source /etc/profile;${HADOOP_HOME}/sbin/mr-jobhistory-daemon.sh stop historyserver"
  8. ssh $i "source /etc/profile;${HADOOP_HOME}/sbin/yarn-daemon.sh stop timelineserver"
  9. done
  10. sleep 3s
  11. echo "stop yarn"
  12. for i in bigdata-node1
  13. do
  14. ssh $i "source /etc/profile;${HADOOP_HOME}/sbin/stop-yarn.sh"
  15. done
  16. sleep 3s
  17. echo "stop done..."
  18. echo "cluster jps status------------------------------------------------"
  19. jpsx
  20. exit 0

设置脚本执行权限:_

  1. sudo chmod +x stop-yarn-cluster
  2. sudo chown vagrant:vagrant stop-yarn-cluster

分发(选做):

  1. # 使用root账户分发至其他节点
  2. sudo scp -r /usr/local/bin/*-{hdfs,yarn}-cluster root@bigdata-node2:/usr/local/bin/
  3. sudo scp -r /usr/local/bin/*-{hdfs,yarn}-cluster root@bigdata-node3:/usr/local/bin/