小试牛刀
Posted qqsu007
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小试牛刀相关的知识,希望对你有一定的参考价值。
1、显示统计占用系统内存最多的进程,并排序。
[root@localhost ~]# ps aux | sort -k 4 -rn |head qemu 10866 4.5 12.6 17634232 16738712 ? Sl Nov13 704:19 /usr/libexec/qemu-kvm -name vm010 -S -machine pc-i440fx-rhel7.0.0,accel=kvm,usb=off,dump-guest-core=off -cpu Westmere,+vme,+ds,+acpi,+ss,+ht,+tm,+pbe,+pclmuldq,+dtes64,+monitor,+ds_cpl,+vmx,+smx,+est,+tm2,+xtpr,+pdcm,+pcid,+dca,+arat,+pdpe1gb,+rdtscp -m 16384 -realtime mlock=off -smp 2,sockets=2,cores=1,threads=1 -uuid 6486aaeb-1094-41ef-b6df-439c36911c78 -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-7-vm010/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown -boot menu=on,strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/home/kvm/disk1/v-disk10,format=qcow2,if=none,id=drive-virtio-disk0 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive file=/home/kvm/disk1/test1_add.qcow2,format=qcow2,if=none,id=drive-virtio-disk2,cache=none -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x6,drive=drive-virtio-disk2,id=virtio-disk2 -drive if=none,id=drive-ide0-1-1,readonly=on -device ide-cd,bus=ide.1,unit=1,drive=drive-ide0-1-1,id=ide0-1-1,bootindex=2 -netdev tap,fd=76,id=hostnet0,vhost=on,vhostfd=81 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:28:56:b9,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input1,bus=usb.0,port=1 -vnc 0.0.0.0:0 -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 -msg timestamp=on qemu 1428 2.5 6.3 9230252 8412928 ? Sl Nov11 478:34 /usr/libexec/qemu-kvm -name vm006 -S -machine pc-i440fx-rhel7.0.0,accel=kvm,usb=off,dump-guest-core=off -cpu Westmere,+vme,+ds,+acpi,+ss,+ht,+tm,+pbe,+pclmuldq,+dtes64,+monitor,+ds_cpl,+vmx,+smx,+est,+tm2,+xtpr,+pdcm,+pcid,+dca,+arat,+pdpe1gb,+rdtscp -m 8192 -realtime mlock=off -smp 2,sockets=2,cores=1,threads=1 -uuid 84e6e3bb-acba-4dc4-8c70-bc04c21ad172 -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-3-vm006/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown -boot menu=on,strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/home/kvm/disk1/v-disk06,format=qcow2,if=none,id=drive-virtio-disk0 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive if=none,id=drive-ide0-1-1,readonly=on -device ide-cd,bus=ide.1,unit=1,drive=drive-ide0-1-1,id=ide0-1-1,bootindex=2 -netdev tap,fd=77,id=hostnet0,vhost=on,vhostfd=79 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:62:80:f2,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input1,bus=usb.0,port=1 -vnc 0.0.0.0:2 -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 -msg timestamp=on wu.jing 7874 0.1 5.0 39726036 6625260 ? Sl Nov11 22:10 java -Dspring.profiles.active=test -jar crm_service-0.0.1-SNAPSHOT.jar wu.jing 7376 0.1 3.0 39784368 4015384 ? Sl Nov11 19:49 java -Dspring.profiles.active=test -jar psi_report_service-0.0.1-SNAPSHOT.jar wu.jing 7378 0.0 2.9 39045900 3868400 ? Sl Nov11 17:59 java -Dspring.profiles.active=test -jar psi_financial_accounting_service-0.0.1-SNAPSHOT.jar wu.jing 7370 0.0 2.8 39114480 3745900 ? Sl Nov11 18:20 java -Dspring.profiles.active=test -jar psi_sell_service-0.0.1-SNAPSHOT.jar wu.jing 7372 0.6 2.7 42049600 3568228 ? Sl Nov11 123:14 java -Dspring.profiles.active=test -jar psi_inventory_service-0.0.1-SNAPSHOT.jar wu.jing 7366 0.0 2.6 39114480 3482776 ? Sl Nov11 18:16 java -Dspring.profiles.active=test -jar psi_purchase_service-0.0.1-SNAPSHOT.jar wu.jing 7374 0.6 2.5 42116176 3410544 ? Sl Nov11 123:06 java -Dspring.profiles.active=test -jar psi_finance_service-0.0.1-SNAPSHOT.jar wu.jing 7364 0.1 2.5 39322392 3346680 ? Sl Nov11 19:18 java -Dspring.profiles.active=test -jar psi_base_service-0.0.1-SNAPSHOT.jar [root@localhost ~]#
2、编写脚本,使用for和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出"success!",若ping不通则输出"fail!"
[root@localhost ~]# cat pingIp.sh #!/bin/bash ip=192.168.0. for n in `seq 1 254` do ping -c 2 $ip$n &> /dev/null if (($?==0)) then echo "$ip$n success!" else echo "$ip$n fail!" fi done
[root@localhost ~]# bash pingIp.sh 192.168.0.1 fail! 192.168.0.2 fail! 192.168.0.3 fail! 192.168.0.4 fail! 192.168.0.5 fail! 192.168.0.6 fail! 192.168.0.7 fail!
3、每周的工作日1:30,将/etc备份至/backup目录中,保存的文件名称格式 为“etcbak-yyyy-mm-dd-HH.tar.xz”,其中日期是前一天的时间
[root@localhost data]# vi /backup/back_etc.sh
tar cvf /backup/etcbak-`date -d "-1 day" +%F-%H`.tar.xz /etc
[root@localhost data]# crontab -e 30 1 * * 1-5 root /bin/bash /backup/back_etc.sh
4、工作日时间,每10分钟执行一次磁盘空间检查,一旦发现任何分区利用率高 于80%,就发送邮件报警
[root@localhost data]# vi /monitor/monitor_disk.sh
for i in `df|awk ‘/^/dev//{print $5}‘|cut -d ‘%‘ -f1`;do if [ $i -gt 80 ];then # /bin/wall "disk is full" echo "disk is full" | mail -s "json" 117433596@qq.com &> /dev/null fi done
[root@localhost data]# crontab -e
*/10 * * * 1-5 root /bin/bash /monitor/monitor_disk.sh &> /dev/null
!-- p.p1>
以上是关于小试牛刀的主要内容,如果未能解决你的问题,请参考以下文章