You may be faced with the problem of using SSH or telent to telnet to a Linux server, running tasks that take a long time to complete, such as system backups, FTP transmissions, and so on. Typically, we open a remote terminal window for each of these tasks, because they take too long to execute. You must wait for them to finish, during which you cannot turn off the window or disconnect, if the network exception or other factors cause a sudden disconnect, the remote command will stop, you can only reconnect and then run, all by halves. I'm here to teach you how to use the screen command to avoid any of these problems.
Screen is a Full-screen window manager that can multiplex a physical terminal across multiple processes. Users can create multiple screen child sessions in a screens session, which is like manipulating a real telnet/ssh connection window in each one of the dialog (or child sessions).
1, use putty or similar SSH tool to log on to CentOS 7 server; Directly enter screen to see the hint "bash:screen: no command ..."; Check the car system has not installed screen;
2, if your CentOS system does not own screen, the installation method is as follows:
Yum Install screen
After the installation is successful, input screen will switch to another window, and you can switch back to the original command line interface via ctrl+a+d;
Create a screen session
Scenario : Need to download and install LNMP one-button installation package in CentOS 7;
1, first execute the following command screen-s Shapolang the above command means: New screen session, the name is Shapolang.
2, start installation LNMP,
A, perform wget--no-check-certificate https://api.sinas3.com/v1/SAE_lnmp/soft/lnmp1.2-full.tar.gz download installation package.
b, the implementation: TAR-XVF lnmp1.2-full.tar.gz decompression.
C, execution: CD lnmp1.2-full/Enter lnmp1.2 directory.
D, implementation:./install.sh for installation.
If the network dropped, you can reconnect, and then execute Screen-r Shapolang will see your Shapolang installation process.
Temporarily leave screen session
(but keep screen running LNMP one-click installation Package command)
In the SSH window, press the shortcut key: Ctrl + A (hold down CTRL, press A, then press D) to exit the session named Shapolang.
When you temporarily leave the screen session, the screen session does not stop because it is away, and the process that is running (such as compiling the LNMP one-click installation package) continues to run, and the benefit of screen is that you can perform multiple tasks in the same SSH window. If you open a new screen session, install Gitlab. You can also temporarily close the ssh window and do something else.
Re-read screen session
The above command can be read in SSH, and if you forget the name of the screen session that you created earlier or if there are multiple sessions with the same name at the time you created it, you may be able to query the screen session list information in progress by following the command.
1, through the screen name (such as the new Shapolang) read.
If there are multiple names with the same name, there will be a session id+ session name, such as 4054.shapolang, before the session name;
The specified session can be obtained via screen-r 4054.shapolang or Screen-r 4054 (the latter is recommended, the first is more complex)
Close screen Session
If you no longer need the current screen session, you can execute exit in the current screen session, prompting [the ' is terminating] to indicate that the screen session has been closed successfully (not in memory) and, if necessary, rebuild.
Shortcut keys for screen
As mentioned earlier, CTRL + A D can temporarily leave the current screen session, while screen also provides additional shortcuts.
Ctrl + A C: Create a child session in the current screen session
Ctrl + A P: previous child session
Ctrl + A N: Next child session
The operation is very simple, but it is best not to create too many of the same name of the session itself is not clear, after all, the reply ID is not intuitive.