Polysh命令实现多日志查询

一、Polysh简介

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

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

二、polysh安装

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

1.已安装python的安装
wget wget http://guichaz.free.fr/polysh/files/polysh-0.4.tar.gz
tar -zxvf polysh-0.4.tar.gz

vim prod-polysh.sh
脚本内容如下:
#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}

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

chmod 777 prod-polysh.sh
2.未安装python的安装
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
脚本内容如下:
#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}

开放给其他用户可执行的权限
chmod 777 prod-polysh.sh

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

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

四、polysh使用

4.1.使用方法一
polysh 10.252.176.33 10.252.176.35
4.2.使用方法二
./prod-polysh.sh

则会出现如下提示信息

[---hl-----]$ ./prod-polysh.sh
ready (8)

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

4.3.执行命令
ready (8)>cd /opt/hl
ready (8)>pwd

显示如下:

10.252.176.33: /opt/hl
10.252.176.35 : /opt/hl

五、源码

可以通过git获取polysh的源码

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

六、其他

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

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.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • linux资料总章2.1 1.0写的不好抱歉 但是2.0已经改了很多 但是错误还是无法避免 以后资料会慢慢更新 大...
    数据革命阅读 13,027评论 2 33
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,322评论 19 139
  • Ubuntu的发音 Ubuntu,源于非洲祖鲁人和科萨人的语言,发作 oo-boon-too 的音。了解发音是有意...
    萤火虫de梦阅读 100,328评论 9 468
  • # Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列...
    aimaile阅读 26,788评论 6 427
  • 我以为我已经痊愈,经过忙碌充实快乐的半天后。 上午J让我带她去旁听我听的那门课,没想到她还挺感兴趣。她的听力口...
    颜如苏阅读 274评论 0 0

友情链接更多精彩内容