From ec191d4914e648ee1c8c2c0fe467679cd4ab980d Mon Sep 17 00:00:00 2001 From: penghuster Date: Sat, 2 Sep 2017 17:36:46 +0800 Subject: [PATCH 1/2] Add files via upload --- ... Cleaning Up Your Linux Startup Process.md | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 translated/tech/20160518 Cleaning Up Your Linux Startup Process.md diff --git a/translated/tech/20160518 Cleaning Up Your Linux Startup Process.md b/translated/tech/20160518 Cleaning Up Your Linux Startup Process.md new file mode 100644 index 0000000000..c406431690 --- /dev/null +++ b/translated/tech/20160518 Cleaning Up Your Linux Startup Process.md @@ -0,0 +1,123 @@ +Linux 系统开机启动项清理 +======= +![Linux cleanup](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/banner-cleanup-startup.png?itok=dCcKwdoP "Clean up your startup process") + +一般情况下, Linux 发行版在开机启动时拉起所有的相关服务进程, 包括许多你可能无需使用的服务, 例如蓝牙bluetooth, Avahi, 调制解调管理器ModemManager, ppp-dns((LCTT 译注:此处作者笔误 ppp-dns 应该为 pppd-dns) 等服务进程, 用于哪里, 有何功能? + +systemd 提供了许多很好的工具, 用于查看系统启动情况, 控制系统启动工作. 该文章中将说明在 systemd 控制系统启动的过程中如何关闭一些令人讨厌cruft的进程。 + +###查看开机启动项 +在老式系统启动方式 systemV 中,在 /etc/init.d 中你能很容易看到服务进程是否被设置为开机启动项。Systemd 以不同的方式展现,可以使用如下命令罗列允许开机启动的服务进程。 +``` +$ systemctl list-unit-files --type=service | grep enabled +accounts-daemon.service enabled +anacron-resume.service enabled +anacron.service enabled +bluetooth.service enabled +brltty.service enabled +[...] +``` +在此列表中, 对我来说, 蓝牙服务是冗余项, 因为在该电脑上我不需要使用蓝牙功能, 故无需运行此服务. 下面的命令将停止该服务进程,并且使其开机不启动。 +``` +$ sudo systemctl stop bluetooth.service +$ sudo systemctl disable bluetooth.service +``` +你可以通过下面命令确定是否操作成功。 +``` +$ systemctl status bluetooth.service + bluetooth.service - Bluetooth service + Loaded: loaded (/lib/systemd/system/bluetooth.service; disabled; vendor preset: enabled) + Active: inactive (dead) + Docs: man:bluetoothd(8) +``` +一个开机不启动的服务进程仍然能够被另外一个服务进程启动。如果你真的想在任何情况下系统启动时都不启动该进程,你可以卸载该程序;若在不卸载程序的情况达到此效果,你可以执行如下命令在任何情况下阻止该进程开机启动。 +``` +$ sudo systemctl mask bluetooth.service + Created symlink from /etc/systemd/system/bluetooth.service to /dev/null. +``` +一旦你对禁止该进程启动的效果感到满意时,你也可以选择卸载该程序。 + +通过执行命令可以获得如下服务列表: +``` +$ systemctl list-unit-files --type=service +UNIT FILE STATE +accounts-daemon.service enabled +acpid.service disabled +alsa-restore.service static +alsa-utils.service masked +``` +你不能使能或使不能静态服务,因为静态服务是依赖于其他的进程,意味着其不能自启动。 + +###哪些服务能够禁止? + +如何知道你是否能够禁止某服务或需要何服务?它总是依赖于你的个性化需求。 + +这里有列出了几个服务进程的作用,所有服务进程都可以在发行版规范中找到,你也可以通过搜索方式查询起作用。 + +- accounts-daemon. 该服务存在潜在的安全威胁。它是账号服务的一部分,它被允许获得或操作用户账户信息。我不认为存在一个好的理由能使我允许这样的后台操作,所以我选择掩盖mask该服务进程。 +- avahi-daemon. 该服务用于零配置网络发现,使电脑极易发现网络中打印机或其他的主机,我总是使其开机不启动,并从未不习惯于此。 +- brltty.service. 该服务提供布莱叶盲文设备支持,例如布莱叶盲文显示器。 +- debug-shell.service. 该服务打开一个重要的安全漏洞(该服务提供了一个无密码的 root 用户用于帮助 systemd 问题的调试。),除非你正在使用该服务,否则永远不要启动服务。 +- ModemManager.service. 该服务是一个被 dbus 激活的守护进程,用于提供移动宽频broadband(2G/3G/4G)接口,如果你不需要该内置接口通过如蓝牙、USB 适配器等来连接手机,那么你也无需该服务。 +- pppd-dns.service. 该是一个计算机发展的遗物,如果你需要通过互联网打电话的话,保留它,否则掩盖mask它。 +- rtkit-daemon.service. 该服务听起来很可怕, 其发音与 rootkit 相似. 但是你需要该服务, 因为它是一个实时内核调度器real-time kernel scheduler. +- whoopsie.service. 该服务是 Ubuntu 错误报告服务. 它用于收集 Ubuntu 系统崩溃报告,并发送报告到 https://daisy.ubuntu.com. 你可以放心地禁止其启动, 或者永久的卸载它. +- wpa_supplicant.service. 该服务仅仅在 Wi-Fi 连接时需要. + +###系统启动bootup时发生什么? +systemd 提供了一些命令帮助调试系统开机启动问题. 该命令重演系统启动的消息打印. +``` +$ journalctl -b + +-- Logs begin at Mon 2016-05-09 06:18:11 PDT, +end at Mon 2016-05-09 10:17:01 PDT. -- +May 16 06:18:11 studio systemd-journal[289]: +Runtime journal (/run/log/journal/) is currently using 8.0M. +Maximum allowed usage is set to 157.2M. +Leaving at least 235.9M free (of currently available 1.5G of space). +Enforced usage limit is thus 157.2M. +[...] +``` +通过命令 `journalctl -b -1` 可以复审前一次启动, `journalctl -b -2` 可以复审倒数第2次启动, 以此类推. + +该命令打印出大量的信息. 你可能并不关注所有信息, 只是关注其中问题相关部分. 为此, 系统提供了几个过滤命令, 用于帮助你锁定目标. 让我们以进程号为 1 的进程为例, 该进程是所有其他进程的父进程. +``` +$ journalctl _PID=1 + +May 08 06:18:17 studio systemd[1]: Starting LSB: Raise network interfaces.... +May 08 06:18:17 studio systemd[1]: Started LSB: Raise network interfaces.. +May 08 06:18:17 studio systemd[1]: Reached target System Initialization. +May 08 06:18:17 studio systemd[1]: Started CUPS Scheduler. +May 08 06:18:17 studio systemd[1]: Listening on D-Bus System Message Bus Socket +May 08 06:18:17 studio systemd[1]: Listening on CUPS Scheduler. +[...] +``` +这些打印消息显示了什么被启动, 或者是正在尝试启动. + +一个最有用的命令工具之一 `systemd-analyze blame`, 用于帮助查看哪个服务进程启动耗时最长. +``` +$ systemd-analyze blame + 8.708s gpu-manager.service + 8.002s NetworkManager-wait-online.service + 5.791s mysql.service + 2.975s dev-sda3.device + 1.810s alsa-restore.service + 1.806s systemd-logind.service + 1.803s irqbalance.service + 1.800s lm-sensors.service + 1.800s grub-common.service +``` +这是一个没有任何异常的特殊样例, 但是如果存在系统启动瓶颈bottleneck, 则该命令将发现它. + +你也能了解 systemd 如何工作通过如下资源: +- [Understanding and Using Systemd](https://www.linux.com/learn/understanding-and-using-systemd) +- [Intro to Systemd Runlevels and Service Management Commands](https://www.linux.com/learn/intro-systemd-runlevels-and-service-management-commands) +- [Here We Go Again, Another Linux Init: Intro to systemd](https://www.linux.com/learn/here-we-go-again-another-linux-init-intro-systemd) + +via: https://www.linux.com/learn/cleaning-your-linux-startup-process + +作者:[David Both](https://www.linux.com/users/cschroder) +译者:[penghuster](https://github.com/penghuster) +校对:校对者ID + +本文由 LCTT 原创编译,Linux中国 荣誉推出 From 126374bb1a792f3344c1ab66e177eedbd933347b Mon Sep 17 00:00:00 2001 From: penghuster Date: Sat, 2 Sep 2017 17:45:50 +0800 Subject: [PATCH 2/2] Delete 20160518 Cleaning Up Your Linux Startup Process.md --- ... Cleaning Up Your Linux Startup Process.md | 166 ------------------ 1 file changed, 166 deletions(-) delete mode 100644 sources/tech/20160518 Cleaning Up Your Linux Startup Process.md diff --git a/sources/tech/20160518 Cleaning Up Your Linux Startup Process.md b/sources/tech/20160518 Cleaning Up Your Linux Startup Process.md deleted file mode 100644 index 47e7de1857..0000000000 --- a/sources/tech/20160518 Cleaning Up Your Linux Startup Process.md +++ /dev/null @@ -1,166 +0,0 @@ -penghuster apply for it - -Cleaning Up Your Linux Startup Process -============================================================ - -![Linux cleanup](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/banner-cleanup-startup.png?itok=dCcKwdoP "Clean up your startup process") -Learn how to clean up your Linux startup process.[Used with permission][1] - -The average general-purpose Linux distribution launches all kinds of stuff at startup, including a lot of services that don't need to be running. Bluetooth, Avahi, ModemManager, ppp-dns… What are these things, and who needs them? - -Systemd provides a lot of good tools for seeing what happens during your system startup, and controlling what starts at boot. In this article, I’ll show how to turn off startup cruft on Systemd distributions. - -### View Boot Services - -In the olden days, you could easily see which services were set to launch at boot by looking in /etc/init.d. Systemd does things differently. You can use the following incantation to list enabled boot services: - -``` -systemctl list-unit-files --type=service | grep enabled -accounts-daemon.service enabled -anacron-resume.service enabled -anacron.service enabled -bluetooth.service enabled -brltty.service enabled -[...] -``` - -And, there near the top is my personal nemesis: Bluetooth. I don't use it on my PC, and I don't need it running. The following commands stop it and then disable it from starting at boot: - -``` -$ sudo systemctl stop bluetooth.service -$ sudo systemctl disable bluetooth.service -``` - -You can confirm by checking the status: - -``` -$ systemctl status bluetooth.service - bluetooth.service - Bluetooth service - Loaded: loaded (/lib/systemd/system/bluetooth.service; disabled; vendor preset: enabled) - Active: inactive (dead) - Docs: man:bluetoothd(8) -``` - -A disabled service can be started by another service. If you really want it dead, without uninstalling it, then you can mask it to prevent it from starting under any circumstances: - -``` -$ sudo systemctl mask bluetooth.service - Created symlink from /etc/systemd/system/bluetooth.service to /dev/null. -``` - -Once you are satisfied that disabling a service has no bad side effects, you may elect to uninstall it. - -You can generate a list of all services: - -``` -$ systemctl list-unit-files --type=service -UNIT FILE STATE -accounts-daemon.service enabled -acpid.service disabled -alsa-restore.service static -alsa-utils.service masked -``` - -You cannot enable or disable static services, because these are dependencies of other systemd services and are not meant to run by themselves. - -### Can I Get Rid of These Services? - -How do you know what you need, and what you can safely disable? As always, that depends on your particular setup. - -Here is a sampling of services and what they are for. Many services are distro-specific, so have your distribution documentation handy (i.e., Google and Stack Overflow). - -* **accounts-daemon.service** is a potential security risk. It is part of AccountsService, which allows programs to get and manipulate user account information. I can't think of a good reason to allow this kind of behind-my-back operations, so I mask it. - -* **avahi-daemon.service** is supposed to provide zero-configuration network discovery, and make it super-easy to find printers and other hosts on your network. I always disable it and don't miss it. - -* **brltty.service** provides Braille device support, for example, Braille displays. - -* **debug-shell.service** opens a giant security hole and should never be enabled except when you are using it. This provides a password-less root shell to help with debugging systemd problems. - -* **ModemManager.service** is a DBus-activated daemon that controls mobile broadband (2G/3G/4G) interfaces. If you don't have a mobile broadband interface -- built-in, paired with a mobile phone via Bluetooth, or USB dongle -- you don't need this. - -* **pppd-dns.service** is a relic of the dim past. If you use dial-up Internet, keep it. Otherwise, you don't need it. - -* **rtkit-daemon.service** sounds scary, like rootkit, but you need it because it is the real-time kernel scheduler. - -* **whoopsie.service** is the Ubuntu error reporting service. It collects crash reports and sends them to [https://daisy.ubuntu.com][2]. You may safely disable it, or you can remove it permanently by uninstalling apport. - -* **wpa_supplicant.service** is necessary only if you use a Wi-Fi network interface. - -### What Happens During Bootup - -Systemd has some commands to help debug boot issues. This command replays all of your boot messages: - -``` -$ journalctl -b - --- Logs begin at Mon 2016-05-09 06:18:11 PDT, -end at Mon 2016-05-09 10:17:01 PDT. -- -May 16 06:18:11 studio systemd-journal[289]: -Runtime journal (/run/log/journal/) is currently using 8.0M. -Maximum allowed usage is set to 157.2M. -Leaving at least 235.9M free (of currently available 1.5G of space). -Enforced usage limit is thus 157.2M. -[...] -``` - -You can review previous boots with **journalctl -b -1**, which displays the previous startup;**journalctl -b -2** shows two boots ago, and so on. - -This spits out a giant amount of output, which is interesting but maybe not all that useful. It has several filters to help you find what you want. Let's look at PID 1, which is the parent process for all other processes: - -``` -$ journalctl _PID=1 - -May 08 06:18:17 studio systemd[1]: Starting LSB: Raise network interfaces.... -May 08 06:18:17 studio systemd[1]: Started LSB: Raise network interfaces.. -May 08 06:18:17 studio systemd[1]: Reached target System Initialization. -May 08 06:18:17 studio systemd[1]: Started CUPS Scheduler. -May 08 06:18:17 studio systemd[1]: Listening on D-Bus System Message Bus Socket -May 08 06:18:17 studio systemd[1]: Listening on CUPS Scheduler. -[...] -``` - -This shows what was started -- or attempted to start. - -One of the most useful tools is **systemd-analyze blame**, which shows which services are taking the longest to start up. - -``` -$ systemd-analyze blame - 8.708s gpu-manager.service - 8.002s NetworkManager-wait-online.service - 5.791s mysql.service - 2.975s dev-sda3.device - 1.810s alsa-restore.service - 1.806s systemd-logind.service - 1.803s irqbalance.service - 1.800s lm-sensors.service - 1.800s grub-common.service -``` - -This particular example doesn't show anything unusual, but if there is startup bottleneck, this command will find it. - -You may also find these previous Systemd how-tos useful: - -* [Understanding and Using Systemd][3] - -* [Intro to Systemd Runlevels and Service Management Commands][4] - -* [Here We Go Again, Another Linux Init: Intro to systemd][5] - --------------------------------------------------------------------------------- - -via: https://www.linux.com/learn/cleaning-your-linux-startup-process - -作者:[CARLA SCHRODER ][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/cschroder -[1]:https://www.linux.com/licenses/category/used-permission -[2]:https://daisy.ubuntu.com/ -[3]:https://www.linux.com/learn/understanding-and-using-systemd -[4]:https://www.linux.com/learn/intro-systemd-runlevels-and-service-management-commands -[5]:https://www.linux.com/learn/here-we-go-again-another-linux-init-intro-systemd -[6]:https://www.linux.com/files/images/banner-cleanup-startuppng