Clustershell 使用介绍

发布时间: 更新时间: 总字数:613 阅读时间:2m 作者: IP上海 分享 网址

ClusterShell 是一个事件驱动的开源 Python 库,旨在在服务器场或大型 Linux 集群上并行运行本地或远程命令。


  • clustershell 在 epel 源中
yum install -y clustershell
  • pip 安装
pip install ClusterShell


$ clush --help
Usage: clush [options] command

  --version             show program's version number and exit
  -h, --help            show this help message and exit
                        optional groups.conf(5) group source to use
  -n, --nostdin         don't watch for possible input from stdin
  --groupsconf=FILE     use alternate config file for groups.conf(5)
  --conf=FILE           use alternate config file for clush.conf(5)
  -O KEY=VALUE, --option=KEY=VALUE
                        override any key=value clush.conf(5) options

  Selecting target nodes:
    -w NODES            nodes where to run the command
    -x NODES            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 GROUP            exclude nodes from this group
    --hostfile=FILE, --machinefile=FILE
                        path to file containing a list of target hosts
    --topology=FILE     topology configuration file to use for tree mode
    --pick=N            pick N node(s) at random in nodeset

  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
    -P, --progress      show progress during command execution
    -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)
    --diff              show diff between gathered outputs

  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

  Connection 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
    -R WORKER, --worker=WORKER
                        worker name to use for command execution ('exec',
                        'rsh', 'ssh', etc. default is 'ssh')
    --remote=REMOTE     whether to enable remote execution: in tree mode,
                        'yes' forces connections to the leaf nodes for
                        execution, 'no' establishes connections up to the leaf
                        parent nodes for execution (default is 'yes')


使用前提是配置无密码登录,或使用 sshpass。更多配置参考:/etc/clustershell/clush.conf

group 配置参考:

$ cat /etc/clustershell/groups.d/local.cfg
# ClusterShell groups config local.cfg
# Replace /etc/clustershell/groups
# Note: file auto-loaded unless /etc/clustershell/groups is present
# See also groups.d/cluster.yaml.example for an example of multiple
# sources single flat file setup using YAML syntax.
# Feel free to edit to fit your needs.
adm: example0
oss: example4 example5
mds: example6
io: example[4-6]
compute: example[32-159]
gpu: example[156-159]
all: example[4-6,32-159]


# group
clush -g adm date

# 指定节点
clush -w 192.168.0.[2,3] date
clush -w c[01-10] date
clush -w c[01-10] -x c02 date  # 排除 c02
clush -w c[01-10] -l test date  # 使用test用户执行

# 批处理模式
clush -w, -b


Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数