Article Title: Tips: Use a comport to manage Linux servers. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
This article briefly introduces how to use common COM ports to expand the Linux server console, which is practical and simple and not subject to server network conditions, you can easily manage Linux servers in a production environment.
Speaking of Linux Server Management, there are many different methods: keyboard + display, network login, WEB-based tools, graphics tools under X system, etc, these methods can be used on common servers or your PC servers without any problems. However, to manage a 24x7 server, make sure that the server can be managed directly and quickly under any circumstances, it's not that easy.
Compare the methods mentioned above:
X system graphics tools. This is of course a friendly interface, and the X system can also be extended to a remote network, but the network is not so reliable after all. If the server's network is paralyzed, what should you do if you need to solve the network problem remotely?
WEB-based tools. This method is also very user-friendly, such as webadmin. However, due to security issues, these tools will not be installed on really important servers. In addition, this method is also limited by the Network;
Log on through the network. This is a common method. Generally, the server opens the SSH service to trusted remote sites so that maintenance personnel can log on remotely for routine maintenance. This is safe, but unfortunately it is still based on the network, and of course it is also limited by the Network;
Keyboard + display. This is the safest way. I suggest using this safest way, but unfortunately this is also flawed, that is, many servers are not equipped with monitors and keyboards, it is only used to install the system. Once put into production, the display and Keyboard will no longer be used.
In fact, for UNIX/Linux servers, you can use the comport to expand the console of the system and manage the servers as another way.
The CONSOLE is the character output device of the system output management information. These management information is generated by the kernel, such as system logs and alarm information. In Linux, the default console is the keyboard and display, while some older SUN, HP, and IBM servers use a serial port to connect Text Terminal [1] (character terminals, such as the famous DEC VT100) as the console, this is also the method to be introduced this time.
Character terminals are widely used in the mainframe era. A mainframe is usually connected to many terminals, and each terminal has no processing capability. It simply uses a keyboard to input and output results from the screen, the processing process is completed by the mainframe. The character terminal screen is mostly black/white, and does not have the graphic display function. The Text Terminal introduced here is the same as that of the mainframe Terminal, but there have been no new Terminal devices in the market. Now it is simulating a Terminal through an application, called a virtual Terminal, for example, a WINDOWS Super Terminal is a commonly used virtual terminal program. Opening a Super Terminal on a management workstation (using the correct speed) is equivalent to a terminal.
This CONSOLE function is widely used through serial ports. For example, CISCO routers manage devices in this way. A small CONSOLE line is equivalent to a PC display and a keyboard, this undoubtedly saves the router a lot of unnecessary accessories, and in fact some CISCO devices are a PC, such as the CISCO PIX515 firewall, as long as you plug in a PCI graphics card to the PCI slot, connect to the display, when you press the switch of the PIX, you can see the startup information of a BX motherboard, Pentium II generation 350MHZ processor, and M memory computer. There is no difference between it and a general computer. After the PIX completes the self-check, the CONSOLE is switched to the CONSOLE port, and the CONSOLE port of the RJ45 interface is actually a comport, but the interface form is not a 9-pin D-port.
Now we can clarify what we need to do: Use the virtual terminal program of the management workstation to simulate a character terminal device and redirect the Linux CONSOLE to the virtual terminal through the comport form of the comport, to control the Linux server from a virtual terminal. The procedure is as follows:
1. Create a crossover line
A "null modem cable" and "null modem cable" are needed to connect the two computers with the comport. the literal translation is "Cross MODEM line", which is similar to the cross line of the network CABLE, this is used to "back-to-back" connect two DTE devices, both ends are 9-pin D-connector, respectively inserted into the management workstation and server COM port, in order to facilitate the identification is recommended to connect the first comport. This line can be made by yourself, or you can buy it in the computer city, the most convenient is that there is a CISCO standard CONSOLE line plus RJ45 to 9-pin D-connector adapter (part number 74-0495-01), can be used directly. For more information, see the following line sequence:
Txd and Rxd, CTS and RTS, GND And GND, DTR and DSR & DCD must be crossly used as a pin signal. DSR & DCD indicates that the two pins are connected together as one pin signal. For more information, see Serial-HOWTO [3].
2. Test connectivity
After connecting the management workstation to the server, you can simply test whether this line works. Create a connection with a super terminal on the management workstation. The connection speed is, 8 data bits, 1 Stop bits, no parity bits, and no hardware "Flow control "; echo '1'>/dev/ttyS0 (ROOT permission required) on the server, and check whether the number 1 is received in the management workstation Super Terminal. If yes, the connection is normal. If you cannot receive the signal, check whether the signal pins are correct on the server, run the "statserial/dev/ttyS0" command to view the status of the current serial port (when the CABLE peer is not connected to the management workstation or the DSR status is 0 when the line sequence is incorrect). The connection status is as follows:
3. Starting from POST
This is a function that many computers cannot implement, mainly depends on whether the motherboard BIOS supports. POST (Power On Self Test) is our common Self-check. We can see the basic information and check process of the system. Of course, there may also be error prompts and corresponding processing prompts, there are some types of server boards (such as INTEL original nlw.bx) that can redirect the POST to the comport, so that we can access a terminal to see the POST process on the comport, of course, you can also operate on a terminal without the need for a keyboard or display. Unfortunately, our motherboard generally does not support this function, but it does not matter. We can first set the BIOS parameter (Halt On is set to None) to ignore irrelevant error information, so that each system self-check passes smoothly, so that the system can smoothly enter the hard disk to start.
4. Redirect GRUB
Maybe you have several systems (such as FreeBSD) or a new kernel needs to be tested. You may want to use the comport to select the system and redirect GRUB to the comport. On the manual page of GRUB [4], we can see that it supports the seriral terminal. Add the following two lines before the first Title of the GRUB configuration file:
Serial -- unit = 0 -- speed = 38400
Terminal serial console
We can see the GRUB prompt information from the terminal connected to the comport. You can select the optical band through the top and bottom keys to correctly enter the various systems. LILO usage is similar. See the LILO manual page.
5. Redirect CONSOLE
To control the Linux server startup process, we need to pass some parameters to the Linux kernel. From serial-console [2], we can see that we only need to set console = ttyS0, 9600 to the kernel, you can achieve CONSOLE redirection to the serial port. Of course, the speed of 9600 is too slow. We can use the speed of 38400, so that the display speed is almost the same as the display speed at startup. My server uses GRUB, so the kernel statement in my/boot/grub/menu. lst file is as follows:
Restart the Linux server and open the Super Terminal. You can see the startup information on the display normally. You can also press the "I" key to enter the interactive startup mode, of course, you can easily input "Y" for file system detection after you accidentally kill the power supply. Is it easy to use? But how can I stop there after the system is started? It seems like Linux is stupid. I don't know how to log on to the system from here? Don't blame Linux. Let's Immediately explain why and how it works.
6. Enable ttyS0 Login
In fact, the information during Linux Startup is displayed by KERNEL. By default, after the startup is complete, init runs mingetty to provide 6 virtual terminals to log on to the system, this can be clearly seen in the/etc/inittab file. In fact, login has no relationship with the kernel. Therefore, if you only add parameters to the kernel so that it can perform interactive operations from the comport, it does not mean that you can log on to the system from the Super Terminal, we need to run another program that provides the login capability from the serial port. This program is agetty, which is a member of the util-Linux software package, you can refer to the man manual page for more information, which is also mentioned in other documents [1] [3. I added a line in the/etc/inittab file on the server as follows:
S0: 2345: respawn:/sbin/agetty-L 38400 ttyS0
In this way, we can log on to the system from the Super Terminal. It's easy to use.
7. Some experiences
There are also some tips and experiences to log on with ttyS0. My experience is as follows:
There are limits on the transmission distance of the comport, and the normal cable is only 15 meters of valid distance. We recommend that you use five twisted pair wires, which can be expanded to 50 meters and still operate normally;
You usually want to use root to log on from ttyS0, but this is not acceptable by default. We need to add this terminal to the file/etc/securetty, that is, the terminal ttyS0 is a secure terminal, you can use root to log on;
If the server is on for a long time, it is best to use exit to exit the terminal every time, because if it is not returned, the terminal may be unavailable due to input garbled characters when you log on again next time, inputting garbled characters at the logon prompt is irrelevant;
If you manage a 24x7 server in this way, you may find that pressing the carriage return on the terminal does not reflect any problems, there is a possibility that services such as NFS and sendmail cannot be started after the system is powered off and then started up, so it gets stuck there, which is especially common in the case of unstable power supply, so be sure to connect your Linux server to the UPS for uninterrupted power supply, or set the power-off in the system BIOS to stop starting the system (if it is not too important ), in this case, you only need to press the keyboard to restart or power down and restart again. Check what happened during the startup process. Generally, you only need to check the hard disk once;
If your ttyS0 is garbled and cannot be used, you can try to log on from the network and comment out the line ttyS0 in the/etc/inittab, run the "init q" command to stop the agetty started through inittab, then cancel the comments in/etc/inittab again, and run the "init q" command to start agetty again, it can be recovered without an accident.
Conclusion
At this point, we can easily manage the absence of monitors.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service