1. 程式人生 > >遠程給多臺主機安裝軟件

遠程給多臺主機安裝軟件

自動化

案例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





遠程給多臺主機安裝軟件