参考:https://www.a5idc.net/helpview_888.html
Ubuntu在启动以后过一段时间大概20分钟左右会自动休眠,在另外一台主机使用脚本检测80端口可以看到多久休眠
禁用休眠前查看状态
systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target ● sleep.target - Sleep Loaded: loaded (/lib/systemd/system/sleep.target; static; vendor preset: enabled) Active: inactive (dead) Docs: man:systemd.special(7) 8月 24 18:00:40 hdy-desktop systemd[1]: Reached target Sleep. 8月 24 18:02:50 hdy-desktop systemd[1]: Stopped target Sleep. 8月 24 18:22:50 hdy-desktop systemd[1]: Reached target Sleep. 8月 25 08:37:14 hdy-desktop systemd[1]: Stopped target Sleep. 8月 25 08:57:15 hdy-desktop systemd[1]: Reached target Sleep. 8月 25 09:03:24 hdy-desktop systemd[1]: Stopped target Sleep. 8月 25 09:23:25 hdy-desktop systemd[1]: Reached target Sleep. 8月 25 09:29:05 hdy-desktop systemd[1]: Stopped target Sleep. ● suspend.target - Suspend Loaded: loaded (/lib/systemd/system/suspend.target; static; vendor preset: enabled) Active: inactive (dead) Docs: man:systemd.special(7) 8月 24 18:02:50 hdy-desktop systemd[1]: Reached target Suspend. 8月 24 18:02:50 hdy-desktop systemd[1]: Stopped target Suspend. 8月 25 08:37:14 hdy-desktop systemd[1]: Reached target Suspend. 8月 25 08:37:14 hdy-desktop systemd[1]: Stopped target Suspend. 8月 25 09:03:24 hdy-desktop systemd[1]: Reached target Suspend. 8月 25 09:03:24 hdy-desktop systemd[1]: Stopped target Suspend. 8月 25 09:29:05 hdy-desktop systemd[1]: Reached target Suspend. 8月 25 09:29:05 hdy-desktop systemd[1]: Stopped target Suspend. ● hibernate.target - Hibernate Loaded: loaded (/lib/systemd/system/hibernate.target; static; vendor preset: enabled) Active: inactive (dead) Docs: man:systemd.special(7) ● hybrid-sleep.target - Hybrid Suspend+Hibernate Loaded: loaded (/lib/systemd/system/hybrid-sleep.target; static; vendor preset: enabled) Active: inactive (dead) Docs: man:systemd.special(7)
禁止休眠
root@hdy-desktop:~# systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target Created symlink /etc/systemd/system/sleep.target → /dev/null. Created symlink /etc/systemd/system/suspend.target → /dev/null. Created symlink /etc/systemd/system/hibernate.target → /dev/null. Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.
再次查看状态,变成masked了
root@hdy-desktop:~# systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target ● sleep.target Loaded: masked (Reason: Unit sleep.target is masked.) Active: inactive (dead) 8月 24 18:00:40 hdy-desktop systemd[1]: Reached target Sleep. 8月 24 18:02:50 hdy-desktop systemd[1]: Stopped target Sleep. 8月 24 18:22:50 hdy-desktop systemd[1]: Reached target Sleep. 8月 25 08:37:14 hdy-desktop systemd[1]: Stopped target Sleep. 8月 25 08:57:15 hdy-desktop systemd[1]: Reached target Sleep. 8月 25 09:03:24 hdy-desktop systemd[1]: Stopped target Sleep. 8月 25 09:23:25 hdy-desktop systemd[1]: Reached target Sleep. 8月 25 09:29:05 hdy-desktop systemd[1]: Stopped target Sleep. ● suspend.target Loaded: masked (Reason: Unit suspend.target is masked.) Active: inactive (dead) 8月 24 18:02:50 hdy-desktop systemd[1]: Reached target Suspend. 8月 24 18:02:50 hdy-desktop systemd[1]: Stopped target Suspend. 8月 25 08:37:14 hdy-desktop systemd[1]: Reached target Suspend. 8月 25 08:37:14 hdy-desktop systemd[1]: Stopped target Suspend. 8月 25 09:03:24 hdy-desktop systemd[1]: Reached target Suspend. 8月 25 09:03:24 hdy-desktop systemd[1]: Stopped target Suspend. 8月 25 09:29:05 hdy-desktop systemd[1]: Reached target Suspend. 8月 25 09:29:05 hdy-desktop systemd[1]: Stopped target Suspend. ● hibernate.target Loaded: masked (Reason: Unit hibernate.target is masked.) Active: inactive (dead) ● hybrid-sleep.target Loaded: masked (Reason: Unit hybrid-sleep.target is masked.) Active: inactive (dead)
重启主机
reboot
再次查看
root@hdy-desktop:~# systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target ● sleep.target Loaded: masked (Reason: Unit sleep.target is masked.) Active: inactive (dead) ● suspend.target Loaded: masked (Reason: Unit suspend.target is masked.) Active: inactive (dead) ● hibernate.target Loaded: masked (Reason: Unit hibernate.target is masked.) Active: inactive (dead) ● hybrid-sleep.target Loaded: masked (Reason: Unit hybrid-sleep.target is masked.) Active: inactive (dead)
主机不在休眠了
重新启动休眠
systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
注意:改禁止休眠命令Ubuntu和Centos通用