Linux使用systemd管理pppd,Linux 系统的开机以及服务管理

66b52468c121889b900d4956032f1009.png

8种机械键盘轴体对比

本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?

systemd 是 Linux 系统中最新的初始化系统 (init), 它主要的设计目标是克服(但不是取代哦) sysvinit 固有的缺点,提高系统的启动速度。

systemd 创始人 Lennart 是 redhat 员工,但 systemd 不是 redhat 项目

systemd 的目标是:尽可能启动更少进程;尽可能将更多进程并行启动

systemd 像是一个小型操作系统一样,接管了系统初始化启动和进程服务管理等

systemd 在设计上很大借鉴了 Mac OSX 的 launchd

systemd 主要的对手是 upstart。从 Ubuntu 16.04 开始,Ubuntu 全面采用了 systemd

IBM 的刘明老师在其一篇2014年的博文中对 systemd 的特性有很好的讲解

service management in Linux

In Linux a service is just another name for a daemon, which is a client/server application that runs in the background. A service is continuously listening for incoming requests and sends a response based on the request given. A process is simply an application or a script which can be running in the foreground or the background.

文件夹 /etc/init.d

准确的来说Linux上的服务 (service) 应该叫守护进程 (Daemon), 这也是为什么Linux的服务程序后面都会加一个字母d(如httpd,sshd)。我们所有的服务(daemon),都是存放在 /etc/init.d 这个目录下。1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19README cups-browsed mountnfs.sh skeleton

acpid dbus mysql speech-dispatcher

alsa-utils dns-clean network-manager ssh

anacron grub-common networking sslh

apache-htcacheclean halt ondemand thermald

apache2 hostname.sh plymouth udev

apparmor hwclock.sh plymouth-log ufw

apport irqbalance pppd-dns umountfs

avahi-daemon kerneloops procps umountnfs.sh

binfmt-support keyboard-setup.dpkg-bak rc umountroot

bluetooth killprocs rc.local unattended-upgrades

bootmisc.sh kmod rcS urandom

brltty lightdm reboot uuidd

checkfs.sh lxcfs resolvconf virtualbox

checkroot-bootclean.sh mountall-bootclean.sh rsync vtun

checkroot.sh mountall.sh rsyslog whoopsie

console-setup mountdevsubfs.sh saned x11-common

cron mountkernfs.sh sendsigs

cups mountnfs-bootclean.sh single

systemctl command

systemd 的主要命令行工具是 systemctl。多数管理员应该都已经非常熟悉系统服务和 init系统的管理,比如 service、chkconfig 以及 telinit 命令的使用。systemd 也完成同样的管理任务,只是命令工具 systemctl 的语法有所不同而已,参考表格2来对比 systemctl 和传统的系统管理命令会非常清晰。

In the following, we take service apache2 as an example. The management of other services is similar.

Command systemctl provides the following management features for service: enable, start, stop, restart, reload, status.1/etc/init.d/apache2 start1

2

3

4

5

6

7

8

9

10

11

12To launch a service at boot time

systemctl service enable apache2

To start a service

systemctl service start apache2

To stop a service

systemctl service stop apache2

To restart a service

systemctl service restart apache2

To reload the configuration without restart the service

systemctl service reload apache2

#Check the running status of a service

systemctl service status apache2

service command

service 其实是 sysvinit 提供的命令,通过这个命令,就能实现对 /etc/init.d 里面所有程序进行状态管理。systemctl 是 Systemd 命令。

To start out you can check what services you currently have running by typing:1service --status-all

如果以1

2

3

4

5

6

7

8#服务的状态

service nginx status

#启动服务

service nginx start

#暂停服务

service nginx stop

#重启服务

service nginx restart

init 启动过程

611a7457cc8332bec50ac0615c4b1e91.png

rc*.d 目录和 /etc/rc.local文件

文件夹 /etc/rc.d下有七个运行级别的启动项配置,也就是七个rc*.d目录(注意: Ubuntu 16.04 下并没有 /etc/rc.d 这个文件夹,七个 rc*.d 直接位于 /etc 之下)。1

2

3

4rc0.d/ rc3.d/ rc6.d/ resolvconf/ rpc

rc1.d/ rc4.d/ rc.local resolv.conf rsyslog.conf

rc2.d/ rc5.d/ rcS.d/ rmt rsyslog.d/

这是一个开机之后会执行的初始化文件,它非常的好用。如果你有什么程序、脚本,想要让它 开机之后自动启动,那么只需要把想要执行的命令写入到这个文件中。例如:1

2#开机之后自动执行 iptables.sh 这个脚本 (这是一个自己定义的防火墙脚本)

bash ~/sh/iptables.sh

引入Systemd机制后,自Debian 9.0开始,系统中默认已不提供/etc/rc.local配置文件。

但是,提供rc.local.service或者rc-local.service,可以通过如下配置,继续使用/etc/rc.local实现系统启动时完成相关自动任务。https://wiki.deepin.io/mediawiki/index.php?title=基于Systemd的rc.local配置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值