离职前他分享了阿里的核心面试题库

大公司的面试,看中的是你对于基础知识的掌握程度, 因为大公司的产品基本是基于开源产品的二次开发,或者使用自动化平台,而这些二次开发的东西是你在其他公司所无法接触到的,更别提让你熟悉阿里的产品或者工具。所以只能通过面试基础知识来考核你的学习能力

  1. netstat -antlp中t表示什么意思?
netstat用来查看系统当前系统网络状态信息,包括端口,连接情况等
netstat -atunlp,各参数含义如下:

-t : 指明显示TCP端口
-u : 指明显示UDP端口
-l : 仅显示监听套接字(LISTEN状态的套接字)
-p : 显示进程标识符和程序名称,每一个套接字/端口都属于一个程序
-n : 不进行DNS解析
-a 显示所有连接的端口
  1. 怎么查看内存?
    方法一:
[root@xinsz08-63 ~]# cat /proc/meminfo 
MemTotal:        3861320 kB
MemFree:         2972532 kB
MemAvailable:    3134304 kB

方法二:

[root@xinsz08-63 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        478M        2.8G         14M        389M        3.0G
Swap:          2.0G          0B        2.0G

方法三:

[root@xinsz08-63 ~]# vmstat  -s |head -n 3
      3861320 K total memory
       487792 K used memory
       347428 K active memory

  1. ss 命令可以用来做什么?

显示所有的TCP端口和使用它们的进程

[root@xinsz08-63 ~]# ss -tnap
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128    127.0.0.1:631                     *:*                   users:(("cupsd",pid=1280,fd=12))
LISTEN      0      128    192.168.1.63:3000                    *:*    
  1. shell命令中$* $# 分别表示什么意思
$0 当前脚本的文件名; 
$n 传递给脚本的第n个参数值(n为1~9); 
$* 传递给脚本的所有参数; 
$# 传递给脚本的参数个数; 
$? 显示最后命令的退出状态(0表示没有错误,其他任何值表明有错误); 
$$ 当前脚本运行的进程ID号; 
$@$*功能类似; 
$!执行上一个背景指令的PID(后台运行的最后一个进程的进程ID号)
$$ 这个程式的PID(脚本运行的当前进程ID号)
$- 显示shell使用的当前选项,与set命令功能相同
  1. shell随机产生20位数字和字母的密码
[root@xinsz08-63 ~]# echo $(date +%t%N)$RANDOM|md5sum|cut -c 2-21
bc1234b5b0276c4db48b

  1. 如何查看动态日志?
[root@xinsz08-63 ~]# tail -f /var/log/messages-20200427 
Apr 27 02:00:01 xinsz08-63 systemd: Started Session 26 of user root.
Apr 27 02:01:01 xinsz08-63 systemd: Started Session 27 of user roo

备注: 打印最后4条日志信息
tail -n 4 /var/log/messages-20200427

  1. 如何通过SSH在远程linux系统上运行命令?
    首先确保设置了ssh无秘钥登陆
    然后使用命令ssh进行远程执行命令,例如我们要查看的是磁盘信息
 ssh 192.168.1.63 df -h
  1. 如何查看系统版本号?
[root@xinsz08-63 ~]# cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)
  1. 查看系统内核?
[root@xinsz08-63 ~]# uname -r
3.10.0-1062.12.1.el7.x86_64
  1. 统计网页/inde.html的uv
grep "/index.html" /var/log/nginx/access.log | cut –d “ ” –f 4| sort | uniq | wc –l

备注: 统计整站的独立IP

cat /var/log/nginx/access.log | cut –d “ ” –f 1 | sort| uniq | wc -l 
  1. linux下使用find查找/var/log/目录下修改时间超过7天且文件名字带. 的文件,找到并删除
[root@xinsz08-63 ~]# find /var/log/ -mtime +7 -name "*.*" -exec rm  {} \;

备注: +7 查找7天前的文件
exec {} ; 固定写法

注意: 此命令不要轻易用

  1. 查看某个端口的网络连接情况

[root@xinsz08-63 ~]# lsof -i:22 (查看22号端口被占用情况)

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd    1283 root    3u  IPv4  27704      0t0  TCP *:ssh (LISTEN)
sshd    1283 root    4u  IPv6  27713      0t0  TCP *:ssh (LISTEN)
sshd    3046 root    3u  IPv4  44272      0t0  TCP xinsz08-63:ssh->192.168.1.4:sm-pas-5 (ESTABLISHED)
  1. 列出当前机器监听的端口
[root@xinsz08-63 ~]# lsof -i -s TCP:LISTEN
COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd      1    root   48u  IPv4  19237      0t0  TCP *:sunrpc (LISTEN)
systemd      1    root   50u  IPv6  19239      0t0  TCP *:sunrpc (LISTEN)
(LISTEN)
sshd      1283    root    3u  IPv4  27704      0t0  TCP *:ssh (LISTEN)
sshd      1283    root    4u  IPv6  27713      0t0  TCP *:ssh (LISTEN)
grafana-s 1287 grafana    6u  IPv4  30239      0t0  TCP xinsz08-63:hbci (LISTEN)
master    1488    root   13u  IPv4  28558      0t0  TCP localhost:smtp (LISTEN)
  1. 能够查看端口信息的命令
ss:可以用于转储套接字统计信息。
netstat:可以显示打开的套接字列表。
lsof:可以列出打开的文件。
fuser:可以列出那些打开了文件的进程的进程 ID。
nmap:是网络检测工具和端口扫描程序。

方法一:

[root@xinsz08-63 ~]# ss -tnlp |grep ssh
LISTEN     0      128          *:22                       *:*                   users:(("sshd",pid=1283,fd=3))
LISTEN     0      128       [::]:22                    [::]:*                   users:(("sshd",pid=1283,fd=4))
[root@xinsz08-63 ~]# 

方法二:

[root@xinsz08-63 ~]# ss -tnlp |grep :22
LISTEN     0      128          *:22                       *:*                   users:(("sshd",pid=1283,fd=3))
LISTEN     0      128       [::]:22                    [::]:*                   users:(("sshd",pid=1283,fd=4))
[root@xinsz08-63 ~]# 

方法三:

[root@xinsz08-63 ~]# netstat -tnlp |grep ssh
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1283/sshd           
tcp6       0      0 :::22                   :::*                    LISTEN      1283/sshd           
[root@xinsz08-63 ~]# 

[root@xinsz08-63 ~]# netstat -tnlp |grep ":22"
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1283/sshd           
tcp6       0      0 :::22                   :::*                    LISTEN      1283/sshd           
[root@xinsz08-63 ~]# 

方法四:

[root@xinsz08-63 ~]# lsof -i -P |grep ssh
sshd      1283    root    3u  IPv4  27704      0t0  TCP *:22 (LISTEN)
sshd      1283    root    4u  IPv6  27713      0t0  TCP *:22 (LISTEN)
sshd      3046    root    3u  IPv4  44272      0t0  TCP xinsz08-63:22->192.168.1.4:2942 (ESTABLISHED)

方法五:

[root@xinsz08-63 ~]# fuser -v 22/tcp
                     用户     进程号 权限   命令
22/tcp:              root       1283 F.... sshd
                     root       3046 F.... sshd
[root@xinsz08-63 ~]# 

方法六:

[root@xinsz08-63 ~]# nmap -sV -p 22 localhost

Starting Nmap 6.40 ( http://nmap.org ) at 2020-04-27 23:08 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000073s latency).
Other addresses for localhost (not scanned): 127.0.0.1
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.4 (protocol 2.0)
  1. 一条命令防范ddos攻击
[root@xinsz08 logs]# netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
      1 100.100.30.25
      1 Address
      1 servers)
      2 120.244.154.106

此套面试题,已经经过阿里学员,百度学员亲身体验,电话面试直接问基础命令。
有时候,最基础的反而是最能体现你工作能力的地方,也往往是很多人最薄弱的地方。 这意思跟最危险的地方,有时候反而是最安全的地方大抵相同。

基础不牢,地动山摇,小伙伴们还是要把基础掌握牢固啊。

猜你喜欢

转载自blog.csdn.net/xinshuzhan/article/details/105799588