第十一周
1、编写脚本selinux.sh,实现开启或禁用SELinux功能
[ scripts]# cat selinux.sh #!/bin/bash . /etc/init.d/functions STATUS=`getenforce` start(){ [ $STATUS != Disabled ] && { setenforce 1;echo "Selinux is already started";return 10; } sed -i ‘s/SELINUX=disabled/SELINUX=enforcing/‘ /etc/selinux/config action "starting selinux ..." echo "You need to restart the system for the changes to take effect." } stop(){ [ $STATUS = Disabled ] && { echo "Selinux is already stopped";return 20; } sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config action "stopping selinux ..." echo "You need to restart the system for the changes to take effect." echo "You can also use ‘setenforce 0‘ to turn off selinux temporarily" } status(){ getenforce } case $* in start) start ;; stop) stop ;; status) status ;; *) echo "Usage:$0 {start|stop|status}" exit 100 ;; esac # 执行结果 [ scripts]# ./selinux.sh status Disabled [ scripts]# ./selinux.sh start starting selinux ... [ OK ] You need to restart the system for the changes to take effect. [ scripts]# ./selinux.sh stop Selinux is already stopped [ scripts]#./selinux.sh status Enforcing [ scripts]#./selinux.sh stop stopping selinux ... [ OK ] You need to restart the system for the changes to take effect. You can also use ‘setenforce 0‘ to turn off selinux temporarily
2、统计/etc/fstab文件中每个文件系统类型出现的次数
[ ~]# awk ‘/^[^# ]/{fsys[$3]++}END{for(n in fsys)print n,fsys[n]}‘ /etc/fstab swap 1 ext4 1 xfs 3
3、提取出字符串%9&Bdh7dq+YVixp3vpw中的所有数字
[ ~]# echo "%9&Bdh7dq+YVixp3vpw" | awk -F "" ‘{for(n=1;n<=NF;n++){if($n ~ /[0-9]/)print $n}}‘ 0 5 9 7 3 [ ~]# echo "%9&Bdh7dq+YVixp3vpw" | tr -dc "[0-9]" 05973[ ~]#
4、解决DOS攻击生产案例:根据web日志或者或者网络连接数,监控当某个IP 并发连接数或者短时内PV达到100,即调用防火墙命令封掉对应的IP,监控频 率每隔5分钟。防火墙命令为:iptables -A INPUT -s IP -j REJECT
[ ~]# crontab -l */5 * * * * /usr/bin/awk ‘{IP[$1]++}END{for(n in IP){if(IP[n]>100)system("/usr/sbin/iptables -A INPUT -s " n " -j REJECT")}}‘ /var/log/httpd/access_log
相关推荐
xiaohouye 2020-08-19
chenchuang 2020-08-01
hnllei 2020-06-25
wys 2020-06-18
kerson 2020-06-16
LonelyTraveler 2020-05-29
sixforone 2020-05-28
missingmuch 2020-05-25
jLawrencee 2020-05-19
想个标题偏头痛 2020-05-04
liaochaowu 2020-05-03
RisenWang 2020-05-02
wintelx 2020-04-29
89284553 2020-04-10
老谢的自留地 2020-03-25
Summer的小屋 2020-02-29
wannagonna 2020-02-25
jackalwb 2020-01-29
jiangtie 2020-01-09