Centos restart command
Common shutdown and restart commands in Linux include shutdown, halt, reboot, and init, which can be used for shutdown and restart. However, the internal working process of each command is different, next we will introduce them one by one.
1. shutdown
The shutdown command is used to safely shut down the Linux system. It is very dangerous for some users to disable Linux by directly disconnecting the power supply. Because Linux and Windows run many processes in the background, forced shutdown may lead to data loss in the process, making the system unstable and even damaging hardware devices.
When the shutdown command is executed, the system notifies all logged-on users that the system will be shut down and the login Command will be frozen. That is, new users cannot log on to the system. You can use the shutdown command to directly shut down the system, delay the specified time before shutting down the system, and restart the system. If the system is shut down after a specified delay, the user can have time to store the files being processed and to close the opened programs.
Some parameters of the shutdown command are as follows:
[-T] specifies how long the system will be shut down
[-R] restart the system
[-K] does not actually shut down, but sends a warning signal to every logged-on user.
[-H] Shut down the system (halt)
The job of the shutdown command is to send a signal to the init program and require it to switch the Runlevel of the system ). The system running level includes:
Common CentOS interface parameters are as follows:
-Tsec: the number of seconds between sending a warning message and deleting the message before notifying init to execute a Run-level switch.
-K: The system is not really shut down, but a warning message is sent to each user.
-R: Shut down and restart the system.
-H: Shut down and stop the system.
-F: fsck is not required to check the disk after the disk is restarted.
-F: Force fsck to check the disk after restart
For example:
# Warn all users that the system will restart in 5 minutes
# Shutdown-r + 5 "Systemwillberebootin5minites, Pleasesaveyourwork ."
# Immediately shut down the system
# Shutdown-hnow
# Immediately restart the system and force the fsck to check the disk after the restart
# Shutdown-h-Fnow
0: Shut down the system
1: in single-user mode, if the-h or-r parameter is not specified for the shutdown command, the system will switch to this running level by default.
2: multi-user mode (NFS not supported)
3: multi-user mode (supporting NFS), which is usually used
5: multi-user mode (GUI Mode)
6. restart the system.
2. halt
Halt is the simplest shutdown command. It actually calls the shutdown-h command. When halt is executed, the application process is killed. After the file system writes, the kernel is stopped.
Some parameters of the halt command are as follows:
[-F] Force shutdown or restart without calling shutdown
[-I] disable all network interfaces before shutting down or restarting
[-P] poweroff is called upon shutdown. This option is the default option.
3. reboot
The reboot process is similar to that of halt. Its function is to restart and halt is to shut down. Its parameters are similar to those of halt.
4. init
Init is the ancestor of all processes, and its Process number is always 1. Init is used to switch the running level of the system. The switchover is completed immediately. The init0 command is used to immediately switch the system running level to 0, that is, shutdown. The init6 command is used to switch the system running level to 6, that is, restart.
In the CentOS interface switch issue, many people may be used to entering the character work mode for operations. So how do I switch to the character working mode? Below we will introduce three methods to enter the character work mode:
In the graphic environment, enable the terminal window to enter the character working mode. After the system starts, it directly enters the character working mode. Use remote login (Telnet or SSH) to enter the character working mode.
Virtual console
After you directly enter the character working mode when the system starts, the system provides multiple (6 by default) virtual consoles. Each virtual console can be used independently without affecting each other. You can use Alt + F1 ~ Alt + F6 switch between multiple virtual consoles. If you use the startx command to start the graphical environment on the CentOS page, you can use Ctrl + Alt + F1 ~ Ctrl + Alt + F6 switch character virtual terminal, use Ctrl + Alt + F7 to switch to the graphic interface.
Local logon and logout
Login: Enter the user name (such as root) and password (pwd) on the logon terminal. Log out: You can enter the logout command on the current logon terminal or use the + shortcut key.
Log on to a remote Linux System Using ssh in a Linux environment. The ssh command in Linux is the client program of OpenSSH. To log on to a remote Linux system, make sure that the OpenSSH server is started on the remote Linux system. Use ssh
The command format for logging on to the remote OpenSSH server is $ username on the ssh remote host @ IP address or FQDN of the remote host
Go to the CentOS page and enter
The Linux system runs on a specified running level at any time, and different running-level programs and services are different. The work to be done and the purpose to be achieved are different. Centos sets the running level as shown in the following table, and the system can switch between these running levels to complete different tasks. Running description
0. All processes will be terminated, and the machine will be stopped in an orderly manner. when the machine is shut down, the system will be in this running level.
1. single-user mode. Used for system maintenance. Only a few processes run and all services are not started.
2-user mode. Like Level 3, the Network File System (NFS) service is not started.
3 multi-user mode. Allows multiple users to log on to the system, which is the default startup level of the system.
4 left to the user's custom running level
5-user mode. After the system is started, run X-Window to provide a graphical logon Window.
6. All processes are terminated and the system restarts.
1. if you enter the character logon CentOS page after the system starts, the default running level is 3. If you enter the graphical logon CentOS page after the system starts, the default running level is 5.
2. If you have enabled the CentOS page, you can run the following command to access the CentOS page:
$ Startx &
View and switch at run level
You can use the following command to view the running runlevel of the current system. You can use the following command to switch the running level init [0123456Ss], that is, the init command is followed by a parameter, this parameter is the runtime code to switch to, for example:
Use the init0 command to switch to the running level 0, that is, shutdown
Use the init1 command to switch to runlevel 1, that is, enter the single-user running mode
Use the init6 command to switch to running Level 6, that is, restart
You can also use the telinit command. In CentOS, The telinit command is the symbolic link of the init command.
The following is an example of using the runlevel and init commands:
# Display the current running level of the system
# Runlevel
N3
# The current running level of the system is "3", but the previous running level does not exist (represented by "N)
# Init2
# After the "init2" command is executed, the system console displays the information about stopping the service.
# Runlevel
32
# The current running level of the system is "2", the last running level is "3", and the conversion operation level is successful
You can also use the shutdown and restart command to go to The CentOS page.
When the system is shut down and restarted, the operation level is switched. You can use the init command to shut down and restart the instance. The init command is used to immediately shut down or restart the instance. However, in a multi-user system, if you want to send a shutdown warning to each user to complete their work and log out, you must use shutdown, halt, and reboot
.
In a multi-user environment, the shutdown command is usually used to close and restart the system. The shutdown command can shut down the system in a safer way. All users logging on to the system will be notified that the system will be shut down, and new Login operations will be blocked; at the same time, all processes will be notified that the system will shut down, so that some programs, such as vi, will be able to save the files edited by the user in time and exit.