华为开发者空间 远程给多台主机安装软件

远程给多台主机安装软件

案例1:在物理机上编写一个自动化批量管理服务器的脚本。要求用ssh命令远程给3台虚拟机全自动安装vsftpd、ftp、lftp、tree、samba、tftp-server、bind、dhcp、httpd、mariadb-server软件,用rpm -q查询软件是否已安装,全自动启动vsftpd、smb、rpcbind、nfs、mariadb服务。参考脚本一:vim aut...

案例1:在物理机上编写一个自动化批量管理服务器的脚本。要求用ssh命令远程给3台虚拟机全自动安装vsftpd、ftp、lftp、tree、samba、tftp-server、bind、dhcp、httpd、mariadb-server软件,用rpm  -q查询软件是否已安装,全自动启动vsftpd、smb、rpcbind、nfs、mariadb服务。

参考脚本一:

vim auto.sh

#!/bin/bash

IPS=192.168.10.

for I  in {6..9};do

(

ssh  root@${IPS}$I 'yum   install  -y   vsftpd   ftp  lftp   tree  samba  tftp-server   bind   dhcp  httpd   mariadb-server'

ssh  root@${IPS}$I 'rpm  -q   vsftpd   ftp   lftp   tree  samba   tftp-server  bind  dhcp  httpd   mariadb-server'

ssh  root@${IPS}$I  'systemctl   restart   vsftpd'

ssh  root@${IPS}$I  'systemctl   restart   smb'

ssh  root@${IPS}$I  'systemctl   restart   rpcbind'

ssh  root@${IPS}$I  'systemctl   restart   nfs'

ssh  root@${IPS}$I  'systemctl   restart   mariadb'

)&

done

wait


参考脚本二:先将需要安装的软件写到一个文件里,然后用scp传送到服务端

vim install.sh

#!/bin/bash

yum   install  -y   vsftpd   ftp  lftp   tree  samba  tftp-server   bind   dhcp  httpd   mariadb-server

rpm  -q   vsftpd   ftp   lftp   tree  samba   tftp-server  bind  dhcp  httpd   mariadb-server

systemctl   restart   vsftpd
systemctl   restart   smb
systemctl   restart   rpcbind
systemctl   restart   nfs
systemctl   restart   mariadb



vim scp.sh

#!/bin/bash

IPS=192.168.10.

for I in {6..9};do

(

scp  -r install.sh root@${IPS}$I:/opt/

ssh root@${IPS}$I 'bash /opt/install.sh'

)&

done

wait





转载于:https://blog.51cto.com/520yg/2044210

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐

  • 浏览量 1137
  • 收藏 0
  • 0

所有评论(0)

查看更多评论 
已为社区贡献6条内容