之前工作在某銀行測試中心蹲點,蹲點的苦你懂的! 駐場就像蛀牙一樣會讓你疼痛無比,輾轉難眠,但是也能讓你有很好的環境和足夠的時間自學。
客戶環境有二十幾臺p770/570/560/8204-E8A 等IBM小機及幾臺HMC,91視頻,小機都是運行的VIOS虛擬化IO服務器系統,有三四百個分區, 每天有很多分區的創建和刪除,經常需要統計分區的:lpar_name、lpar_id 、cpu 、memory、oslevel、vscsi、vlan id、IP、lun\lun size、lun屬於哪臺存儲等等信息, 可想而知多麼悲劇, 剛開始一個一個profile點,一個一個分區登錄進去看,往往加班加點一兩個禮拜才能統計完三四百個分區的配置情況,兩個禮拜後可能又要統計更新這些信息。 後來實在忍無可忍了就惦記着寫腳本,經過一番折騰終於寫了個能用的腳本。
腳本運行原理: 建立一個lpar 客戶端分區,使用ssh與HMC及VIOS分區建立SSH信任關係,通過SSH在HMC及VIOS上撈需要的數據,
腳本運行前期工作:
1: 運行腳本主機必須安裝ssh客戶端
lslpp -l |grep open
2: 運行腳本主機必須與HMC建立SSH信任關係
在HMC上開啓允許遠程執行命令開關
在主機上
root@testlearn</.ssh>#ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (//.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in //.ssh/id_rsa.
Your public key has been saved in //.ssh/id_rsa.pub.
The key fingerprint is:
49:eb:6f:5c:91:d2:1b:b4:28:77:8b:eb:ef:52:8c:f0 root@testlearn
The key's randomart image is:
root@testlearn</.ssh>#feelkey=`cat id_rsa.pub`
root@testlearn</.ssh>#ssh hscroot@hmc230 mkauthkeys -a \"$feelkey\" #hmc230已經寫入了/etc/hosts文件
Password:
root@testlearn</.ssh>#ssh hscroot@hmc230 ls -l #搞定
drwxr-xr-x 4 root root 4096 2012-09-27 10:49 tmp
3:運行腳本主機必須必須與VIOS分區的root用戶建立ssh信任關係,hmcadmin用戶也可以
root@testlearn</.ssh>#touch authorized_keys
root@testlearn</.ssh>#cat id_rsa.pub >authorized_keys
root@testlearn</.ssh>#chmod 600 authorized_keys
VIOS分區:
# mkdir /.ssh
# cd /.ssh
#ssh-keygen -t rsa
#cat id_rsa.pub >authorized_keys.
#chmod 600 authorized_keys
#cat id_rsa.pub >authorized_keys
#scp authorized_keys xxx.xxx.xxx.xxx:/.ssh/authorized_keys_2
client分區
root@testlearn</.ssh>#cat authorized_keys_2 >> authorized_keys
root@testlearn</.ssh>#scp authorized_keys xxx.xxx.xxx.xxx:/.ssh/authorized_keys
運行腳本的時候只要輸入你的HMC地址,VIOS IP會自動從HMC獲取的到, 不想寫固定的HMC IP在腳本內,萬一將來還有VIOS環境這個腳本能拿來就用