Several situations of Linux automatically reboot without reboot logs in the /var/log/messages

Situation One

This Linux server is a virtual server. If we reboot it though its virtual software, there is no relevant logs in the /var/log/messages.

Situation Two

This Linux server is a member of a pacemaker cluster. If the pacemaker cluster software fences this server for protecting the whole cluster, there is no relate logs in the /var/log/messages.

Situation Three

This Linux server has critical problems in its system or hardware. Core panic of Linux and hardware problem both can reboot the system automatically without any reboot logs in the /var/log/messages.

[步骤] Linux 关机前执行脚本

步骤一:创建要被管理的脚本

# vim /root/12456.sh

创建以下内容:

#!/bin/bash
for i in {1..5}
do
echo $i
done

(补充:这里以创建 /etc/root/for.sh 脚本为例)

步骤二:创建 systemctl 的管理文件

# vim /etc/systemd/system/12456.service

创建以下内容:

[Unit]
Description=12345
After=getty@tty1.service display-manager.service plymouth-start.service
Before=systemd-poweroff.service systemd-halt.service
DefaultDependencies=no

[Service]
ExecStart=/root/12456.sh
Type=forking

[Install]
WantedBy=poweroff.target
WantedBy=reboot.target
WantedBy=halt.target

(补充:这里以创建 /etc/systemd/system/12456.service 来管理 ExecStart=/root/12456.sh 为例)

步骤三:加载刚刚创建的 systemctl 管理文件

# systemctl daemon-reload

步骤四:给 systemctl 的管理文件添加执行权限

# chmod u+x /etc/systemd/system/12456.service

步骤五:设置关机前执行脚本

5.1 设置关闭系统前执行此脚本

# ln -s /usr/lib/systemd/system/12456.service /usr/lib/systemd/system/halt.target.wants/

5.2 设置关闭电源前执行此脚本

# ln -s /usr/lib/systemd/system/12456.service /usr/lib/systemd/system/poweroff.target.wants/

5.3 设置重启先执行此脚本

# ln -s /usr/lib/systemd/system/12456.service /usr/lib/systemd/system/reboot.target.wants/

[命令] Linux 命令 gzip (打包、解包、压缩和解压文件或目录,压缩包以 xz 作为后缀)

内容一:gzip 命令简介

1.1 gzip 命令的格式

# gzip <option> <file>

1.2 gunzip 命令的常用选项

1) -c or –stdout, write on standard output, keep original files unchanged
2) -d or –decompress, decompress
3) -f or –force, force overwrite of output file and compress links
4) -h or –help, give this help
5) -k or –keep, keep (don’t delete) input files
6) -l or –list, list compressed file contents
7) -n or –no-name, do not save or restore the original name and timestamp
8) -N or –name, save or restore the original name and timestamp
9) -q or –quiet, suppress all warnings
10) -r or –recursive or –rsyncable, operate recursively on directories
11) -t or –test, test compressed file integrity
12) -1 or –fast, compress faster
13) -9 or –best, compress better

内容二:gzip 命令的使用案例

2.1 案例一:压缩文件

# gzip test.txt

(补充:这里以压缩文件 test.txt 为例)

2.2 案例二:解压文件

# gzip -d test.txt.xz

(补充:这里以解压文件 test.txt.zx 为例)

[命令] Linux 命令 gunzip (打包、解包、压缩和解压文件或目录,压缩包以 xz 作为后缀)

内容一:gunzip 命令简介

1.1 gunzip 命令的格式

# gunzip <option> <file>

1.2 gunzip 命令的常用选项

1) -c or –stdout, write on standard output, keep original files unchanged
2) -d or –decompress, decompress
3) -f or –force, force overwrite of output file and compress links
4) -h or –help, give this help
5) -k or –keep, keep (don’t delete) input files
6) -l or –list, list compressed file contents
7) -n or –no-name, do not save or restore the original name and timestamp
8) -N or –name, save or restore the original name and timestamp
9) -q or –quiet, suppress all warnings
10) -r or –recursive or –rsyncable, operate recursively on directories
11) -t or –test, test compressed file integrity
12) -1 or –fast, compress faster
13) -9 or –best, compress better

内容二:gunzip 命令的使用案例

2.1 案例一:压缩文件

# gunzip test.txt

(补充:这里以压缩文件 test.txt 为例)

2.2 案例二:解压文件

# gunzip -d test.txt.xz

(补充:这里以解压文件 test.txt.zx 为例)