运维面试题选摘
来源:原创 更新时间:2018-08-26 18:49:25 编辑:管理员 浏览:2183
1:如何将本地80端口的请求转发到8080端口,当前主机IP为192.168.2.1 ?
iptables -t nat -A PREROUTING -d 192.168.10.10 -p tcp --dport 80 -j DNAT --to-destination 192.168.10.10:8080 iptables -t nat -A PREROUTING -d 192.168.10.10 -p udp --dport 80 -j DNAT --to-destination 192.168.10.10:8080
2:通过Apache访问日志access.log 统计IP和每个地址访问的次数,按从大到小前10名?
cat access_log | awk '{print $1}' | sort | uniq -c | sort -nr
3:编写shell脚本,获取本机的网络地址。比如IP地址是192.168.100.2/255.255.255.0,那么它的网络地址是192.168.100.0
#!/bin/bash ip=`ifconfig|grep -A1 eth0|grep 'inet add'|awk -F: '{print $2}'|awk '{print $1}'` mask=`ifconfig|grep -A1 eth0|grep 'inet add'|awk -F: '{print $NF}'` echo "$ip/$mask"
#ip=`ifconfig eth0|grep -E "inet add"|awk '{print $2}'|awk -F: '{print $2}'`:
4:写一个脚本查找最后创建时间是3天前,后缀是*.log的文件并删除。
find / -name "*.log" -ctime +3 -exec rm -f {} \;
5:写一个脚本将某目录下大于100k的文件移动至/tmp下。
for i in `find /test -type f -size +100k`;do cd /test && mv $i /tmp;done
6:写一个脚本将数据库备份并打包至远程服务器192.168.1.1 /backup目录下。
mount 192.168.1.1:/backup /mnt cd /mnt /usr/local/mysql/bin/mysqldump -hlocalhost -uroot test >test.sql tar czf test.sql.tar.gz test.sql rm -f test.sql:
7 : 写一个防火墙配置脚本,只允许远程主机访问本机的80端口。
iptables -P INPUT ACCEPT iptables -P OUTPUT ACCEPT iptables -P FORWARD ACCEPT iptables -F iptables -X iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT iptables -P INPUT DROP
8 : 写一个脚本进行nginx日志统计,得到访问ip最多的前10个(nginx日志路径:/home/logs/nginx/default/access.log
awk '{a[$1]++}END{for (j in a) print a[j],j}' /home/logs/nginx/default/access.log|sort -nr|head -10
9、写一个脚本把指定目录里面的/usr/local替换成别的目录
sed 's:/usr/local:/tmp:g' filename