關閉開機啟動
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=

