def tasktrackerconf(): ip = all_ip.slaves_ip() for i in range(len(ip)): getoutput( "scp /root/Desktop/project/task0/mapred-site.xml {}.{}.{}.{}:/etc/hadoop/" .format(ip[i][0], ip[i][1], ip[i][2], ip[i][3]))
def slaveconf(): ip = all_ip.slaves_ip() for i in range(len(ip)): getoutput( "scp /root/Desktop/project/task0/hdfs-site2.xml {}.{}.{}.{}:/etc/hadoop/hdfs-site.xml" .format(ip[i][0], ip[i][1], ip[i][2], ip[i][3])) getoutput( "scp /root/Desktop/project/task0/core-site.xml {}.{}.{}.{}:/etc/hadoop/hdfs-site.xml" .format(ip[i][0], ip[i][1], ip[i][2], ip[i][3]))
def set_slaves_hostname(): ip = all_ip.slaves_ip() for i in range(len(ip)): print(ip[i]) getoutput("ssh {}.{}.{}.{} hostnamectl set-hostname s{}.com".format( ip[i][0], ip[i][1], ip[i][2], ip[i][3], i + 1)) #getoutput("ssh {0}.{1}.{2}.{3} echo '{0}.{1}.{2}.{3} m{4}.com' >> /etc/hosts".format(ip[0],ip[1],ip[2],ip[3],i+1)) getoutput( "echo '{}.{}.{}.{} s{}.com' >> /root/Desktop/project/task0/hosts". format(ip[i][0], ip[i][1], ip[i][2], ip[i][3], i + 1))
def send_hosts_to_all_ip(): ip1 = all_ip.master_ip() ip2 = all_ip.jobtracker_ip() ip3 = all_ip.slaves_ip() ip4 = all_ip.slaves_ip() getoutput( "scp /root/Desktop/project/task0/hosts {}.{}.{}.{}:/etc/hosts".format( ip1[0], ip1[1], ip1[2], ip1[3])) getoutput( "scp /root/Desktop/project/task0/hosts {}.{}.{}.{}:/etc/hosts".format( ip2[0], ip2[1], ip2[2], ip2[3])) getoutput( "scp /root/Desktop/project/task0/hosts {}.{}.{}.{}:/etc/hosts".format( ip4[0], ip4[1], ip4[2], ip4[3])) for i in range(len(ip3)): getoutput( "scp /root/Desktop/project/task0/hosts {}.{}.{}.{}:/etc/hosts". format(ip3[i][0], ip3[i][1], ip3[i][2], ip3[i][3]))
def hadoop_install_in_slaves(): ip = all_ip.slaves_ip() for i in range(len(ip)): a = getoutput("ssh {}.{}.{}.{} hadoop version".format( ip[i][0], ip[i][1], ip[i][2], ip[i][3])) if a == 0: pass else: getoutput( "scp /root/Desktop/project/task0/hadoop-1.2.1-1.x86_64.rpm {}.{}.{}.{}:" .format(ip[i][0], ip[i][1], ip[i][2], ip[i][3])) getoutput( "ssh {}.{}.{}.{} rpm -ivh hadoop-1.2.1-1.x86_64.rpm --force". format(ip[i][0], ip[i][1], ip[i][2], ip[i][3]))
def java_install_in_slaves(): ip = all_ip.slaves_ip() for i in range(len(ip)): a = getoutput("ssh {}.{}.{}.{} java -version".format( ip[i][0], ip[i][1], ip[i][2], ip[i][3])) if a == 0: print("Java is already installed") else: getoutput( "scp /root/Desktop/project/task0/jdk-8u171-linux-x64.rpm {}.{}.{}.{}:" .format(ip[i][0], ip[i][1], ip[i][2], ip[i][3])) getoutput( "ssh {}.{}.{}.{} rpm -ivh jdk-8u171-linux-x64.rpm".format( ip[i][0], ip[i][1], ip[i][2], ip[i][3])) getoutput( "scp /root/Desktop/project/task0/.bashrc {}.{}.{}.{}:".format( ip[i][0], ip[i][1], ip[i][2], ip[i][3]))
def with_slaves(): ip=all_ip.slaves_ip() for i in range(len(ip)): os.system("ssh-copy-id {}.{}.{}.{}".format(ip[i][0],ip[i][1],ip[i][2],ip[i][3]))