SSH批量部署服務

来源:http://www.cnblogs.com/hackerer/archive/2016/03/06/5248803.html
-Advertisement-
Play Games

SSH批量部署服務 1.1在NFS上作為中心分發伺服器將私鑰分發到其他伺服器上 1.1.1NFS部署 1 [root@nfs-server ~]# useradd zhurui 2 [root@nfs-server ~]# echo 123456|passwd --stdin zhurui 3 Ch


SSH批量部署服務

1.1在NFS上作為中心分發伺服器將私鑰分發到其他伺服器上

1.1.1NFS部署

 

 1 [root@nfs-server ~]# useradd zhurui
 2 [root@nfs-server ~]# echo 123456|passwd --stdin zhurui
 3 Changing password for user zhurui.
 4 passwd: all authentication tokens updated successfully.
 5 創建密碼對:
 6 [root@nfs-server ~]# su - zhurui     ##切換到zhurui用戶下,以後批量分發都在當前用戶下,安全考慮
 7 [zhurui@nfs-server ~]$ ssh-keygen -t dsa ##ssh-keygen是生成秘鑰的工具,-t參數指建立秘鑰的類型,這裡建立dsa類型秘鑰(還有一種類型的秘鑰為RSA,兩者加密演算法有區別)
 8 Generating public/private dsa key pair.
 9 Enter file in which to save the key (/home/zhurui/.ssh/id_dsa): 
10 Created directory '/home/zhurui/.ssh'.
11 Enter passphrase (empty for no passphrase): 
12 Enter same passphrase again: 
13 Your identification has been saved in /home/zhurui/.ssh/id_dsa.
14 Your public key has been saved in /home/zhurui/.ssh/id_dsa.pub.
15 The key fingerprint is:
16 6f:65:c4:a6:fb:32:45:0c:85:c3:bc:87:8f:a4:ae:bc zhurui@nfs-server
17 The key's randomart image is:
18 +--[ DSA 1024]----+
19 |         o o.    |
20 |          *.     |
21 |           *+    |
22 |          +++    |
23 |        So.=o    |
24 |        ...+o    |
25 |       .  +.     |
26 |     .  ..o.     |
27 |      Eo   o.    |
28 +-----------------+
29 [zhurui@nfs-server ~]$ 
30 [zhurui@nfs-server ~]$ ls -l .ssh/
31 total 8
32 -rw-------. 1 zhurui zhurui 672 Mar  5 04:23 id_dsa   ##私鑰
33 -rw-r--r--. 1 zhurui zhurui 607 Mar  5 04:23 id_dsa.pub  ##公鑰
34 將公鑰分發給web-lamp01伺服器
35 [zhurui@nfs-server ~]$ ssh-copy-id -i .ssh/id_dsa.pub [email protected]  ##將公鑰分發給1.12伺服器
36 The authenticity of host '192.168.1.12 (192.168.1.12)' can't be established.
37 RSA key fingerprint is d6:e6:e6:2a:c7:df:99:51:bb:f4:90:29:16:df:c4:a5.
38 Are you sure you want to continue connecting (yes/no)? yes
39 Warning: Permanently added '192.168.1.12' (RSA) to the list of known hosts.
40 Nasty PTR record "192.168.1.12" is set up for 192.168.1.12, ignoring
41 [email protected]'s password: 
42 Permission denied, please try again.
43 [email protected]'s password: 
44 Now try logging into the machine, with "ssh '[email protected]'", and check in:
45 
46   .ssh/authorized_keys
47 
48 to make sure we haven't added extra keys that you weren't expecting.
49 
50 [zhurui@nfs-server ~]$ 

 

1.1.2 web-lnmp02客戶端分發部署

 1 [zhurui@nfs-server ~]$ ssh-copy-id -i .ssh/id_dsa.pub [email protected]  ##將公鑰分發到1.13伺服器
 2 The authenticity of host '192.168.1.13 (192.168.1.13)' can't be established.
 3 RSA key fingerprint is d6:e6:e6:2a:c7:df:99:51:bb:f4:90:29:16:df:c4:a5.
 4 Are you sure you want to continue connecting (yes/no)? yes
 5 Warning: Permanently added '192.168.1.13' (RSA) to the list of known hosts.
 6 Nasty PTR record "192.168.1.13" is set up for 192.168.1.13, ignoring
 7 [email protected]'s password: 
 8 Now try logging into the machine, with "ssh '[email protected]'", and check in:
 9 
10   .ssh/authorized_keys
11 
12 to make sure we haven't added extra keys that you weren't expecting.
13 
14 [zhurui@nfs-server ~]$ 

1.1.3 rsync-backup客戶端分發部署

 

 1 [zhurui@nfs-server ~]$ ssh-copy-id -i .ssh/id_dsa.pub [email protected]
 2 The authenticity of host '192.168.1.17 (192.168.1.17)' can't be established.
 3 RSA key fingerprint is d6:e6:e6:2a:c7:df:99:51:bb:f4:90:29:16:df:c4:a5.
 4 Are you sure you want to continue connecting (yes/no)? yes
 5 Warning: Permanently added '192.168.1.17' (RSA) to the list of known hosts.
 6 [email protected]'s password: 
 7 Now try logging into the machine, with "ssh '[email protected]'", and check in:
 8 
 9   .ssh/authorized_keys
10 
11 to make sure we haven't added extra keys that you weren't expecting.
12 
13 [zhurui@nfs-server ~]$ 

 

2.1在NFS上測試

2.1.1 通過ssh命令在當前機器上查看web-lamp01的IP地址

 

 1 [zhurui@nfs-server ~]$ ssh -P22 [email protected] /sbin/ifconfig eth0
 2 eth0      Link encap:Ethernet  HWaddr 00:0C:29:49:CE:B3  
 3           inet addr:192.168.1.12  Bcast:192.168.1.255  Mask:255.255.255.0
 4           inet6 addr: fe80::20c:29ff:fe49:ceb3/64 Scope:Link
 5           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 6           RX packets:7701 errors:0 dropped:0 overruns:0 frame:0
 7           TX packets:4795 errors:0 dropped:0 overruns:0 carrier:0
 8           collisions:0 txqueuelen:1000 
 9           RX bytes:4806676 (4.5 MiB)  TX bytes:484902 (473.5 KiB)
10 註:在命令執行過程中,跳過輸入密碼的步驟
11 接著分發文件測試:
12 [zhurui@nfs-server ~]$ cp /etc/hosts
13 hosts        hosts.allow  hosts.deny   
14 [zhurui@nfs-server ~]$ cp /etc/hosts .
15 [zhurui@nfs-server ~]$ ll
16 [zhurui@nfs-server ~]$ scp -P22 hosts [email protected]:~ ##將當前目錄下hosts文件分發到1.12家目錄下
17 hosts                                          100%  243     0.2KB/s   00:00    
18 [zhurui@nfs-server ~]$ 
19 
20 檢查1.12上zhurui家目錄下有無hosts文件
21 [root@lamp01 zhurui]# cat /home/zhurui/hosts 
22 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 
23 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
24 192.168.1.11 nfs-server
25 192.168.1.17 backup
26 192.168.1.12 lamp01
27 192.168.1.13 lnmp02
28 [root@lamp01 zhurui]# 
29 通過腳本分發:
30 [zhurui@nfs-server ~]$ sh fenfa.sh
31 hosts                                          100%  257     0.3KB/s   00:00    
32 hosts                                          100%  257     0.3KB/s   00:00    
33 hosts                                          100%  257     0.3KB/s   00:00  
34   

 

批量管理腳本:

 

 1 #!/bin/sh
 2 . /etc/init.d/functions
 3 if [ $# -ne 1 ]
 4    then
 5     echo "USAGE:$0 USAGE|COMMAND"
 6     exit 1
 7 fi
 8 for n in 12 13 17
 9 do
10   ssh -p22 [email protected].$n $1
11 done
12 
13 ~         

 

 

 

批量分發腳本:

 

 1 #!/bin/sh
 2 . /etc/init.d/functions
 3 
 4 for n in 12 13 17
 5 do
 6   scp -P22 $1 [email protected].$n:~ &>/dev/null
 7   if [ $? -eq 0 ]
 8     then
 9       action "fenfa $1 ok" /bin/true
10     else
11       action "fenfa $1 ok" /bin/false
12   fi
13 done
14 
15 ~     

 

利用分發腳本分發hosts文件

 

1 [zhurui@nfs-server ~]$ sh fenfa.sh hosts
2 fenfa hosts ok                                             [  OK  ]
3 fenfa hosts ok                                             [  OK  ]
4 fenfa hosts ok                                             [  OK  ]
5 [zhurui@nfs-server ~]$ 

 

優化後的分發腳本

 

 1 #!/bin/sh
 2 . /etc/init.d/functions
 3 if [ $# -ne 1 ]
 4    then
 5     echo "USAGE:$0 {FILENAME|DIRNAME}"
 6     exit 1
 7 fi
 8 for n in 12 13 17
 9 do
10   scp -P22 -r $1 [email protected].$n:~ &>/dev/null
11   if [ $? -eq 0 ]
12     then
13       action "fenfa $1 ok" /bin/true
14     else
15       action "fenfa $1 ok" /bin/false
16   fi
17 done

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • ubuntu 修改網卡名稱 更改設備網卡名稱 修改eno16777736為eth0 ubuntu 15.10網卡名稱為eno16777736 linux 網卡名字為eno16777736怎麼辦
  • 博客園(FOREVER_ENJOY):http://www.cnblogs.com/zyx1314/ 本文版權歸作者所有;歡迎轉載!請註明文章作者和原文連接 Linux各個目錄的結構介紹 Linux系統以目錄的方式來組織和管理系統中的所有文件。Linux系統通過目錄將系統中的所有的文件分級、分層組織...
  • ARM的指令系統中關於棧指令的內容比較容易引起迷惑,這是因為準確描述一個棧的特點需要兩個參數: 棧地址的增長方向 :ARM將向高地址增長的棧稱為 遞增棧 (Descendent Stack),將向低地址增長的棧稱為 遞減棧 (Acendant Stack) 棧指針的指向位置 :ARM將棧指針指向棧頂
  • Arduino控制LCD屏幕顯示出helloworld字元串基本知識及其軟硬體設計
  • pstack命令用來顯示進程的棧跟蹤。 pstack 命令必須由相應進程的屬主或root賬號運行。可以使用pstack來確定進程掛起的位置。此命令只有一個參數,那就是pid,具體關於pstack的介紹可以查看man手冊,如下所示: [root@DB-Server ~]# man pstackPSTA...
  • 一、USB設備描述結構 1.邏輯組織結構 在USB設備的邏輯組織中,包含設備、配置、介面和端點4個層次。設備通常有一個或多個配置,配置通常有一個或多個介面,介面有零或多個端點。 每個USB設備都可以包含一個或多個配置,不同的配置使設備表現出不同的功能組合,配置由多個介面組成。在USB協議中,介面代表
  • vm12 安裝ubuntu15.10詳細圖文教程 虛擬機安裝ubuntu安裝 ubuntu更新軟體 ubuntu一直卡在下載語言怎麼辦 官網下載ubuntu 下載ubuntu鏡像文件 虛擬機安裝ubuntu如何設置處理器配置 虛擬機安裝ubuntu 記憶體多大合適 ubuntu更新軟體 ubuntu...
  • RPM包安裝wget http://down.wdlinux.cn/in/lanmp_wdcp_ins.shsh lanmp_wdcp_ins.sh就可以RPM包安裝支持系統:CentOS 5.X/wdlinux_base 5.X/wdOS 1.0,CentOS 6.X ,32位,64位均支持卸載 
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...