def sysncTime(): timeIpList = CONFIG.MASTERIP + CONFIG.NODEMACHINE timeIpList.append(CONFIG.DB_ENV_DIC['NEW_BOSS_DB_IP']) logging.info('start to sysnc time from timeserver.') for timeIp in timeIpList: tool.sshAndRun(['ntpdate -u 10.0.250.132'], timeIp) logging.info('sucess to sysnc time from timeserver.')
def scpRedisAndZkFile(ip): # 删除节点上原文件夹 cmdList = [] redisCmdStr = 'rm -rf /redis' zkconfigStr = 'rm -rf /platform-config' nginxDirStr = 'rm -rf /nginx' dubboStr = 'rm -rf /dubbo' swaggerStr = 'rm -rf /swagger' cmdList.append(redisCmdStr) cmdList.append(zkconfigStr) cmdList.append(nginxDirStr) cmdList.append(dubboStr) cmdList.append(swaggerStr) tool.sshAndRun(cmdList, ip) # 传送redis的新的文件到节点上 filePathList = [] uploadPathList = [] redisFilePath = '%s/redis' % CONFIG.ROOT_HOME redisUploadPath = '/' filePathList.append(redisFilePath) uploadPathList.append(redisUploadPath) tool.uploadViaSCP(filePathList, uploadPathList, ip) # 传送zk的新的配置到节点上 zkPathList = [] zkuploadPathList = [] zkFilePath = '%s/platform-config' % (CONFIG.ROOT_HOME + os.sep + 'zkconfig') zkUploadPath = '/' zkPathList.append(zkFilePath) zkuploadPathList.append(zkUploadPath) tool.uploadViaSCP(zkPathList, zkuploadPathList, ip) # 传送nginx文件到节点上 nginxDirPathList = [] nginxDiruploadPathList = [] nginxDirPath = CONFIG.ROOT_HOME + os.sep + 'nginx' nginxDiruploadPath = '/' nginxDirPathList.append(nginxDirPath) nginxDiruploadPathList.append(nginxDiruploadPath) tool.uploadViaSCP(nginxDirPathList, nginxDiruploadPathList, ip) # 传送dubbo文件到节点上 dubboDirPathList = [] dubboDiruploadPathList = [] dubboDirPath = CONFIG.ROOT_HOME + os.sep + 'dubbo' dubboDiruploadPath = '/' dubboDirPathList.append(dubboDirPath) dubboDiruploadPathList.append(dubboDiruploadPath) tool.uploadViaSCP(dubboDirPathList, dubboDiruploadPathList, ip) # 传送swagger文件到节点上 swaggerPathList = [] swaggeruploadPathList = [] swaggerPath = CONFIG.ROOT_HOME + os.sep + 'swagger' swaggeruploadPath = '/' swaggerPathList.append(swaggerPath) swaggeruploadPathList.append(swaggeruploadPath) tool.uploadViaSCP(swaggerPathList, swaggeruploadPathList, ip)
def restartService(): masterList = ['systemctl restart kube-apiserver.service', 'systemctl restart kube-controller-manager.service', 'systemctl restart kube-scheduler.service' ] nodeCmdList = ['systemctl restart flanneld.service', 'systemctl restart docker.service', 'systemctl restart kubelet.service', 'systemctl restart kube-proxy.service' ] # 重启master上的服务 tool.sshAndRun(masterList, CONFIG.MASTERIP[0]) logging.info("Services of Master restart over") # 重启Node上的服务 for ip in CONFIG.NODEMACHINE: for cmd in nodeCmdList: cmdList = [] if 'flanneld' in cmd: cmdList.append(cmd) tool.sshAndRun(cmdList, ip) logging.info('%s on %s has been restarted,please wait 10 seds' % ('flanneld.service', ip)) time.sleep(10) else: cmdList.append(cmd) tool.sshAndRun(cmdList, ip) logging.info("Services of Node:%s restart over" % ip)
def changeTimeByDateCmd(machineList, newTime): newTime = newTime + '.07' cmdStr = 'date %s' % newTime cmdList = [] cmdList.append(cmdStr) for machine in machineList: resTup = tool.sshAndRun(cmdList, machine) logging.info(' '.join(resTup[0][cmdStr])) if resTup[1][cmdStr]: logging.error(' '.join(resTup[1][cmdStr])) raise myException.MyException(' '.join(resTup[1][cmdStr])) logging.info("Time of node %s has been changed successfully." % machine)
def showTimeOfEveryMachine(masterIpList, nodeIpList): ipList = masterIpList + nodeIpList strList = [] for ipAddr in ipList: cmdList = [] cmdStr = 'date' cmdList.append(cmdStr) resTup = tool.sshAndRun(cmdList, ipAddr) res = ' '.join(resTup[0][cmdStr]) wholeRes = ('Time of %s' % ipAddr) + ":" + res strList.append(wholeRes) for infoStr in strList: logging.info(infoStr)
def changeMasterTime(newTime, masterIp): newTime = newTime + '.07' cmds = [] cmdStr = 'date %s' % newTime cmds.append(cmdStr) print "**************************" resTup = tool.sshAndRun(cmds, masterIp) print len(resTup[0][cmdStr]) logging.info(' '.join(resTup[0][cmdStr])) if resTup[1][cmdStr]: logging.error(' '.join(resTup[1][cmdStr])) raise myException.MyException(' '.join(resTup[1][cmdStr])) logging.info("Time of master %s has been changed successfully." % masterIp)
def syncTimeWithMater(nodeIpList, masterIp): for nodeIp in nodeIpList: cmdStrList = [] print masterIp print nodeIp cmdStr = 'ntpdate -u %s' % masterIp cmdStrList.append(cmdStr) print cmdStrList resTup = tool.sshAndRun(cmdStrList, nodeIp) logging.info(' '.join(resTup[0][cmdStr])) if resTup[1][cmdStr]: logging.error(' '.join(resTup[1][cmdStr])) raise myException.MyException(' '.join(resTup[1][cmdStr])) logging.info("Time of node %s has been changed successfully." % nodeIp)
def stopRedis(): masterStr = 'docker-compose -f %s/redismaster-compose.yml down' % ( CONFIG.NFS_HOST_DIR + os.sep + 'compose-yml') masterStrList = [] masterStrList.append(masterStr) masterResTup = tool.sshAndRun(masterStrList, CONFIG.NODEMACHINE[1], port=22, username='******', password='******') logging.info(masterResTup[0][masterStr]) logging.info(masterResTup[1][masterStr]) slaveStr = 'docker-compose -f %s/redisslave-compose.yml down' % ( CONFIG.NFS_HOST_DIR + os.sep + 'compose-yml') slaveStrList = [] slaveStrList.append(slaveStr) slaveResTup = tool.sshAndRun(slaveStrList, CONFIG.NODEMACHINE[2], port=22, username='******', password='******') logging.info(slaveResTup[0][slaveStr]) logging.info(slaveResTup[1][slaveStr]) sentinelStr = 'docker-compose -f %s/redissentinel-compose.yml down' % ( CONFIG.NFS_HOST_DIR + os.sep + 'compose-yml') sentinelStrList = [] sentinelStrList.append(sentinelStr) sentinelResTup = tool.sshAndRun(sentinelStrList, CONFIG.NODEMACHINE[0], port=22, username='******', password='******') logging.info(sentinelResTup[0][sentinelStr]) logging.info(sentinelResTup[1][sentinelStr])