小知识:Polysh命令实现多日志查询的方法示例

一、Polysh简介

Polysh 是一个交互式命令,可以在一台服务器上批量的对一批服务器进行处理,运行交互式命令。Polysh可以同时登录多个远程主机,而不需要通过relay一台一台的登录,并执行相同的指令,方便了问题的排查和定位,大大减少了我们的工作量。

?
1
Polysh is a tool to aggregate several remote shells into one. It is used to launch an interactive remote shell on many machines at once. It is written in Python and requires Python ≥ 2.4.

注: 官方解释:Polysh 是一个由几个远程脚本集合而成的工具,它被用于在许多服务器上运行一个交互式的远程脚本,由 Python 编写,最低要求为 Python 2.4 。

二、polysh安装

通过relay登录staging机器,执行如下命令安装polysh。安装目录为用户目录: /opt/hl/。

1.已安装python的安装

?
1
2
3
4
wget wget http://guichaz.free.fr/polysh/files/polysh-0.4.tar.gz
tar -zxvf polysh-0.4.tar.gz
vim prod-polysh.sh

脚本内容如下:

?
1
2
#10.252.176.33,10.252.176.35是你要链接的机器ip
python /opt/hl/polysh-0.4/polysh.py {10.252.176.33,10.252.176.35}

开放给其他用户可执行的权限

?
1
chmod 777 prod-polysh.sh

2.未安装python的安装

?
1
2
3
4
5
6
7
wget wget http://guichaz.free.fr/polysh/files/polysh-0.4.tar.gz
tar -zxvf polysh-0.4.tar.gz
cd polysh-0.4
su
python setup.py install
vim prod-polysh.sh

脚本内容如下:

?
1
2
#10.252.176.33,10.252.176.35是你要链接的机器ip
python /opt/hl/polysh-0.4/polysh.py {10.252.176.33,10.252.176.35}

开放给其他用户可执行的权限

?
1
chmod 777 prod-polysh.sh

三、Xshell配置Xagent(mac可跳过这一步)

打开文件-属性,选择SSH选项,选择”使用密码处理的Xagent(SSH代理)”。然后将Xshell重启。

四、polysh使用

4.1.使用方法一

?
1
polysh 10.252.176.33 10.252.176.35

4.2.使用方法二

?
1
./prod-polysh.sh

则会出现如下提示信息

?
1
2
[—hl—–]$ ./prod-polysh.sh
ready (8)

ready (8) 表示 8台机器已经连接完毕,可以执行查询命令。exit或Crtl+z都可以退出。

4.3.执行命令

?
1
2
ready (8)>cd /opt/hl
ready (8)>pwd

显示如下:

?
1
2
10.252.176.33: /opt/hl
10.252.176.35 : /opt/hl

五、源码

可以通过git获取polysh的源码

?
1
git clone git://repo.or.cz/polysh.git

六、其他

以冒号开头的指令不会发送到远程主机,polysh会执行以冒号开头的指令,例如:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
ready (2)> :help
:add Add one or many remote shells.
:chdir Change the current directory of polysh (not the remote shells).
:disable Disable sending commands to remote shells.
:enable Enable sending commands to remote shells.
:export_vars Export some environment variables on enabled remote shells.
:help List control commands or show their documentations.
:hide_password Do not echo the next typed line.
:list List remote shells and their states.
:purge Delete disabled remote shells.
:quit Quit polysh.
:reconnect Try to reconnect to disconnected remote shells.
:rename Rename all enabled remote shells with the argument.
:replicate Copy a path from one remote shell to all others
:reset_prompt Change the prompt to be recognized by polysh.
:send_ctrl Send a control character to remote shells.
:set_debug Enable or disable debugging output for remote shells.
:set_log Duplicate every console I/O into the given local file.
:show_read_buffer Print the data read by remote shells.
:upload Upload the specified local path to enabled remote shells.

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对服务器之家的支持。

原文链接:http://www.jianshu.com/p/2ed0ad5ccb3f

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:Nginx配置同一个域名同时支持http与https两种方式访问实现

2023-3-30 4:11:08

建站知识

小知识:利用Nginx代理如何解决前端跨域问题详析

2023-3-30 4:20:15

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索