日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux Shell脚本专栏_监控100台服务器磁盘利用率脚本_07

發(fā)布時間:2024/9/27 linux 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux Shell脚本专栏_监控100台服务器磁盘利用率脚本_07 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

文章目錄

  • 監(jiān)控100臺服務(wù)器磁盤利用率腳本
    • 1. 遠(yuǎn)程連接生成sshkey
    • 2. 復(fù)制ssh公鑰到目標(biāo)服務(wù)器
    • 3. 登錄目標(biāo)服務(wù)器查看
    • 4. 私鑰免登錄
    • 5. 192.168.43.134 服務(wù)器創(chuàng)建host,info文件
    • 6. 編輯腳本
    • 7. 賦予可執(zhí)行權(quán)限
    • 8. 運行腳本
    • 9. 命令分解

監(jiān)控100臺服務(wù)器磁盤利用率腳本

1. df -h 查看磁盤占有2. 遠(yuǎn)程連接

1. 遠(yuǎn)程連接生成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. 復(fù)制ssh公鑰到目標(biāo)服務(wù)器

[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. 登錄目標(biāo)服務(wù)器查看

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 服務(wù)器通過私鑰免交互登錄目標(biāo)服務(wù)器(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 服務(wù)器創(chuàng)建host,info文件

vim host.info192.168.43.228 root 22 192.168.43.226 ly 22 192.168.43.225 user 22

6. 編輯腳本

#!/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 done

7. 賦予可執(zhí)行權(quán)限

chmod +x 6.sh

8. 運行腳本

[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

總結(jié)

以上是生活随笔為你收集整理的Linux Shell脚本专栏_监控100台服务器磁盘利用率脚本_07的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。