Spark with Pi Cluster 2


Background

We might need some commands which can be run together across all servers in the cluster.

Command sending to the cluster

  1. List other pis other than itself.
    
    function otherpis {
        grep "pi" /etc/hosts | awk '{print $2}' | grep -v $(hostname)
    }
              
  2. General cluster cmd for any purpose
    
    clustercmd() {
        for pi in $(otherpis)
        do
            echo "ssh $pi $@"
            ssh $pi "$@"
        done
        echo "$@"
        eval $@
    }
              
    1. For examples,
    2. 
      clustercmd date
      clustercmd 'sudo apt install htpdate -y > /dev/null 2>&1'
      clustercmd sudo htpdate -a -l time.nist.gov
                
  3. Commands for shutdown or reboot together,
    
    function clusterreboot {
        clustercmd sudo shutdown -r now
    }
    function clustershutdown {
        clustercmd sudo shutdown now
    }
              
  4. Command for copy file to another servers in cluster.
    
    clusterscp() {
        for pi in $(otherpis); do
            cat $1 | ssh $pi "sudo tee $1" > /dev/null 2>&1
        done
    }
              

References