网友投稿 250 2022-11-07

磁盘方面:

1.节点空间不够的问题磁盘空间的内容虽然很多,但是节点编号不够,导致它也说磁盘空间不够2.删除大文件,但是磁盘空间依然没有释放

df -h 查看,空间依然无法释放, 方法一 : [root03:07 PMcentos8 /opt]#lsof |grep delete 查看是哪个进程在使用该文件,将使用那个文件的进程创建删除 但是如果是一个nginx 占用该文件,那么就半夜删除该文件,关闭Nginx,删除大文件后再 启动nginx ,但是万一服务起不来了怎么办。所以这依然是个不好的办法 方法二: cat /dev/null 和 > 都可以清空文件,但是cat /dev/null 更通用 >的通用性不好,必须在bash 下才可以,在csh下就不可以了

进程管理方面

用户管理方面

1.让以后新建的账户都有一个同样的文件

修改/etc/skel 里面添加文件

文件权限问题

1.执行 cp /etc/issue /data/dir 所需要的最小权限? /bin/cp 需要x权限 /etc/ 需要x权限 /etc/issue 需要r 权限 /data 需要x权限 /data/dir 需要w,x 权限

2.一个文件夹用root一直无法删除

lsattr FILENAME 查看文件的权限 chattr -i FILENAME chattr -a FILENAME

文本处理工具

1.两个文件取相同行和不同行 sort uniq

[root@centos8 data]#cat test1.txt a b 1 c [root@centos8 data]#cat test2.txt b e f c 1 2 #取文件的共同行 [root@centos8 data]#cat test1.txt test2.txt | sort |uniq -d 1 b c #取文件的不同行 [root@centos8 data]#cat test1.txt test2.txt | sort |uniq -u 2 a e f

2.找到超过10天的一个大于10M文件且将它移走

[root10:07 AMcentos8 /scripts]#find /usr/ -size +10M -mtime +10 -ok mv {} /data \;

3.取出网站访问量最大的前3个IP

[root@VM_0_10_centos logs]# awk '{print $1}' nginx.access.log-20200428|sort | uniq -c |sort -nr|head -3   5498 122.51.38.20   2161 117.157.173.214   953 211.159.177.120   [root@centos8 ~]#awk '{print $1}' access_log |sort |uniq -c|sort -nr|head   4870 172.20.116.228   3429 172.20.116.208   2834 172.20.0.222   2613 172.20.112.14   2267 172.20.0.227   2262 172.20.116.179   2259 172.20.65.65   1565 172.20.0.76   1482 172.20.0.200   1110 172.20.28.145

4.取出分区利用率

[root@centos8 ~]#df | awk '{print $1,$5}' Filesystem Use% devtmpfs 0% tmpfs 0% tmpfs 2% tmpfs 0% /dev/sda2 3% /dev/sda3 1% /dev/sda1 15% tmpfs 0% #使用扩展的正则表达式 [root@centos8 ~]#df | awk -F"[[:space:]]+|%" '{print $5}' 使用空格和%作为分隔符 Use 001051 92 1 [root@centos8 ~]#df | awk -F'[[:space:]]+|%' '{print $1,$5}'   Filesystem Use devtmpfs 0 tmpfs 0 tmpfs 2 tmpfs 0 /dev/sda2 3 /dev/sda3 1 /dev/sda1 15 tmpfs 0 [root@centos8 ~]#df | grep "^/dev/sd" | awk -F"[[:space:]]+|%" '{print $5}' 51 92 [root@centos8 ~]#df | grep '^/dev/sd'| awk -F'[[:space:]]+|%' '{print $1,$5}'   /dev/sda2 3 /dev/sda3 1 /dev/sda1 15 [root@centos8 ~]#df | awk -F"[[:space:]]+|%" '/^\/dev\/sd/{print $5}' 51 92 [root@centos8 ~]#df | awk -F'[[:space:]]+|%' '/^\/dev\/sd/{print $1,$5}'   /dev/sda2 3 /dev/sda3 1 /dev/sda1 15

5.取 ifconfifig 输出结果中的IP地址

[root@centos8 ~]#ifconfig eth0 | awk '/netmask/{print $2}' 10.0.0.8 [root@centos6 ~]#ifconfig eth0 |awk -F " +|:" '/Mask/{print $4}' 10.0.0.6 [root@centos8 ~]#ifconfig eth0| sed -rn '2s/^[^0-9]+([0-9.]+) .*$/\1/p' 10.0.0.8 [root@centos6 ~]#ifconfig eth0| sed -rn '2s/^[^0-9]+([0-9.]+) .*$/\1/p' 10.0.0.6

6.文件host_list.log 如下格式,请提取”.magedu.com”前面的主机名部分并写入到回到该文件中

[root@centos8 ~]#cat host_list.log 1 magedu.com 2 blog.magedu.com 3 study.magedu.com 4 linux.magedu.com 5 python.magedu.com [root@centos8 ~]#awk -F"[ .]" '{print $2}' host_list.log www blog study linux python [root@centos8 ~]#awk -F"[ .]" '{print $2}' host_list.log >> host_list.log [root@centos8 ~]#cat host_list.log 1 magedu.com 2 blog.magedu.com 3 study.magedu.com 4 linux.magedu.com 5 python.magedu.com www blog study linux python

7.接数最多的前3个IP

[root@centos8 ~]#awk -F" +|:" '{print $(NF-2)}' ss.log |sort |uniq -c|sort - nr|head -n3     12 223.88.255.148     11 119.250.197.118     10 183.202.63.36 [root@centos8 ~]#awk -F" +|:" '/^ESTAB/{print $(NF-2)}' ss.log |sort |uniq - c|sort -nr|head -n3     12 223.88.255.148     10 183.202.63.36     9 117.152.155.119 [root@centos8 ~]#ss -nt |grep "^ESTAB" | awk -F"[[:space:]]+|:" '{print $(NF- 2)}' 10.0.0.1 10.0.0.7 10.0.0.1 [root@centos8 ~]#ss -nt |awk -F"[[:space:]]+|:" '/^ESTAB/{print $(NF-2)}' [root@centos8 ~]#ss -nt|awk -F: '{print $(NF-1)}' |awk '/^[0-9]/{print $NF}'| sort |uniq -c |head -n 3

8.每十分钟检查将连接数超过100个以上的IP放入黑名单拒绝访问

第一步:编写脚本 [root@centos8 ~]#cat deny_dos.sh LINK=100 while true;do ss -nt | awk -F"[[:space:]]+|:" '/^ESTAB/{print $(NF-2)}'|sort |uniq - c|while read count ip;do if [ $count -gt $LINK ];then   iptables -A INPUT -s $ip -j REJECT fi done done 第二步:写计划任务 [root@centos8 ~]#chmod +x /root/deny_dos.sh [root@centos8 ~]#crontab -e [root@centos8 ~]#crontab -l */10 * * * *   /root/deny_dos.sh -------------------------------------------------------------- [root@centos8 ~]#cat deny_dos.sh IPLIST=`awk -F" +|:" '/^ESTAB/{print $(NF-2)}' ss.log |sort |uniq -c|sort - nr|head -3|awk '{print $2}'` for ip in $IPLIST;do   iptables -A INPUT -s $ip -j REJECT done

端口冲突

[root@centos8 ~]#nc -l 22 Ncat: bind to :::22: Address already in use. QUITTING. [root@centos8 ~]#ss -ntlp State   Recv-Q   Send-Q       Local Address:Port   Peer Address:Port                   LISTEN  0         128                 0.0.0.0:22              0.0.0.0:*       users:(("sshd",pid=699,fd=4))   LISTEN  0         128                   [::]:22                 [::]:*       users:(("sshd",pid=699,fd=6))   [root@centos8 ~]#lsof -i :22 COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME sshd     699 root   4u IPv4  26846     0t0 TCP *:ssh (LISTEN) sshd     699 root   6u IPv6  26848     0t0 TCP *:ssh (LISTEN) sshd    1287 root   5u IPv4  29875     0t0 TCP centos8.localdomain:ssh- >10.0.0.1:pc-mta-addrmap (ESTABLISHED) sshd    1300 root   5u IPv4  29875     0t0 TCP centos8.localdomain:ssh- >10.0.0.1:pc-mta-addrmap (ESTABLISHED)

利用管道read无法赋值

[root11:26 AMcentos7 ]#cat f1 a b [root11:26 AMcentos7 ]#read i j

求和

[root@centos7: ~]#seq -s + 100 |bc 5050 [root@centos7: ~]#sum=0;for i in {1..100};do let sum+=$i;done;echo sum=$sum sum=5050 [root@centos7: ~]#echo {1..100} |tr ' ' + |bc 5050 [root@ C8-18]#for((sum=0,i=1;i<=100;sum+=i,i++));do true;done;echo $sum 5050 [root@c7-4 data]# seq -s+ 1 10 1+2+3+4+5+6+7+8+9+10 [root@c7-4 data]# seq -s+ 1 10 >bc.log [root@c7-4 data]# bc

将指定目录下的文件所有文件的后缀改名为 bak

#!/bin/bash # #************************************* #author: 王千三 #QQ: 1722525928 #email: 1722525928@qq.com #version: 1.0 #date: 2021-05-16 #description: 怕水的鱼 #************************************* DIR=/data/tests cd $DIR for i in *;do PRE=`echo $i |sed -nr 's#^(.*)\.[^.]+$#\1#p'` mv $i $PRE.bak done

要求将目录YYYY-MM-DD/中所有文件,移动到YYYY-MM/DD/下

#1 yyyy-mm-dd10.sh 创建YYYY-MM-DD,当前日期一年前365天到目前共365个目录,里面有10个文件, $RANDOM.log [root@centos8 ~]#cat for_dir.sh #!/bin/bash for i in {1..365};do DIR=`date -d "-$i day" +%F` mkdir /data/test/$DIR cd /data/test/$DIR for n in {1..10};do touch $RANDOM.log done done #2 移动到YYYY-MM/DD/下   #!/bin/bash # DIR=/data/test cd $DIR for DIR in * ;do YYYY_MM=`echo $DIR |cut -d"-" -f1,2` DD=`echo $DIR |cut -d"-" -f3` [ -d $YYYY_MM/$DD ] || mkdir -p $YYYY_MM/$DD &> /dev/null mv $DIR/*   $YYYY_MM/$DD done

扫描一个网段:10.0.0.0/24,判断此网段中主机在线状态,将在线的主机的IP打印出来

NET=10.0.0 for ID in {1..254};do   {    ping -c1 -W1 $NET.$ID &> /dev/null && echo $NET.$ID is up || echo $NET.$ID is down   }& done wait wait:表示所有ping完了就自动的退出了

求年纪之和

[root10:56 PMcentos7~ ]#cat a xiaoing=20 xiaohong=18 xiaoqiang=22 方法一: [root11:08 PMcentos7~ ]#cut -d"=" -f2 a |tr -s "\n" + |cut -d'+' -f1-3 20+18+22 [root11:01 PMcentos7~ ]#cut -d"=" -f2 a |tr -s "\n" + |cut -d'+' -f1-3 |bc 60 方法二: [root11:14 PMcentos7~ ]#cut -d"=" -f2 a |tr -s "\n" + |grep -Eo "([0-9]+\+){2}[0-9]+"|bc 60 方法三 [root11:14 PMcentos7~ ]#cut -d"=" -f2 a |tr -s "\n" + 20+18+22+[root11:16 PMcentos7~ ]#cut -d"=" -f2 a |tr -s "\n" + |grep -Eo ".*[0-9]+" |bc 60 方法四: [root10:11 AMcentos8 ~]#awk -F"=" '{print $2}' |paste -sd+ |bc 60

mysql

#创建时间表: https://blog./u_14847540/3675905 MariaDB [test]> desc testdate_01; +-------+-----------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-----------+------+-----+---------------------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | date | timestamp | NO | | current_timestamp() | | +-------+-----------+------+-----+---------------------+----------------+ 2 rows in set (0.000 sec) MariaDB [test]> select * from testdate_01; +----+---------------------+ | id | date | +----+---------------------+ | 1 | 2021-08-29 03:00:38 | | 2 | 2021-08-29 03:01:10 | | 3 | 2021-08-29 07:23:34 | | 4 | 2021-08-29 07:22:56 | | 5 | 2021-08-29 07:22:46 | +----+---------------------+ 5 rows in set (0.000 sec) MariaDB [test]> select * from testdate_01 where date between '2021-08-29 03:00:38' and '2021-08-29 07:22:46 '; +----+---------------------+ | id | date | +----+---------------------+ | 1 | 2021-08-29 03:00:38 | | 2 | 2021-08-29 03:01:10 | | 5 | 2021-08-29 07:22:46 | +----+---------------------+ 3 rows in set (0.000 sec) 或者; MariaDB [test]> select * from testdate_01 where date >= '2021-08-29 03:00:38' <= '2021-08-29 07:22:46 '; +----+---------------------+ | id | date | +----+---------------------+ | 1 | 2021-08-29 03:00:38 | | 2 | 2021-08-29 03:01:10 | | 3 | 2021-08-29 07:23:34 | | 4 | 2021-08-29 07:22:56 | | 5 | 2021-08-29 07:22:46 | +----+---------------------+ 5 rows in set, 1 warning (0.000 sec)

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:程序包管理补充
下一篇:解决@springboottest注解无法加载src/main/resources目录下文件
相关文章

 发表评论

暂时没有评论,来抢沙发吧~