ubuntu20优化开机启动

关闭开机启动

systemctl disable vmware-USBArbitrator.service

systemctl disable vmware.service

systemctl disable vmware-workstation-server.service

systemctl disable mysql.service

systemctl enable mysql.service

使用systemctl命令,systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起。

据说在CentOS7.0后,不再使用service,而是systemctl 。centos7.0是向下兼容的,也是可以用service

据说许多linux的distributions都已经转投systemd了,而ubuntu自从15.04版本以后都使用了systemd。Systemctl是一个systemd工具,主要负责控制systemd系统和服务管理器。

打开服务:sudo systemctl start foobar
关闭服务:sudo systemctl stop foobar
重启服务:sudo systemctl restart foobar
不中断正常功能下重新加载服务:sudo systemctl reload foobar
设置服务的开机自启动:sudo systemctl enable foobar
关闭服务的开机自启动:sudo systemctl disable foobar
查看活跃的单元:systemctl list-units
查看某个服务的状态:systemctl status foobar
查看已启动的服务列表: systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed

1。 查看开机启动时间

# systemd-analyze blame

5min 939ms networking.service
25.236s systemd-journal-flush.service
23.723s dev-sda13.device
17.206s plymouth-quit-wait.service
14.800s systemd-udevd.service

2. 优化networking.service

sudo gedit /lib/systemd/system/networking.service

将TimeoutStartSec设置为10s:TimeoutStartSec=10s

3。其他项优化

第一项为开机动画,用 mask 干掉 (要恢复使用 unmask) 

$ sudo systemctl mask plymouth-quit-wait.service

 第二项,延迟 apt-daily 服务

$ sudo systemctl edit apt-daily.timer

在打开的窗口填入如下内容 (这将把此服务,延迟到 boot 后的 15 到 45 分钟后再执行,并且每天只执行 1 次,详情可见 https://askubuntu.com/questions/800479/ubuntu-16-04-slow-boot-apt-daily-service)

sudo gedit /lib/systemd/system/apt-daily.timer

[Unit]
Description=Daily apt download activities

[Timer]
OnCalendar=*-*-* 6,18:00
RandomizedDelaySec=12h
Persistent=true

[Install]
WantedBy=timers.target

# apt-daily timer configuration override
[Timer]
OnBootSec=15min
OnUnitActiveSec=1d
AccuracySec=1h
RandomizedDelaySec=30min

第三项,直接 disable (要恢复使用 enable )

$ sudo systemctl disable NetworkManager-wait-online.service

第五项,systemd-journal-flush.service,更改 journal 记录方式 (详见:https://askubuntu.com/questions/1094389/what-is-the-use-of-systemd-journal-flush-service)

打开,

$ sudo vim /etc/systemd/journald.conf

修改如下,

复制代码
[Journal]
Storage=auto
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitIntervalSec=30s
#RateLimitBurst=1000
#SystemMaxUse=
#SystemKeepFree=
SystemMaxFileSize=1G
SystemMaxFiles=5
#RuntimeMaxUse=
#RuntimeKeepFree=
复制代码
原文地址:https://www.cnblogs.com/fengtai/p/12484227.html