概述
运维人员往往会头疼,要在10多台服务器上去执行同样的操作。
在linux下有一款这样的工具(pssh),解决了这个问题。
这款工具的几个主要功能:
pssh 在多个主机上并行地运行命令。
pscp 把文件并行地复制到多个主机上。
prsync 通过 rsync 协议把文件高效地并行复制到多个主机上。
pslurp 把文件并行地从多个远程主机复制到中心主机上。
pnuke 并行地在多个远程主机上杀死进程。
--
1:安装
wget http://parallel-ssh.googlecode.com/files/pssh-2.2.2.tar.gz
tar zxvf pssh-2.2.2.tar.gz
cd pssh-2.2.2
python setup.py install
---
2.配置密钥,免密码访问管理机器
在使用之前需要配置密钥访问,如下:
#ssh-keygen 【回车】
#复制公钥到远端服务器
#ssh-copy-id -i .ssh/id_rsa.pub root@192.168.16.X
ps.如果端口不是默认22 ,需要使用:ssh-copy-id -i .ssh/id_rsa.pub ”-p 4567 yin@192.168.16.X”
编辑 服务器列表文件 servers.txt
# vim /home/server.txt
root@183.62.138.82:22031
hosts file (each line "[user@]host[:port]")
3:运行第一条命令,查看启动时间
]# pssh -h servers.txt -l root -P uptime
173.16.0.102: 13:14:57 up 1 day, 2:00, 1 user, load average: 0.00, 0.00, 0.00
173.16.0.100: 13:23:34 up 21:40, 1 user, load average: 0.00, 0.00, 0.00
[1] 13:13:52 [SUCCESS] 173.16.0.102
[2] 13:13:52 [SUCCESS] 173.16.0.100
4:删除文件
我需要删除以前yum.repo 文件
pssh -h servers.txt -P "rm -r /etc/yum.repos.d/*.repo"
5:传输单个文件
pscp -h servers.txt /etc/yum.repos.d/ftp.repo /etc/yum.repos.d/
6:运行yum update
]# pssh -h servers.txt -l root -P "yum update"
173.16.0.100: Loaded plugins: fastestmirror
173.16.0.102: Loaded plugins: fastestmirror
173.16.0.100: Loading mirror speeds from cached hostfile
173.16.0.102: Loading mirror speeds from cached hostfile
173.16.0.100: Setting up Update Process
173.16.0.102: Setting up Update Process
173.16.0.100: No Packages marked for Update
173.16.0.102: No Packages marked for Update
[1] 13:38:13 [SUCCESS] 173.16.0.100
[2] 13:38:13 [SUCCESS] 173.16.0.102
7:让机器加载Ext4
]# pssh -h servers.txt -l root -P "modprobe ext4"
[1] 13:49:42 [SUCCESS] 173.16.0.100
[2] 13:49:42 [SUCCESS] 173.16.0.102
8:安装e4fsprogs, 支持ext4分区
[root@gluster02b ~]# pssh -h servers.txt -l root -P "yum -y install e4fsprogs"
173.16.0.102: Loaded plugins: fastestmirror
173.16.0.100: Loaded plugins: fastestmirror
173.16.0.100: Complete!
[1] 13:53:11 [SUCCESS] 173.16.0.100
173.16.0.102:
Installed:
e4fsprogs.x86_64 0:1.41.12-2.el5
173.16.0.102: Complete!
[2] 13:53:11 [SUCCESS] 173.16.0.102
9:创建一个目录
# pssh -h servers.txt -l root -P "mkdir /data01"
[1] 09:53:27 [SUCCESS] 173.16.0.100
[2] 09:53:27 [SUCCESS] 173.16.0.102
# pscp -h servers.txt /etc/fstab /etc/
[1] 09:53:51 [SUCCESS] 173.16.0.102
[2] 09:53:51 [SUCCESS] 173.16.0.100
10:复制文件夹到远程
# pscp -h servers.txt -r /root/tools/ /root/
[1] 10:23:27 [SUCCESS] 173.16.0.100
[2] 10:23:28 [SUCCESS] 173.16.0.102
11:关闭Selinux
# pssh -h servers.txt -l root -P "sed -i '/SELINUX=enforcing/s/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux"
[1] 11:47:15 [SUCCESS] 173.16.0.100
[2] 11:47:15 [SUCCESS] 173.16.0.102
# pssh -h servers.txt -l root -P init 6
[1] 11:47:28 [SUCCESS] 173.16.0.102
[2] 11:47:28 [SUCCESS] 173.16.0.100
# pssh -h servers.txt -l root -P sestatus
[1] 11:49:37 [FAILURE] 173.16.0.100 Exited with error code 255
[2] 11:49:37 [FAILURE] 173.16.0.102 Exited with error code 255
# pssh -h servers.txt -l root -P sestatus
173.16.0.100: SELinux status: disabled
[1] 11:52:32 [SUCCESS] 173.16.0.100
173.16.0.102: SELinux status: disabled
[2] 11:52:32 [SUCCESS] 173.16.0.102
http://sheriy.com/?p=748
http://www.theether.org/pssh/docs/0.2.3/pssh-HOWTO.html
转载于:https://blog.51cto.com/chensanxin/1236091
最后
以上就是激昂小刺猬为你收集整理的通过pssh同时管理多台服务器,批量管理服务器的全部内容,希望文章能够帮你解决通过pssh同时管理多台服务器,批量管理服务器所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复