Linux operation and maintenance engineer interview questions (1)

Linux operation and maintenance engineer interview questions (1)

I wish you all the best of luck in finding the job you want.
Continuous learning will not be eliminated.
The earth doesn't explode, we don't take holidays.
Opportunities are always reserved for those who are prepared.
Come on, hit the workers!

1 Execution order of aliases, internal commands, and external commands

Command execution search order: alias > internal command > external command;

That is, first check whether it is an alias, then check whether it is an internal command, and finally check whether it is an external command.

Expansion: What is an internal command? What are external commands?

Internal command: comes with the shell, and is provided in the form of a command
External command: there is a corresponding executable program file under the file system path

# 使用type命令判断是外部命令还是内部命令

[root@waluna ~]# type -a echo
echo is a shell builtin
echo is /usr/bin/echo	# echo 即为内部命令也为外部命令
[root@waluna ~]# type echo
echo is a shell builtin	# 内部命令显示结果
[root@waluna ~]# type vim
vim is /usr/bin/vim	# 外部命令会显示命令的路径

# 使用此命令后效果
[root@waluna ~]# vim 1.sh
[root@waluna ~]# type vim
vim is hashed (/usr/bin/vim) # 会显示为是hash,因为命令执行后会使用hash缓存在内存中,不会再次依次寻找环境变量的路径,可以直接执行,加速速度

2 Linux system startup process

Different operating systems and versions are different. The following uses centos 7 as an example.

The startup process is more complicated. The following is a brief description, and the details are shown in the figure below.

  1. UEFI or BIOS initialization, run POST power-on self-test;
  2. Load the hardware information of the BIOS and get the first boot device;
  3. Read the boot information of the boot loader (grub) of the first boot device MBR;
  4. Bootloader, centos 7 is grub2, load the configuration file for the loader:
  • /etc/grub.d/
    • /etc/default/grub
    • /boot/grub2/grub.cfg
  1. Load the initramfs driver module;
  2. load kernel options;
  3. Kernel initialization, centos7 uses systemd instead of init;
  4. Execute all units of initrd.target, including mounting /etc/fstab;
  5. Switch from the initramfs root file system to the disk root directory;
  6. systemd executes the default target configuration, configuration file /etc/systemd/system/default.target;
  7. systemd executes sysinit.target to initialize the system and basic.target to prepare the operating system;
  8. systemd starts the local and server services under multi-user.target;
  9. systemd executes /etc/rc.d/rc.local under multi-user.target;
  10. systemd executes getty.target and login service under multi-user.target;
  11. systemd executes the services required by graphical.

linux boot process

The pictures are from the Internet, there are slight errors, and are for reference only

3 Methods to Crack User Passwords

method one:

启动时任意键暂停启动
选择内核按e键进入编辑模式
将光标移动linux开始的行,添加内核参数rd.break # rd.break为打断正常启动
按 ctrl-x 启动
mount -o remount,rw /sysroot
chroot /sysroot
passwd root
# 如果SELinux是启用的,才需要执行下面操作,如查没有启动,不需要执行
touch /.autorelabel
exit
reboot

Method Two:

启动时任意键暂停启动
选择内核按e键进入编辑模式
将光标移动linux开始的行,改为将 ro 改为 rw init=/sysroot/bin/sh
按 ctrl-x 启动
chroot /sysroot
passwd root
# 如果SELinux是启用的,才需要执行下面操作,如查没有启动,不需要执行
touch /.autorelabel
exit
reboot

4 How to solve the forgotten grub password

If the root password is forgotten, and the grub password is also forgotten, you can enter the rescue mode and delete the password line in /mnt/sysimage/boot/grub/grub.confthe file , or directly modify the shadow file, delete the root password directly, and then you can use root to log in with an empty password .

Physical security is the premise of system security

5 What to do when the hard disk space is full, and how to find large files in the hard disk

First use to df -hcheck the usage of the hard disk and find out which partition is full;

Then go to the corresponding partition to use du -sh *or du -acheck which file takes up more space, usually the log file.

What should I do if no large files are found after using the above method?

Special case one:

When mounting, the directory with data will be overwritten. You need to use the df command to check the mounting status. After canceling the mounting, delete the large files in the original directory.

Special case two:

A large number of deleted files have not been released. Use lsof -n | grep deletedthe command to view the pids of the deleted files, and stop the corresponding process to release the deleted files and free up hard disk space.

The correct way to release large files:

cat /dev/null > /data/bigfile or > /data/bigfile but the latter is not universal, and some shells do not support >, such as
deleting rm -f /data/bigfile after releasing csh

Investigate the difference between du, df, ls -l commands:

ls -l checks the actual size of the file, du checks the actual size of the hard disk space occupied by the file, and df checks the actual size of the hard disk. The default metadata of the ext series is much smaller than that of the xfs file system.

In general, the display of du will be larger than that of ls -l, mainly because the display of du is an integer multiple of block.

Why there is 33M data before the file is generated, because the metadata of the default disk will also take up space.

6 The hard disk obviously has a lot of space, why can’t the file be stored

The reason is that the inode number of the partition is full, df -iyou can check the usage of the inode.

Generally, a large number of small files are generated and the inode number is exhausted. Delete these small files and release the inode number.

Too many soft links can also lead to inode exhaustion.

7 Process usage memory problem

7.1 Memory Leak: Memory Leak

It means that the program uses malloc or new to apply for a block of memory, but does not use free or delete to release the memory, resulting in this memory being occupied all the time.

7.2 Memory overflow: Memory Overflow

It means that the program has applied for 10M space, but writing more than 10M bytes of data in this space is overflow.

7.3 Out of memory: OOM

OOM is Out Of Memory, "the memory is used up", which is more common in java programs. The system will choose a process to kill it, and you will see a prompt similar to the following in the log messages:

Jul 10 10:20:30 kernel: Out of memory: Kill process 9527(java) score 88 or sacrifice child

When the JVM does not have enough memory to allocate space for the object and the garbage collector has no space to reclaim, it will throw this error, because the problem is not serious enough to be handled by the application.

reason:

  • Too little memory is allocated to the application: For example, the memory available to the virtual machine itself (generally specified by the VM parameter at startup) is too little.
  • The application uses too much, and it is not released when it is used up, which is wasted. At this time, it will cause memory leak or memory overflow.

The solution used:

  1. Limit the max heap of the java process, and reduce the number of workers in the java program, thereby reducing memory usage
  2. Add swap space to the system

8 The difference between process, thread and coroutine

definition:

(1) A process is an independent unit for resource allocation and scheduling by the system;

(2) A thread is the entity of a process and the basic unit of CPU scheduling and allocation;

(3) Coroutines, also known as micro-threads, have their own CPU context and are smaller execution units than threads, occupying less resources and high efficiency.

the difference:

(1) A program has at least one process, and a process has at least one thread;

(2) The division scale of threads is smaller than that of processes (resources are less than processes), making multi-threaded programs highly concurrency;

(3) The process has an independent memory unit during execution, and multiple threads share the memory, which greatly improves the operating efficiency of the program;

(4) Threads cannot be executed independently and must depend on processes.

process thread coroutine

9 Use the find command to find out the files ending with log in the /data directory for more than 15 days and delete them

find /data -type f -iname "*.log" -mtime +15 -exec rm -rf {
    
    } \;

10 The difference between su, su - and sudo

su username: Non-login switching, that is, the configuration file of the target user will not be read, and the current working directory will not be changed, that is, incomplete switching

su - username: login switch, it will read the configuration file of the target user, switch to your home directory, that is, completely switch

sudo is a permission management mechanism that depends on /etc/sudoers, which defines which user is authorized to execute what kind of management commands as an administrator. Format: sudo -u USERNAME COMMAND

When using su to switch users, you need to enter the password of the target user, and when using sudo to execute commands, you need to enter the password of the current user.

The above interview questions are just a personal summary. Write whatever you think of, without any order. If there is anything wrong with the writing, please comment and leave a message, and I will correct it in time.

Original link: Linux operation and maintenance engineer interview questions (1) .

Guess you like

Origin blog.csdn.net/qq_45520116/article/details/129105747