MySQL启动脚本(start-mysql)

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

脚本内容如下:

  1. #!/bin/bash
  2. echo "start MySQL-------------------------------------------------"
  3. for i in bigdata-node3
  4. do
  5. ssh $i "source /etc/profile;service mysql start"
  6. done
  7. sleep 5s
  8. echo "MySQL status------------------------------------------------"
  9. for i in bigdata-node3
  10. do
  11. echo ------------------- $i --------------
  12. ssh $i "source /etc/profile;service mysql status"
  13. done
  14. exit 0

设置脚本执行权限:

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

MySQL停止脚本(stop-mysql)

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

脚本内容如下:

  1. #!/bin/bash
  2. echo "stop MySQL-------------------------------------------------"
  3. for i in bigdata-node3
  4. do
  5. ssh $i "source /etc/profile;service mysql stop"
  6. done
  7. sleep 5s
  8. echo "MySQL status------------------------------------------------"
  9. for i in bigdata-node3
  10. do
  11. echo ------------------- $i --------------
  12. ssh $i "source /etc/profile;service mysql status"
  13. done
  14. exit 0

设置脚本执行权限:

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

MySQL状态查看脚本(status-mysql)

  1. cd /usr/local/bin
  2. sudo vi status-mysql

脚本内容如下:

  1. #!/bin/bash
  2. echo "MySQL status------------------------------------------------"
  3. for i in bigdata-node3
  4. do
  5. echo "${i}------------------------------------"
  6. ssh $i "source /etc/profile;service mysql status"
  7. done
  8. exit 0

设置脚本执行权限:

  1. sudo chmod +x status-mysql
  2. sudo chown vagrant:vagrant status-mysql

分发(选做):

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