您的位置:首页 > 运维架构 > Linux

Linux面试题&答案03

2017-03-24 20:25 344 查看
1--处理以下文件内容,将域名去除并进行计数排序,如处理:
http://www.baidu.com/index.html
http://www.baidu.com/1.html
http://post.baidu.com/index.html
http://mp3.baidu.com/index.html
http://www.baidu.com/3.html
http://post.baidu.com/2.html
得到如下结果:
域名的出现次数 域名
3 www.baidu.com
2 post.baidu.com
1 mp3.baidu.com

解:awk -F'/' '{print $2,$3}' 1.txt | sort -r | uniq -c
2--通过nginx访问日志access.log 统计IP和每个地址访问的次数,按访问量列出前十名。
日志格式样例如下
192.168.1.247 - [02/Jul/2010:23:44:59+0800] "GET /HTTP/1.1" 200 19

解:cd /usr/local/nginx/logs 日志位置

awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10}' | uniq -c | sort -rn | head -10
3--如何将本地80端口的请求转发到8080端口,当前主机IP为192.168.16.1,其中本地网卡eth0:
解:iptables -t nat -A PREROUTING -d 192.168.16.1 -p tcp --dport 80 -j DNAT --to-destination

192.168.16.1:8080
4--编写个shell脚本将当前目录下大于10K的文件转移到/tmp目录下;
解: #!/bin/bash
cd /home/test
for i in `ls -l | awk '{if($5>10240){print $9}}'`
do
mv $i /tmp
done
5--在mysql创建一个系统用户为ytk,用户权限为增删改查,写出详细命令?
解://创建用户
mysql> use mysql;
mysql> insert into user(Host,User,Password) values('localhost','ytk',password('123456'));
//查看用户有哪些权限
mysql> select * from user where User='ytk'\G;
//授予增删改查权限
mysql> GRANT SELECT,UPDATE,INSERT,DELETE on *.* to ytk@'localhost';
6--现公司有这样需求,将nginx反向代理apache,已知apache地址:192.168.2.11 代理链接为
curl http://192.168.2.11/index.php,nginx具体怎么配置能够实现此功能? 解:nginx代理详解
--/usr/local/nginx/conf/vhosts/ 创建proxy.conf
--server {
listen 80;
server_name www.nginx.com;

location / {
proxy_pass http://192.168.2.11/; #proxy_set_header Host $host;
}
}
-- curl -x127.0.0.1:80 www.nginx.com
--dig www.baidu.com 查看网址
--upstream wang{
server 192.168.2.11:80
}
server {
listen 80;
server_namewww.nginx.com;

location / {
proxy_pass http://wang/; proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
}
} 负载均衡

7--请列出以下服务的运行端口号
解:ssh 22 redis6379 SMTP25 DNS 53 samba(UDP 137 138 TCP 139 445) mysql(3306 show variables ;)

mongodb (db.getMongo() 27017) pops(110) https443 ftp(20和21)、https(443)、smtp(25)、pops(110)、

ssh(22) zabbix_agent 10050
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: