2019-04-21 11:50:48 +08:00

69 lines
3.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1 id="pssh">pssh</h1>
<p>批量管理执行</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>pssh命令</strong> 是一个python编写可以在多台服务器上执行命令的工具同时支持拷贝文件是同类工具中很出色的类似pdsh个人认为相对pdsh更为简便使用必须在各个服务器上配置好密钥认证访问。</p>
<h3 id="安装pssh">安装pssh</h3>
<p>在CentOS系统环境下介绍yum的安装和源码安装的方式</p>
<p><strong>yum方法</strong></p>
<pre><code class="language-bash">yum install pssh</code></pre>
<p><strong>编译安装</strong></p>
<pre><code class="language-bash">wget http://parallel-ssh.googlecode.com/files/pssh-2.3.1.tar.gz
tar xf pssh-2.3.1.tar.gz
cd pssh-2.3.1/
python setup.py install</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">--version查看版本
--help查看帮助即此信息
-h主机文件列表内容格式”[user@]host[:port]”
-H主机字符串内容格式”[user@]host[:port]”
-:登录使用的用户名
-p并发的线程数【可选】
-o输出的文件目录【可选】
-e错误输入文件【可选】
-tTIMEOUT 超时时间设置0无限制【可选】
-OSSH的选项
-v详细模式
-A手动输入密码模式
-x额外的命令行参数使用空白符号引号反斜线处理
-X额外的命令行参数单个参数模式同-x
-i每个服务器内部处理信息输出
-P打印出服务器返回信息</code></pre>
<h3 id="实例">实例</h3>
<p>获取每台服务器的uptime</p>
<pre><code class="language-bash"># pssh -h ip.txt -i uptime
[1] 11:15:03 [SUCCESS] Mar.mars.he
11:15:11 up 4 days, 16:25, 1 user, load average: 0.00, 0.00, 0.00
[2] 11:15:03 [SUCCESS] Jan.mars.he
11:15:12 up 3 days, 23:26, 0 users, load average: 0.00, 0.00, 0.00
[3] 11:15:03 [SUCCESS] Feb.mars.he
11:15:12 up 4 days, 16:26, 2 users, load average: 0.08, 0.02, 0.01</code></pre>
<p>查看每台服务器上mysql复制IO/SQL线程运行状态信息</p>
<pre><code class="language-bash"># pssh -h IP.txt -i &quot;/usr/local/mysql/bin/mysql -e &#39;show slave status \G&#39;&quot;|grep Running:
Slave_IO_Running: yes
Slave_SQL_Running: Yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes</code></pre>
<p>保存每台服务器运行的结果:</p>
<pre><code class="language-bash"># pssh -h IP.txt -i -o /tmp/pssh/ uptime
[1] 11:19:47 [SUCCESS] Feb.mars.he
11:19:55 up 4 days, 16:31, 2 users, load average: 0.02, 0.03, 0.00
[2] 11:19:47 [SUCCESS] Jan.mars.he
11:19:56 up 3 days, 23:30, 0 users, load average: 0.01, 0.00, 0.00
[3] 11:19:47 [SUCCESS] Mar.mars.he
11:19:56 up 4 days, 16:30, 1 user, load average: 0.00, 0.00, 0.00</code></pre>
<p>我们来看一下/tmp/pssh/下的文件及其内容</p>
<pre><code class="language-bash"># ll /tmp/pssh/
总用量 12
-rw-r--r--. 1 root root 70 12月 1 11:19 Feb.mars.he
-rw-r--r--. 1 root root 70 12月 1 11:19 Jan.mars.he
-rw-r--r--. 1 root root 69 12月 1 11:19 Mar.mars.he
# cat /tmp/pssh/*
11:19:55 up 4 days, 16:31, 2 users, load average: 0.02, 0.03, 0.00
11:19:56 up 3 days, 23:30, 0 users, load average: 0.01, 0.00, 0.00
11:19:56 up 4 days, 16:30, 1 user, load average: 0.00, 0.00, 0.00</code></pre>
<p>上面介绍的是pssh命令很少的一部分大家可以将其用到适合自己的场景发挥它的最大功效。</p>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->