clustershell批量執行shell命令

來源:互聯網
上載者:User

標籤:blank   target   二進位   

安裝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指明了組名;最後是批量執行的命令,將會在組下面所有節點執行該命令。

650) this.width=650;" title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6C/D1/wKiom1VSt-HyUyXWAAMaF05wp38910.jpg" "820" height="266" />

 

附錄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

clustershell批量執行shell命令

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.