Linux Shell脚本专栏_监控100台服务器磁盘利用率脚本_07
生活随笔
收集整理的這篇文章主要介紹了
Linux Shell脚本专栏_监控100台服务器磁盘利用率脚本_07
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 監控100臺服務器磁盤利用率腳本
- 1. 遠程連接生成sshkey
- 2. 復制ssh公鑰到目標服務器
- 3. 登錄目標服務器查看
- 4. 私鑰免登錄
- 5. 192.168.43.134 服務器創建host,info文件
- 6. 編輯腳本
- 7. 賦予可執行權限
- 8. 運行腳本
- 9. 命令分解
監控100臺服務器磁盤利用率腳本
1. df -h 查看磁盤占有2. 遠程連接1. 遠程連接生成sshkey
[root@localhost ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:oqRrNpiEGm/lvN6Nark2VQHckCk56Egda/RVeG1J+qc root@localhost.localdoma The key's randomart image is: +---[RSA 2048]----+ | .+.ooBo.o.. | | .o.* =.o..+ | |.o o + .o. | |. o . . | |. . ..S . . | |o. o.... o | |o=.+.o E | |+ *.B. o | | +.===o . | +----[SHA256]-----+ [root@localhost ~]#2. 復制ssh公鑰到目標服務器
[root@localhost ~]# ssh-copy-id root@192.168.43.228 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host '192.168.43.228 (192.168.43.228)' can't be established. ECDSA key fingerprint is SHA256:FXF2nnf+x1mP2M662486Z/51fjmcwfE23S2Pewwlxx8. ECDSA key fingerprint is MD5:c0:cb:5f:3f:ba:3a:b4:2b:73:47:7b:59:d1:79:94:17. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@192.168.43.228's password: Number of key(s) added: 1Now try logging into the machine, with: "ssh 'root@192.168.43.228'" and check to make sure that only the key(s) you wanted were added.3. 登錄目標服務器查看
192.168.43.228
[root@localhost ~]# ls -a . anaconda-ks.cfg .bash_profile .cshrc .tcshrc .. .bash_logout .bashrc .ssh .viminfo [root@localhost ~]# cd .ssh/ [root@localhost .ssh]# ll total 4 -rw------- 1 root root 408 Feb 24 21:16 authorized_keys [root@localhost .ssh]#4. 私鑰免登錄
192.168.43.134 服務器通過私鑰免交互登錄目標服務器(192.168.43.228)
[root@localhost ~]# ssh -i .ssh/id_rsa root@192.168.43.228 Last login: Mon Feb 24 21:20:34 2020 from 192.168.43.134 [root@localhost ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.43.228 netmask 255.255.255.0 broadcast 192.168.43.255inet6 fe80::2df:a3c9:3a0d:ed24 prefixlen 64 scopeid 0x20<link>ether 00:0c:29:07:3f:59 txqueuelen 1000 (Ethernet)RX packets 1602 bytes 151986 (148.4 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 1035 bytes 140376 (137.0 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1000 (Local Loopback)RX packets 296 bytes 54872 (53.5 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 296 bytes 54872 (53.5 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0[root@localhost ~]#5. 192.168.43.134 服務器創建host,info文件
vim host.info192.168.43.228 root 22 192.168.43.226 ly 22 192.168.43.225 user 226. 編輯腳本
#!/bin/bash HOST_INFO=host.info for IP in $(awk '/^[^#]/{print $1}' $HOST_INFO); doUSER=$(awk -v ip=$IP 'ip==$1{print $2}' $HOST_INFO)PORT=$(awk -v ip=$IP 'ip==$1{print $3}' $HOST_INFO)TMP_FILE=/tmp/disk.tmpssh -p $PORT $USER@$IP 'df -h' > $TMP_FILEUSE_RATE_LIST=$(awk 'BEGIN{OFS="="}/^\/dev/{print $NF,int($5)}' $TMP_FILE)for USE_RATE in $USE_RATE_LIST; doPART_NAME=${USE_RATE%=*}USE_RATE=${USE_RATE#*=}if [ $USE_RATE -ge 80 ]; thenecho -e "$IP /n Warning: $PART_NAME Partition usage $USE_RATE%!"elseecho "SERVER OK!"fidone done7. 賦予可執行權限
chmod +x 6.sh8. 運行腳本
[root@localhost app]# ./6.sh SERVER OK! SERVER OK! SERVER OK!9. 命令分解
[root@localhost ~]# df -h |awk '/^\/dev/{print $0}' /dev/mapper/centos-root 50G 2.1G 48G 5% / /dev/sda1 1014M 146M 869M 15% /boot /dev/mapper/centos-home 47G 33M 47G 1% /home vim host.info192.168.43.228 root 22 192.168.43.226 ly 22 192.168.43.225 user 22 #$1 第1列 #$2 第2列 #$3 第3列 [root@localhost ~]# awk '/^[^#]/{print $1}' host.info 192.168.43.228 192.168.43.226 192.168.43.225 [root@localhost ~]# awk '/^[^#]/{print $2}' host.info root ly user [root@localhost ~]# awk '/^[^#]/{print $3}' host.info 22 22 22 [root@localhost ~]# awk -v ip=192.168.43.228 '$1==ip{print $2}' host.info root總結
以上是生活随笔為你收集整理的Linux Shell脚本专栏_监控100台服务器磁盘利用率脚本_07的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Apache JMeter 测试 HTT
- 下一篇: Linux Shell脚本专栏_一键查看