转自:http://blog.csdn.net/napolunyishi/article/details/18219867

这两天做了一个需求,因为上一个版本的/tmp空间默认只分配了5G,而升级程序上传解压路径也是/tmp,且解压过程要占用5G左右的空间,这样 就导致/tmp空间占满,解压失败,升级无法进行。后来想了一个办法,就是从/var建了一个软链接到/tmp,这样实际上升级文件上传解压到/var路 径下了,解决了/tmp路径空间不足的问题。但是因为客户那里是一个cluster环境,由6个node组成,最好能够在一个机器上执行一次补丁,所有 node都生效。

经过几次尝试,写了两个shell脚本,一个run.sh负责调度和分发补丁,另外一个doFix.sh,真正给系统打补丁的脚本。这里只介绍调度分发的部分

基本思路就是从主node上将doFix.sh脚本分发到其他各个node上,然后再从主node上ssh到各node执行补丁脚本。

调度脚本run.sh:

    #!/bin/bash  

    #check version
cat /etc/issue | grep "V3.5"
if [ $? -ne ]; then
echo "This is not V3.5, exit!"
exit
fi ISFABRIC=
ADMPW="" echo read -rsn1 -p "Is this a fabric with same admin password? [y/n]"
echo
if [ "$REPLY" = "y" -o "$REPLY" = "Y" ]; then
ISFABRIC=
read -esp "Please input the password: " ADMPW
else
echo "Please run the script doFix.sh manually"
exit
fi
echo
echo echo "Patch current node..."
sh ./doFix.sh NODEIP=$(ifconfig eth0 | grep 'inet addr' | cut -d':' -f2 | awk '{print $1}') echo "Begin to patch other nodes..."
echo egrep "MAGICNODE-" /etc/hosts | awk '{print $1}' | sort | uniq | while read LINE
do
if [ "$NODEIP" = "$LINE" ]; then
continue
fi echo "Patching node $LINE"
# scp doFix.sh to remote node
./scpExpect $ADMPW./doFix.sh admin@$LINE:/tmp/
if [ $? -ne ]; then
echo "SCP script to node $LINE failed! skip"
continue
fi # execute patch script
./sshExpectSudo admin $ADMPW $LINE "sudo bash /tmp/doFix.sh"
if [ $? -ne ]; then
echo "Remote patch node $LINE failed! skip"
continue
fi
echo
echo
done echo "Patch finished."

从/etc/hosts文件中获取cluster环境的所有node IP,然后将doFix.sh脚本通过scp送过去,再执行ssh打补丁。

这里两个关键点是scpExpect和sshExpect,何为Expect文件?请参考http://expect.sourceforge.net/,网上有很多Expect的介绍文章,归结一句话就是一种实现自动化交互的脚本语言,从TCL扩展出来。

scpExpect

    #!/usr/bin/expect -f
# usage: scpExpect user password ip file target system "rm -rf ~/.ssh/known_hosts"
set password [lindex $argv ]
set from [lindex $argv ]
set to [lindex $argv ]
set timeout # now connect to remote UNIX box (ipaddr) with given script to execute
spawn scp -r -o StrictHostKeyChecking=no $from $to
match_max
expect {
"*assword:*" {
send -- "$password\r"
set timeout -
expect {
"*assword:*" {
exit
}
}
} "yes/no)?" {
send "yes\r"
set timeout -
} -re . {
exp_continue
} timeout {
exit
} eof {
exit
}
}

sshExpect

#!/usr/bin/expect -f
# usage: ssh user password ipaddre command target
# set Variables
set user [lrange $argv ]
set password [lrange $argv ]
set ipaddr [lrange $argv ]
set command [lrange $argv ]
set target [lrange $argv ]
set timeout - # now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh -o StrictHostKeyChecking=no $user@$ipaddr $command $target
match_max
# Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof

Linux Cluster环境下批量分发执行补丁的更多相关文章

  1. PHP 命令行模式实战之cli+mysql 模拟队列批量发送邮件(在Linux环境下PHP 异步执行脚本发送事件通知消息实际案例)

    源码地址:https://github.com/Tinywan/PHP_Experience 测试环境配置: 环境:Windows 7系统 .PHP7.0.Apache服务器 PHP框架:ThinkP ...

  2. Linux单机环境下HDFS伪分布式集群安装操作步骤v1.0

    公司平台的分布式文件系统基于Hadoop HDFS技术构建,为开发人员学习及后续项目中Hadoop HDFS相关操作提供技术参考特编写此文档.本文档描述了Linux单机环境下Hadoop HDFS伪分 ...

  3. Linux centos7环境下安装MySQL的步骤详解

    Linux centos7环境下安装MySQL的步骤详解 安装MySQL mysql 有两个跟windows不同的地方 1).my.ini 保存到/etc/my.ini 2).用户权限,单独用户执行 ...

  4. Centos 7(Linux)环境下安装PHP(编译添加)相应动态扩展模块so(以openssl.so为例)

    https://blog.csdn.net/shinesun001/article/details/54312402 在centos 7环境下搭建好Lnmp环境之后,发现安装的php有好多扩展都没有安 ...

  5. linux centos7环境下安装apache2.4+php5.6+mysql5.6 安装及踩坑集锦

    linux centos7环境下安装apache2.4+php5.6+mysql5.6 安装及踩坑集锦(一) 一.Linux下安装MySQL 1.下载 下载地址:http://dev.mysql.co ...

  6. 在 Windows 和 Linux(Gnome) 环境下 从命令界面打开网页的方式

    1.在 Windows 中 通过命令 可以打开网页是很简单的: start http://www.baidu.com 或 start iexplorer http://www.baidu.com 第二 ...

  7. linux网络环境下socket套接字编程(UDP文件传输)

    今天我们来介绍一下在linux网络环境下使用socket套接字实现两个进程下文件的上传,下载,和退出操作! 在socket套接字编程中,我们当然可以基于TCP的传输协议来进行传输,但是在文件的传输中, ...

  8. 如何在Linux桌面环境下自动启动程序?

    大多数Linux桌面环境有各自的图形用户界面(GUI),让用户可以配置针对特定用户的自动启动程序或服务.本文将介绍如何在各种Linux桌面环境下,自动启动某个程序的方法. AD:WOT2014:用户标 ...

  9. Linux centos7环境下安装JDK的步骤详解

    Linux centos7环境下安装JDK的步骤详解 测试root用户下JAVA版本 输入命令:   java –version 1.先到Oracle官网里下载好jdk,网址如下: http://ww ...

随机推荐

  1. 2018.09.15 秘密的牛奶管道SECRET(次小生成树)

    描述 约翰叔叔希望能够廉价连接他的供水系统,但是他不希望他的竞争对手知道他选择的路线.一般这样的问题需要选择最便宜的方式,所以他决定避免这种情况而采用第二便宜的方式. 现在有W(3 <= W & ...

  2. 【C#】VS2015开发环境的安装和配置(转)

    出处: http://www.cnblogs.com/rainmj/p/5636518.html http://www.cnblogs.com/rainmj/p/5636529.html http:/ ...

  3. 【Unity】2.1 初识Unity编辑器

    分类:Unity.C#.VS2015 创建日期:2016-03-26 一.简介 本节要点:了解Unity编辑器的菜单和视图界面,以及最基本的操作,这是入门的最基础部分,必须掌握. 二.启动界面 双击桌 ...

  4. 使用ntpdate校正linux系统的时间

    当Linux服务器的时间不对的时候,可以使用ntpdate工具来校正时间. 安装:yum install ntpdate ntpdate简单用法: # ntpdate ip # ntpdate 210 ...

  5. org.hibernate.HibernateException: /hibernate.cfg.xml not found等三个问题

    初次配置hibernate在myeclipse上: 出现三个问题,怎么都不好使,比对代码,没有问题,查看路径还是没有问题: 1.org.hibernate.HibernateException: /h ...

  6. js继承——扩展Object方式实现继承

    function Parent(name,sex){ this.name = name; this.sex = sex; this.sayName = function(){ console.log( ...

  7. 有关在 Word 中撰写博客的帮助

    目前大部分的博客作者在用Word写博客这件事情上都会遇到以下3个痛点: 1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.使用Word写 ...

  8. spring boot docker 初尝试

    Docker服务中进程间通信通过/var/run/docker.sock实现,默认服务不提供监听端口,因此使用docker remote api 需要手动绑定端口. 在centos7.2下,可以进行这 ...

  9. faceswap安装说明

    Installing Faceswap Installing Faceswap Prerequisites Hardware Requirements Supported operating syst ...

  10. c# Clipboard.SetDataObject(bmp1) 在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记。 只有将调试器附加到该进程才会引发此异常

    c# Clipboard.SetDataObject(bmp1)  在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式.请确保您的 Main 函数带有 STAThreadAttri ...