1. Getting started and installing Linux

1.1. Relationship between VM, Linux, and host

The VM software is installed on the host, while the Linux software is installed on the VM.

1.2 installation of vm software and CentOS7.6

Official website of the VM software

CentOS7.6

Please check the installation steps:

Han teacher Linux_centos7.6 installation

1.3 Three ways of network connection

1. Bridge mode

  • If the bridge mode is used, the first three decimal digits of the IP address of the virtual system are the same as that of the host and the external host. Therefore, the virtual system can communicate with the external system, but IP address conflicts may occur.

2. NAT mode

  • If it’s NAT mode, it’s actuallyNetwork address translation mode. The last two digits of the IP address of the virtual system are different from that of the external host.However, it can also communicate with the outside world through the host agent (one-way) without causing IP conflicts.

3. Host mode

  • It’s essentially a separate system.

1.4 vm cloning

  1. Method 1: Copy a VM file.

  2. Method 2: Clone vmware. Note: To clone, you need to shut down the Linux system.

  • Create linked clones: Essentially, create a link to an existing virtual machine file that points to the same system.

  • Create a full clone: Create a full clone is actually a copy of the corresponding VM file.

1.5. Vm Snapshot

If you are using a virtual machine system (such as Linux) and you want to go back to a certain state, that is, you are worried that there may be some misoperation of the system, you need to go back to a certain state, vmware also provides this function, called snapshot management.

Examples of application

  1. After the system is installed, create snapshot A.
  2. After entering the system and making some changes (either by creating a new folder or installing some software), save snapshot B.
  3. throughThe snapshot managementState transitions can be made accordingly.

  1. Snapshots also take up a certain amount of memory.

1.6. Migrate and delete VMS

  • An installed virtual system is actually a file. Therefore, migrating and deleting a VM is actually copying and deleting virtual system files.
  • If you remove it in vmware, you only remove the reference, and you don’t really delete it until you delete the file.

1.7 VmTools installation

1. Vmtools functions

Vmtools allows you to better manage VMS in Windows. You can set Windows and centos shared folders.

2. Install VMTools

  1. Enter the centos
  2. Click on the VM menu – > Install vmware Tools
  3. Centos comes with a VM installation package, xx.tar.gz
  4. Copy the file to the /opt directory
  5. Use the decompression command to extract an installation file
  • cd /opt [The opt directory is displayed]
  • tar -zxvf xx.tar.gz Unpack the command
  1. Go to the /opt directory where the VM is decompressedcd /vmware-tools-distrib
  2. The installation./vmware-install.pl
  3. Then all the default Settings can be installed successfully
  4. Note: GCC is required to install VMTools.

3. Set the shared folder

2. Directory structure

2.1 Introduction to directory structure

  • The Linux file system isThe hierarchical tree directory structure is adopted.At the top of this structure is the /And then create other directories under this directory.
  • In the Linux world,Everything is a document. (Hardware is also mapped to a file for management).

2.2. Detailed description of the catalog

  1. Bin: short for Binary, this directory houses the most frequently used commands.
  2. Sbin: S stands for Super User, which stores the system management program used by the system administrator.
  3. Home: the home directory for common users. In Linux, each user has his or her own directory, which is usually named after the user account.
  4. Root: This directory is the user directory of the system administrator, also known as the super permission user.
  5. Lib: the most basic dynamic connection shared library required for system startup. It is similar to the DLL file in Windows. Almost all applications need these shared libraries.
  6. Lost +found: This directory is usually empty and contains files when the system is shut down illegally.

Hidden in the graphical interface, we can view through the terminal command line.

  1. Etc: all configuration files and subdirectories required for system management.
  2. Usr: Many of the user’s applications and files reside in this directory, similar to the Program Files directory on Windows.

/usr/local: this is a directory to install additional software (software) for the host. It is usually installed by compiling source code.

  1. Boot: Stores some core files used to start Linux, including some connection files and image files.
  2. Proc: This is a virtual directory that is a map of system memory and is accessed to obtain system information (the directory cannot be moved).
  3. SRV: short for service. This directory stores data that needs to be extracted after the service is started (this directory cannot be moved).
  4. Sys: This is a big change from the Linux2.6 kernel. A new file system sysfs in the 2.6 kernel is installed in this directory (the directory cannot be moved).
  5. TMP: Directory for storing temporary files.
  6. Dev: Similar to Windows device manager, stores all hardware as files.
  7. Media: The Linux system automatically identifies certain devices, such as USB flash drives and CD/DVD-ROM drives. After identifying the devices, Linux will mount them to this directory.
  8. MNT: This directory is provided by the system to allow users to temporarily mount other file systems, we can mount external storage on MNT, and then enter the directory to view the contents inside.
  9. Opt: The directory for storing additional installation software (installation package) for the host. The default directory is empty.
  10. Var: This directory is used to store things that are constantly being expanded. It is customary to put frequently modified directories in this directory, including various everyday files
  11. Selinux [Sercurity-Enhanced Linux] : Selinux is a security subsystem that controls application access to specific files. Selinux has three self-configurable operating modes.

Maybe we don’t see this directory in our root directory because it is not enabled, so we can see it when enabled.

  1. Run: is a file required for the system to run. After the system restarts, the directory data will be generated again.

3. Remote login and remote file transfer

  • The Linux server is shared by the development team
  • Officially launched projects are running on the public network.
  • Therefore, programmers need to remotely log in to centos for project management or development.

3.1. Remote Login

Xshell is currently the best remote login to Linux operation software, smooth speed and perfect solution to the problem of Chinese garble, is currently the programmer’s preferred software.

3.2. Remote file transfer

Xftp is a powerful SFTP and FTP file transfer software based on Windows platform. With Xftp, Windows users can securely transfer files between UNIX/Linux and Windows PCS.

4. Vi and Vim

4.1 basic introduction

  • Linux comes with built-in vi and VIm text editors
  • Vim has the ability to write programs, which can be regarded as the enhanced version of VI. It can actively identify the correctness of syntax by font color, which is convenient for program design. Code completion, compilation, error jump and other convenient programming functions are particularly rich, widely used in programmers.

4.2 Introduction and conversion of the three modes

1. Introduction

  1. Normal mode: Open a document with Vim and enter normal mode directly. In this mode, you can use the up, down, left and right keys to move the cursor, you can use Delete characters or delete entire lines to process file content, and you can use Assign, Paste to process file data.
  2. Insert mode: Press I, I, O, O, A, A, R, R and any other letter to enter the edit mode. Generally speaking, press I. Press Esc to exit this mode and enter normal mode.
  3. Command line mode: Enter colon (:) or slash (/) to switch to the command line mode. In this mode, you can provide relevant instructions to complete the read. Actions such as saving, replacing, leaving vim, displaying line numbers, etc.
  • Wq: Save the configuration and exit
  • Q: quit
  • Q! : Forcibly exits and does not save

2. Mode conversion

4.3 Common shortcuts for VI and VIm

  • In normal mode, copy the current line: YY, copy the 5 lines down from the current line: 5YY, and paste (enter: P)

  • In normal mode, delete the current line: dd and delete the 5 lines down from the current line: 5DD

  • To find a word in a document: In command line mode, use the: / keyword, press Enter, and type n to find the next location (if you want to find something else, just use the slash keyword).

  • Set the line number of the file: in command line mode: set nu, cancel the line number of the file: set nonu

  • Edit the /etc/profile file. The last line of the file is G and the first line is gg.

  • Type “hello” in a file. The shortcut for undoing it is U.

  • Edit /etc/profile, enter: 20, then: shift+g [in normal mode]

5. Shutdown, restart and user management

5.1 shut down and restart

  1. shutdown -h now: Shut down immediately.
  2. shutdown -h 1: Set the power off after 1 minute
  3. shutdown -r now: Restart immediately
  4. halt: turn it off
  5. reboot: Restart immediately
  6. sync: Synchronizes memory data to disks.
  • Han reminds us that whether we reboot or shut down the system,It is best to run sync first, writes the data in memory to disk. Although the current shutdown/reboot/haltAnd other commands have been automatically synchronized before the shutdown.

5.2 Log out and switch users

1. Basic introduction

  • When you log in, use the root account less, because it is the system administrator, the largest permission, to avoid errors. You can log in as a common user and use it after loginSu - User name to switchCommand to switch to system administrator status
  • Enter at the promptlogoutUsers can be logged out.

2. Pay attention to

  • Logout The logout command is not valid at the graphical run level and is valid at run level 3 (non-graphical)

3. Special instructions

After logging in to root as a common user, run logout to logout as a common user, and then run logout to exit the system.

5.3. Add a User

  • Linux is a multi-user and multi-task operating system. Any user who wants to use system resources must apply for an account from the system administrator and use the account to access the system.

  • Add a user command: useradd + The name of the user to be created (go to /home/first and enter the command).

Pay attention to

  • After creation,A home directory with the same name as the user name is automatically createdThe default directory is /home/home.
  • Also throughUseradd -d Directory name New user nameTo specify a home directory for the newly created user.

5.4 Password related instructions

Command: passwd + user name

5.5. Delete a User

  • Instruction 1: userdel user name (delete the user, but keep the home directory).

  • Directive 2: userdel -r user name (delete user and home directory)

Pay attention to

  • If you want to delete a user, you need to be under root.
  • In most cases,Keep the home directories of relevant usersBecause it will retain some of the employee’s job information.

5.6. Query user Information

The basic grammar

Id + User name

5.7. Switch users

  • On Linux, if the current user has insufficient permissions, the user can passSu - User nameSwitch the command to the user with higher privileges.

Detail description

  • You do not need to enter a password to switch from a user with a higher permission to a user with a lower permission.
  • When you need to return to the original user, use the exit/logout command.

5.8. View the current user

The basic grammar

who am i

5.9. User Groups

  • Similar to roles, the system canUsers with common rights can be managed in a unified manner.

Common commands

  • The new group:Groupadd group name
  • Delete the group:Groupdel group name
  • Add user group directly:Useradd -g User name of a user group
  • Modify the user group: ‘usermod -g User group user name

`

5.10 Files related to users and groups

  • /etc/passwd File: the configuration file of a user, which records various information about the user.The meanings of each line are as follows: User name: Password: User ID (UID) : Group ID (GID) : Description: Home directory: Login Shell

  • /etc/shadowFile: configuration file of the password.The meaning of each line is as follows: Login Name: Encrypted password: Last modified time: Min interval: Max interval: Warning time: Inactive time: Invalid time: flag

  • /etc/groupFile: a configuration file for a group, which records information about groups contained in Linux.The meanings of each line are as follows: Group name: password: Group ID: List of users in the group

6. Run level introduction

  • 0: turn it off
  • 1: single user (can retrieve the lost password through single user)
  • 2: no network service is available in the multi-user state
  • 3: The network service is available in the multi-user state
  • 4: The system is not in use
  • 5: Graphical interface
  • 6: The system restarts

Common runlevels are 3 and 5, but you can also specify a default runlevel.

  • Switching runlevel instructions:Init The runlevel to switch.
  • To view the current runlevel directive:systemctl get-default.

Before CentOS7

We set the default runlevel in /etc/inittab

After CentOS7

  • Multi-user. Target is equivalent to the original analogous to Runlevel 3

  • Target is equivalent to the original analogous to Runlevel 5

  • There is also a new command to switch the run level: systemctl set-default New to switch to the run level

7. Retrieve your password

  1. First, start the system, enter the boot interface, press in the interface"E"The edit page is displayed.

  1. Enter the edit screen, use the up and down keys on the keyboard to move down,Find “number of lines starting with Linux16”At the end of the line type:init=/bin/sh.
  2. Then, after typing, press the shortcut key directly:ctrl + xThe single user mode is displayed.

  1. Next, type in the blinking position of the cursor:Mount -o remount, RW /(Note the space between each word), then press enter on the keyboard.
  2. Type passwd at the end of the new line, press Enter when finished, and enter the password again. After the password is successfully changed, the system displays passwd… Is displayed, indicating that the modification is successful.
  3. Next, type in the blinking mouse position:Touch /. Autorelabel (note: there is a space between touch and /)When finished, press enter on the keyboard
  4. Continue typing at the blinking position:Exec /sbin/init (note: there is a space after exec and /)Press Enter and wait until the system automatically changes the password. This process may take a bit longer please be patient.The system automatically restarts and the new password takes effect.

8. Help instructions

1. Main Obtain help information

Instruction: main [command or configuration file]

For example, view the help information of the ls command: main ls

2. Help Obtain help information about shell built-in commands

Command: help command