# 分布式计算小试 # 1.首先获取本机host,作为实际计算时分区hash的种子 # 2.以*.*.*.44为主节点,*.*.*.29/30/34/43为从节点 hash=`cat /root/data/host.txt` ha=$[$hash -1] cat /root/data/test.txt | while read line do if [ $[$line%4] -eq ${ha} ];then echo $[$line*$line]>>result_${ha}.txt fi done # 3.计算开始时将脚本和data分发到各个从节点 # 4.从主节点启动各从节点的脚本,每个节点只需要计算总量的一部分 if [ ${ha} -eq 4 ];then ssh root@*.*.*.43 "sh /root/data/cm.sh" & ssh root@*.*.*.34 "sh /root/data/cm.sh" & ssh root@*.*.*.30 "sh /root/data/cm.sh" & ssh root@*.*.*.29 "sh /root/data/cm.sh" & fi sleep 5 # 5.正常执行完毕的节点会产生结果文件,将生成的结果文件发回主节点 # 6.没有结果文件的是主节点,主节点将从节点发回的结果文件汇总 if [ -b result_${ha}.txt ];then scp /root/data/result_${ha}.txt root@*.*.*.44:/root/data/ else sleep 5 cat /root/data/result_*.txt > /root/data/res_all.txt fi
备注:
test.txt文件是从1到10的数字,计算是计算每个数字的平方并输出到一个新文件。