安装clustershell
从https://github.com/cea-hpc/clustershell/downloads下面源码或者二进制包进行安装。
下面以CentOS6.6使用rpm安装为例:
wget https://github.com/downloads/cea-hpc/clustershell/clustershell-1.5.1-1.el6.noarch.rpm
rpm -ivh clustershell-1.5.1-1.el6.noarch.rpm
源码安装方式:
wget https://github.com/downloads/cea-hpc/clustershell/clustershell-1.5.1.tar.gz
tar -xvf clustershell-1.5.1.tar.gz
cd clustershell-1.5.1
sudo python setup.py install
mkdir /etc/clustershell
cp conf/* /etc/clustershell
使用clustershell
首先,对于我们要管理的节点,创建一个组。假如我们需要管理的是10台web server,主机名分别为web1-web10,那么我们先创建一个文件/etc/clustershell/groups,内容如下:
web: web1 web2 web3 web4 web5 web6 web7 web8 web9 web10 |
其中:web是组名,web1-10是组下面的所有主机名。
接下来就可以使用clustershell批量执行命令了:
clush --user=root -g web "uptime" ### --user指明了ssh登录的用户;-g指明了组名;最后是批量执行的命令,将会在组下面所有节点执行该命令。
附录1:clustershell命令使用方法:
Usage: clush [options] command Options: --version show program‘s version number and exit -h, --help show this help message and exit -s GROUPSOURCE, --groupsource=GROUPSOURCE optional groups.conf(5) group source to use --nostdin don‘t watch for possible input from stdin Selecting target nodes: -w NODES nodes where to run the command -x EXCLUDE exclude nodes from the node list -a, --all run command on all nodes -g GROUP, --group=GROUP run command on a group of nodes -X EXGROUP exclude nodes from this group Output behaviour: -q, --quiet be quiet, print essential output only -v, --verbose be verbose, print informative messages -d, --debug output more messages for debugging purpose -G, --groupbase do not display group source prefix -L disable header block and order output by nodes -N disable labeling of command line -b, --dshbak gather nodes with same output -B like -b but including standard error -r, --regroup fold nodeset using node groups -S return the largest of command return codes --color=WHENCOLOR whether to use ANSI colors (never, always or auto) File copying: -c, --copy copy local file or directory to remote nodes --rcopy copy file or directory from remote nodes --dest=DEST_PATH destination file or directory on the nodes -p preserve modification times and modes Ssh options: -f FANOUT, --fanout=FANOUT use a specified fanout -l USER, --user=USER execute remote command as user -o OPTIONS, --options=OPTIONS can be used to give ssh options -t CONNECT_TIMEOUT, --connect_timeout=CONNECT_TIMEOUT limit time to connect to a node -u COMMAND_TIMEOUT, --command_timeout=COMMAND_TIMEOUT limit time for command to run on the node |