上海网站建设q479185700強,韩国小游戏网站,网站我优化,西地那非片的功效是多长时间文章目录监控100台服务器磁盘利用率脚本1. 远程连接生成sshkey2. 复制ssh公钥到目标服务器3. 登录目标服务器查看4. 私钥免登录5. 192.168.43.134 服务器创建host,info文件6. 编辑脚本7. 赋予可执行权限8. 运行脚本9. 命令分解监控100台服务器磁盘利用率脚本 1. df -h 查看磁盘…
文章目录监控100台服务器磁盘利用率脚本1. 远程连接生成sshkey2. 复制ssh公钥到目标服务器3. 登录目标服务器查看4. 私钥免登录5. 192.168.43.134 服务器创建host,info文件6. 编辑脚本7. 赋予可执行权限8. 运行脚本9. 命令分解监控100台服务器磁盘利用率脚本 1. df -h 查看磁盘占有2. 远程连接1. 远程连接生成sshkey
[rootlocalhost ~]# 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/RVeG1Jqc rootlocalhost.localdoma
The keys randomart image is:
---[RSA 2048]----
| ..ooBo.o.. |
| .o.* .o.. |
|.o o .o. |
|. o . . |
|. . ..S . . |
|o. o.... o |
|o..o E |
| *.B. o |
| .o . |
----[SHA256]-----
[rootlocalhost ~]#
2. 复制ssh公钥到目标服务器
[rootlocalhost ~]# ssh-copy-id root192.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) cant be established.
ECDSA key fingerprint is SHA256:FXF2nnfx1mP2M662486Z/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
root192.168.43.228s password: Number of key(s) added: 1Now try logging into the machine, with: ssh root192.168.43.228
and check to make sure that only the key(s) you wanted were added.
3. 登录目标服务器查看
192.168.43.228
[rootlocalhost ~]# ls -a
. anaconda-ks.cfg .bash_profile .cshrc .tcshrc
.. .bash_logout .bashrc .ssh .viminfo
[rootlocalhost ~]# cd .ssh/
[rootlocalhost .ssh]# ll
total 4
-rw------- 1 root root 408 Feb 24 21:16 authorized_keys
[rootlocalhost .ssh]#4. 私钥免登录
192.168.43.134 服务器通过私钥免交互登录目标服务器(192.168.43.228)
[rootlocalhost ~]# ssh -i .ssh/id_rsa root192.168.43.228
Last login: Mon Feb 24 21:20:34 2020 from 192.168.43.134
[rootlocalhost ~]# ifconfig
ens33: flags4163UP,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 0x20linkether 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: flags73UP,LOOPBACK,RUNNING mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10hostloop 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[rootlocalhost ~]#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_INFOhost.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. 运行脚本
[rootlocalhost app]# ./6.sh
SERVER OK!
SERVER OK!
SERVER OK!9. 命令分解
[rootlocalhost ~]# 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% /homevim 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列
[rootlocalhost ~]# awk /^[^#]/{print $1} host.info
192.168.43.228
192.168.43.226
192.168.43.225
[rootlocalhost ~]# awk /^[^#]/{print $2} host.info
root
ly
user
[rootlocalhost ~]# awk /^[^#]/{print $3} host.info
22
22
22[rootlocalhost ~]# awk -v ip192.168.43.228 $1ip{print $2} host.info root