39 Common Linux System Administration Interview Questions

1. How to check the number of physical CPUs and the number of cores per CPU in the current Linux system?

答:[root@centos6 ~ 10:55 #35]# cat /proc/cpuinfo|grep -c 'physical id'

4

[root@centos6 ~ 10:56 #36]# cat /proc/cpuinfo|grep -c 'processor'

4

2. There are two commonly used commands to check system load. Which two are they? What do these three numbers mean?

Answer: [root@centos6 ~ 10:56 #37]# w

10:57:38 up 14 min,  1 user,  load average: 0.00, 0.00, 0.00

USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT

root     pts/0    192.168.147.1    18:44    0.00s  0.10s  0.00s w

[root@centos6 ~ 10:57 #38]# uptime

10:57:47 up 14 min,  1 user,  load average: 0.00, 0.00, 0.00

The load average is the system load, and the three values ​​represent the average load of the system in one minute, five minutes, and fifteen minutes, that is, the average number of tasks.

3. What do the columns of vmstat r, b, si, so, bi, bo mean?

Answer: [root@centos6 ~ 10:57 #39]# vmstat

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----

r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st

0  0      0 1783964  13172 106056    0    0    29     7   15   11  0  0 99  0  0

r is running, indicating the number of tasks being run

b is blocked, indicating the number of blocked tasks

si indicates how much data is read from the swap partition into memory

so indicates how much data is written from memory to the swap partition

bi indicates how much data is read from disk into memory

bo indicates how much data is written from memory to disk

Short note: i --input, enter memory

o --output, out of memory

s --swap, swap partition

b --block, block device, disk

The unit is KB

4. In Linux system, do you know how to distinguish between buffer and cache?

Answer: Both the buffer and the cache are an area in the memory. When the CPU needs to write data to the disk, because the disk speed is relatively slow, the CPU first stores the data in the buffer, and then the CPU performs other tasks. The data in the buffer will be periodically Write to disk; when the CPU needs to read data from the disk, because the disk speed is relatively slow, the data to be used can be stored in the cache in advance, and the CPU can get the data directly from the cache much faster.

5. When using top to view the system resource usage, which column represents the memory usage?

答: PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

301 root 20 0 0 0 0 S 0.3 0.0 0:00.08 jbd2/sda3-8

1 root      20   0  2900 1428 1216 S  0.0  0.1   0:01.28 init

2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd

3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0

VIRT virtual memory usage

RES physical memory usage

SHR shared memory usage

%MEM memory usage

6. How to check the network card traffic in real time? How to view historical network card traffic?

A: Install the sysstat package and use the sar command to view it.

yum install -y sysstat#Install the sysstat package and get the sar command

sar -n DEV# View network card traffic, update every 10 minutes by default

sar -n DEV 1 10# is displayed once a second, a total of 10 times

sar -n DEV -f /var/log/sa/sa22#View the traffic log of the specified date

7. How to check which processes are in the current system?

Answer: ps -aux or ps -elf

[root@centos6 ~ 13:20 #56]# ps -aux

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

root         1  0.0  0.0   2900  1428 ?        Ss   10:43   0:01 /sbin/init

root         2  0.0  0.0      0     0 ?        S    10:43   0:00 [kthreadd]

root         3  0.0  0.0      0     0 ?        S    10:43   0:00 [migration/0]

root         4  0.0  0.0      0     0 ?        S    10:43   0:00 [ksoftirqd/0]

……

[root@centos6 ~ 13:21 #57]# ps -elf

F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD

4 S root         1     0  0  80   0 -   725 -      10:43 ?        00:00:01 /sbin/init

1 S root         2     0  0  80   0 -     0 -      10:43 ?        00:00:00 [kthreadd]

1 S root         3     2  0 -40   - -     0 -      10:43 ?        00:00:00 [migration/0]

1 S root         4     2  0  80   0 -     0 -      10:43 ?        00:00:00 [ksoftirqd/0]

1 S root         5     2  0 -40   - -     0 -      10:43 ?        00:00:00 [migration/0]

8. When ps checks the system process, there is a column of STAT. What does it mean if the stat of the current process is Ss? What does it mean if it is Z?

Answer: S means sleeping; s means main process; Z means zombie process.

9. How to check which ports are opened by the system?

Answer: [root@centos6 ~ 13:20 #55]# netstat -lnp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1035/sshd

tcp        0      0 :::22                       :::*                        LISTEN      1035/sshd

udp        0      0 0.0.0.0:68                  0.0.0.0:*                               931/dhclient

Active UNIX domain sockets (only servers)

Proto RefCnt Flags       Type       State         I-Node PID/Program name    Path

unix  2      [ ACC ]     STREAM     LISTENING     6825   1/init              @/com/ubuntu/upstart

unix  2      [ ACC ]     STREAM     LISTENING     8429   1003/dbus-daemon    /var/run/dbus/system_bus_socket

10. How to check the network connection status?

Answer: [root@centos6 ~ 13:22 #58]# netstat -an

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address               Foreign Address             State

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN

tcp        0      0 192.168.147.130:22          192.168.147.1:23893         ESTABLISHED

tcp        0      0 :::22                       :::*                        LISTEN

udp        0      0 0.0.0.0:68                  0.0.0.0:*

……

11. If you want to modify the IP, which configuration file needs to be edited? After modifying the configuration file, how to restart the network card to make the configuration take effect?

A: Use vi or vim editor to edit the network card configuration file /etc/sysconfig/network-scripts/ifcft-eth0 (if the eth1 file name is ifcft-eth1), the content is as follows:

DEVICE=eth0

HWADDR = 00: 0C: 29: 06: 37: BA

TYPE=Ethernet

UUID=0eea1820-1fe8-4a80-a6f0-39b3d314f8da

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=static

IPADDR=192.168.147.130

NETMASK=255.255.255.0

GATEWAY=192.168.147.2

DNS1=192.168.147.2

DNS2=8.8.8.8

After modifying the network card, you can restart the network card with the command:

ifdown eth0

ifup eth0

You can also restart the network service:

service network restart

12. Can you configure multiple IPs for one network card? If so, how?

A: You can configure multiple IPs for one network card. The configuration steps are as follows:

cat /etc/sysconfig/network-scripts/ifcfg-eth0#View the configuration of eth0

DEVICE=eth0

HWADDR = 00: 0C: 29: 06: 37: BA

TYPE=Ethernet

UUID=0eea1820-1fe8-4a80-a6f0-39b3d314f8da

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=static

IPADDR=192.168.147.130

NETMASK=255.255.255.0

GATEWAY=192.168.147.2

DNS1=192.168.147.2

DNS2=8.8.8.8

(1) Create a new ifcfg-eth0:1 file

cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1

(2) Modify its content as follows: vim /etc/sysconfig/network-scripts/ifcfg-eth0:1

DEVICE=eth0:1

HWADDR = 00: 0C: 29: 06: 37: BA

TYPE=Ethernet

UUID=0eea1820-1fe8-4a80-a6f0-39b3d314f8da

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=static

IPADDR=192.168.147.133

NETMASK=255.255.255.0

GATEWAY=192.168.147.2

DNS1=192.168.147.2

DNS2=8.8.8.8

(3) Restart the network service:

service network restart

13. How to check whether a network card is connected to the switch?

Answer: mii-tool eth0 or mii-tool eth1

14. How to check the hostname of the current host and how to modify the hostname? Which configuration file do I need to modify to make it still take effect after restarting?

Answer: View the hostname: hostname

centos6.5

Modify the hostname: hostname centos6.5-1

For permanent effect, you need to modify the configuration file: vim /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=centos6.5-1

15. Which configuration file needs to be modified to set DNS?

Answer: (1) Set DNS in the file /etc/resolv.conf

(2) Set DNS in the file /etc/sysconfig/network-scripts/ifcfg-eth0

16. Use iptables to write a rule: directly reject the packets whose source IP is 192.168.1.101 to access port 80 of the machine

答:iptables -I INPUT -s 192.168.1.101 -p tcp --dport 80 -j REJECT

17. How to save iptable rules to a file? How to restore?

A: Use iptables-save to redirect to a file: iptables-save > 1.ipt

Use iptables-restore to reverse redirect back: iptables-restore < 1.ipt

18. How to backup a user's task plan?

Answer: Copy the task plan of the specified user in the /var/spool/cron/ directory to the backup directory cron_bak/

cp /var/spool/cron/rachy /tmp/bak/cron_bak/

19. In the task plan format, what do the first 5 numbers sub-table mean?

Answer: In order: minutes, hours, days, months, weeks

20. How can I turn off unused services in the system?

Answer: (1) Use the visualization tool: ntsysv

(2) Use the command: chkconfig servicename off

21. How to make a service (if the service name is nginx) only open in two run levels 3 and 5, and close other levels?

Answer: Turn off all runlevels first: chkconfig nginx off

Then turn on the 35 runlevel: chkconfig --level 35 nginx on

22. In the rsync synchronization command, what is the difference between the following two methods?

(1) rsync -av / dira / ip: / dirb /

(2) rsync -av / dira / ip :: dirb

Answer: (1) The former is synchronized through ssh

(2) The latter is synchronized through the rsync service

23. During rsync synchronization, if there is a soft link in the source to be synchronized, how to synchronize the target file or directory of the soft link?

A: To synchronize source files, you need to add the -L option

24. After an account logs in to Linux, which log files will the system record relevant information?

A: The user authentication process is recorded in /var/log/secure, and the successful login information is recorded in /var/log/wtmp.

25. When there is a problem with the network card or hard disk, which command can we use to view the relevant information?

Answer: Use the command dmesg

26. Use xargs and exec respectively to achieve such requirements, and change the permissions of all files with the suffix of .txt in the current directory to 777

答:(1)find ./ -type f -name "*.txt" |xargs chmod 777

(2)find ./ -type f -name "*.txt" -exec chmod 777 {} ;

27. A script may run for more than 2 days. How can I make it run uninterrupted and observe the output information of the script at any time?

A: Use the screen tool

28. How to capture packets according to the following requirements under Linux system: only filter out access to http service, the target IP is 192.168.0.111, capture a total of 1000 packets, and save them in the 1.cap file?

答:tcpdump -nn -s0 host 192.168.0.111 and port 80 -c 1000 -w 1.cap

29. When rsync synchronizes data, how to filter out all .txt files that are not synchronized?

Answer: Add the --exclude option: --exclude="*.txt"

30. When rsync synchronizes data, if the target file is newer than the source file, the file will be ignored, what should I do?

A: To keep updates use the -u or --update option

31. I want to visit a website under the Linux command line, and the domain name of the website has not been resolved, how to do it?

Answer: Add a resolution record from the website domain name to its IP in the /etc/hosts file, or use curl -x

32. When custom resolution domain name, which file can we edit? Can one IP correspond to multiple domain names? Does one domain name correspond to multiple IPs?

Answer: Edit /etc/hosts, one ip can correspond to multiple domain names, but one domain name cannot correspond to multiple ips

33. Which command can we use to view the historical load of the system (say two days ago)?

Answer: sar -q -f /var/log/sa/sa22 #View the system load on the 22nd

34. How to specify a dns server under Linux to resolve a domain name?

Answer: Use the dig command: dig @DNSip domain.com

Such as: dig @8.8.8.8 www.baidu.com# Use Google DNS to resolve Baidu

35. When using rsync to synchronize data, if we use the ssh method, and the sshd port of the target machine is not the default 22 port, how do we do it?

Answer: rsync "--rsh=ssh -p 10022" or rsync -e "ssh -p 10022"

36. During rsync synchronization, how to delete the extra data from the target data, that is, the files or directories that do not exist on the source but exist on the target?

Answer: Add the --delete option

37. When using free to view memory usage, which value represents the amount of memory that is really available?

Answer: The value of the second row of the free column

38. One day you suddenly find that the access speed of the company's website becomes very slow, what should you do?

(The server can log in, prompt: you can start from the system load and network card traffic)

Answer: You can start from two aspects: analyze the system load, use the w command or the uptime command to check the system load, if the load is high, use the top command to check the occupancy of CPU, MEM, etc., either the CPU is busy or the memory is not enough , if both are normal, use the sar command to analyze the network card traffic to see if it has been attacked. Once the cause of the problem is analyzed, take corresponding measures to solve it, such as deciding whether to kill some processes or prohibit some access.

39. When rsync uses the service mode, if we specify a password file, how much should the permissions of the password file be set to?

Answer: 600 or 400

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324887654&siteId=291194637