Reference https://www.ibm.com/developerworks/cn/linux/l-cn-sysrq/index.html
What is SYSRQ?
Do you encounter a server that cannot log in via SSH or log on through a local terminal, but can ping it, and the numeric keypad lock can also respond to keystroke operation? In this case, what else did you do besides pressing the power or reset key? Have you ever thought that this situation is likely to be restored? Have you ever thought about collecting more information to locate the reason why the system hangs? In this case, it can be called "interruptible system hangs". In other words, the system has stopped responding to most of the normal services for some reason, but the system can still respond to the keyboard's key interrupt request. In this case, a set of key combinations called SYSRQ will play its magical role.
SYSRQ is often referred to as the Magic System Request, which is defined as a series of key combinations. It is magical because it is able to perform a series of pre-defined system operations with key combinations when the system hangs and most services are unresponsive. through it, not only can the security of the disk data to restart a suspended server, to avoid data loss and restart after a long period of file system inspection, but also can collect including system memory usage, CPU task processing, process operation status and other system operation information, It may even be possible to retrieve a server that has stopped responding without restarting.
Enable SYSRQ
To enable the SYSRQ feature, you must first ensure that the kernel has joined CONFIG_MAGIC_SYSRQ support. In today's Linux distributions, no exception has been added to this feature's support, which is verified as follows:
grep " SysRq " /boot/config-3.10. 0-514.44. 5 . 10_33.x86_64config_magic_sysrq=ylinuxgrep"sysrq" /boot/config-'uname -R ' Config_magic_sysrq=y
Enabled via Sysctl
The SYSRQ feature is disabled by default on RHEL5U2. It can be enabled by proc the file system. Use the SYSCTL command to enable it and check its availability through/proc.
cat /proc/sys/kernel/sysrq0linux-yloidx:/var/run # sysctl-W kernel.sysrq=11linuxcat /proc/sys/kernel/sysrq1
KERNEL.SYSRQ can also accept enable parameters other than 0 and 1, please refer to the SYSRQ kernel documentation for details.
Keep it in effect after reboot
By setting the "KERNEL.SYSRQ = 1" To/etc/sysctl.conf, the SYSRQ will still take effect after the next system restart. Please note that in a non-RHEL system, it may be necessary to make it restart after a different configuration file, such as/usr/lib/sysctl.d/50-default.conf
Using SYSRQ
Online problem, asked in only Shell,init, halt, shutdown and other commands do not work in the case of how to restart the system. The answer is SYSRQ, which completes the system reboot through the sysrq–b.
The early SYSRQ only supported keyboard operations. To use SYSRQ, you must perform a keyboard operation directly on the host. To perform a sysrq-b to reboot the system, you can only do it via the direct keyboard operation Alt–sysrq–b (where B is only the B key, not case sensitive). A patch on the kernel 2.5.64 adds a/proc/sysrq-trigger interface that allows the user to perform SYSRQ operations via the/proc interface, in other words, the physical contact with the host keyboard is no longer present in most distributions built on the 2.6 kernel. Again is the necessary condition of SYSRQ. Users only need to log on to the system, they can use the echo "B" >/proc/sysrq-trigger to restart the system. In the following paragraphs, the concise,sysrq-<?> for the description represent alt-sysrq-<?> or echo "?" >/proc/sysrq-trigger.
As we all know, the system hangs a lot of time SSH login may not respond, in the absence of physical operating conditions for the host,/proc/sysrq-trigger also because unable to obtain the login shell and unable to operate. An open-source project called SYSRQD, which allows SYSRQ to be triggered directly over the network, appears. The program only 300 lines of code, listening to TCP Port 4094, through the custom password verification, you can operate on the/proc/sysrq-trigger. However, since this program is implemented in user space, the availability of the program and its security are widely questioned when the system hangs. In fact, if the service to do kernel space, in a similar response to ARP processing, coupled with a reasonable authentication method, perhaps most of the system hangs can play a more practical role. Of course, in the modern server Remote management module increasingly advanced premise, whether the network to trigger the SYSRQ seems to be not so important.
SYSRQ function key combination safe restart system
Most of the SYSRQ recommendations we've seen so far have been a secure restart after the system hangs, using this method to avoid data loss. This sysrq sequence is r-e-i-s-u-b. You know, this sequence existed as early as the SYSRQ first in the Linux implementation of the 2.1.43 kernel. It is basically equivalent to the reboot command, which stops the process running on the system sequentially, writes back the disk buffer, and then restarts the system safely. It should be noted that E will send a SIGTERM signal to all processes except init, which means that the program may take a certain amount of time to finish the process before finishing, depending on the system load and the number of tasks, which can take up to dozens of seconds. I send a non-capturing SIGKILL signal, relatively no more delay. Meanwhile, the two actions of S and U are all related to disk. When the system has a certain load, these two actions will not be completed immediately, but it will take a certain amount of time, usually a few seconds. So, the recommended way of r-e-i-s-u-b This sequence is: r–1 seconds –e–30 seconds –i–10 seconds –s–5 seconds –u–5 seconds –b, instead of one go to press these six keys, imagine a normal reboot command is not in the blink of an end Into it.
echo c > /proc/sysrq-trigger
' C ' is one of the pre-defined SYSRQ functions, triggering crashdump, producing kernel panic
One hour per day Linux (1)--sysrq