全程和就业作业
1、显示统计占用系统内存最多的进程,并排序。
[root@centos8 ~]# ps axo pid,cmd,%mem --sort -%mem #方法1
PID CMD %MEM
12966 /usr/libexec/mysqld --based 5.0
791 /usr/libexec/sssd/sssd_nss 2.0
760 /usr/libexec/platform-pytho 1.6
686 /usr/lib/polkit-1/polkitd - 1.3
685 /usr/sbin/NetworkManager -- 0.9
679 /usr/bin/vmtoolsd 0.8
779 /usr/libexec/sssd/sssd_be - 0.7
680 /usr/sbin/sssd -i --logger= 0.7
678 /usr/bin/VGAuthService -s 0.7
1 /usr/lib/systemd/systemd -- 0.5
986 /usr/sbin/rsyslogd -n 0.5
570 /usr/lib/systemd/systemd-jo 0.5
1239 /usr/lib/systemd/systemd -- 0.5
[root@centos8 ~]# top #方法2,在top下,按M键按照内存排序
top - 18:10:42 up 1 day, 22:11, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 129 total, 1 running, 128 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 1806.2 total, 241.7 free, 313.3 used, 1251.3 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 1308.0 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12966 mysql 20 0 1298804 93580 21332 S 0.0 5.1 0:25.31 mysqld
791 root 20 0 220676 37172 35548 S 0.0 2.0 0:01.22 sssd_nss
760 root 20 0 424280 30736 16004 S 0.0 1.7 0:13.20 tuned
686 polkitd 20 0 1626820 25572 16628 S 0.0 1.4 0:00.11 polkitd
685 root 20 0 389304 17216 14672 S 0.0 0.9 0:02.08 NetworkManager
679 root 20 0 248944 15208 13220 S 0.0 0.8 1:10.85 vmtoolsd
779 root 20 0 217928 14292 11628 S 0.0 0.8 0:00.89 sssd_be
2、编写脚本,使用for和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出""success!"",若ping不通则输出""fail!""
- for循环
[root@centos8 ~]# cat test1.sh #for方法1
#!/bin/bash
subnet=192.168.0.
for ip in {1..255}; do
{ ping -c 2 -w 2 ${subnet}${ip} &> /dev/null && echo "${subnet}${ip} success!" || echo "${subnet}${ip} fail!"; }&
done
wait
[root@centos8 ~]# cat test2.sh #for方法2
#!/bin/bash
subnet=192.168.0.
for ((i=1;i<=255;i++)); do
{ ping -c 2 -w 2 ${subnet}${i} &> /dev/null && echo "${subnet}${i} success!" || echo "${subnet}${i} fail!"; }&
done
wait
[root@centos8 ~]#
- while循环
[root@centos8 ~]# cat test3.sh #while方法1
#!/bin/bash
subnet=192.168.0.
seq 1 255 | while read ip; do
{ ping -c 2 -w 2 ${subnet}${ip} &> /dev/null && echo "${subnet}${ip} success!" || echo "${subnet}${ip} fail!"; }&
done
[root@centos8 ~]# cat test4.sh #while方法2
#!/bin/bash
subnet=192.168.0.
ip=1
while [[ ${ip} -lt 256 ]]; do
{ ping -c 2 -w 2 ${subnet}${ip} &> /dev/null && echo "${subnet}${ip} success!" || echo "${subnet}${ip} fail!"; }&
let ip++
done
wait
[root@centos8 ~]#
3、每周的工作日1:30,将/etc备份至/backup目录中,保存的文件名称格式 为“etcbak-yyyy-mm-dd-HH.tar.xz”,其中日期是前一天的时间
- 准备备份脚本
[root@centos8 ~]# cat backup_etc.sh
#!/bin/bash
src_dir=/etc
backup_dir=/backup
backup_etc (){
mkdir -p ${backup_dir}
tar -cPf ${backup_dir}/etcbak`date -d "-1day" +"%F-%H"`.tar.xz ${src_dir}
}
backup_etc
- 创建crontab
[root@centos8 ~]# crontab -e
[root@centos8 ~]# crontab -l
30 1 * * 1-5 /bin/bash /root/backup_etc.sh
[root@centos8 ~]#
4、工作日时间,每10分钟执行一次磁盘空间检查,一旦发现任何分区利用率高 于80%,就发送邮件报警
- 准备检查磁盘脚本
[root@centos8 ~]# cat disk_space_check.sh
#!/bin/bash
sendmail (){
rpm -q mailx || yum -y install mailx &> /dev/null
rpm -q sendmail || yum -y install sendmail &> /dev/null
contact=123456@qq.com
subject="Wanning: `hostname -I` $1 space will be fulled!!!"
content="Date: $(date +'%F %T') \n Host: $(hostname -I) \n Device: $1 \n Info:\n$(df -h $1)"
echo $content | mail -s $subject $contact
}
disk_space_check (){
disk=`df -h | awk -F' |%' -v warnning=80 '/^\/dev\/.*/{if($(NF-2)>=warnning) print $1}'`
if [ -n "${disk}" ];then
for d in $disk;do
sendmail $d
done
fi
}
disk_space_check
- 创建crontab
[root@centos8 ~]# crontab -e
[root@centos8 ~]# crontab -l
*/10 * * * 1-5 /bin/bash /root/disk_space_check.sh
[root@centos8 ~]#
架构作业
"1、使用docker安装部署jumpserver跳板机
2、openstack rocky版keystone,glance,nova,neutron,cirros等安装配置。
3、配置nginx反向代理tomcat,并使用 redis实现会话保持。"