参考教程

http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html

项目地址

https://github.com/systemd/systemd

概述

Systemd 是 Linux 系统工具,用来启动守护进程,已成为大多数发行版的标准配置。
根据 linux 的传统,d 是守护进程 daemon 的缩写,systemd 的含义就是要守护整个系统进程。
使用了 Systemd 就不要使用 initd 了,Systemd 取代了 initd 成为了系统的第一个进程(PID 等于 1),其他进程都是它的子进程。

systemd 是 centos7 的默认包管理工具。在 centos7 下直接 yum 安装就好。
systemctl 是系统服务管理器命令,它实际上将 service 和 chkconfig 这两个命令组合到一起。

systemctl 常用命令

启动/重启服务

  1. systemctl start/restart xxx.service

启动 ambari 时,出现了两行提示:

  1. ambari-server.service is not a native service, redirecting to /sbin/chkconfig.
  2. Executing /sbin/chkconfig ambari-server on

这个提示没关系的,因为 syctemctl 本身就是 service 和 chkconfig 的组合。它是把这个任务交给 chkconfig 处理而已。

禁止/开机自启

  1. systemctl disable/enable xxx.service

查看当前服务的状态

  1. systemctl status xxx.service

查看所有已启动的服务

  1. systemctl list -units --type=service

查看所有开机自启的服务

  1. systemctl list-unit-files

注意,systemctl 并不能查看所有的开机自启服务的,比如 ambari 开机自启就不会显示出来。还是 is-enabled 比较准。

查看某个服务是否开机自启

  1. systemctl is-enabled xxx

安装

首先查看是否安装:

  1. systemctl --version

如果是 not found, 说明没有安装 systemed.
安装教程:https://www.cnblogs.com/boshen-hzb/p/6080343.html

yum 安装

systemd 是 centos7 的默认包管理工具。在 centos7 下直接 yum 安装就好。

  1. yum install systemd

编译安装

  • 下载

    1. wget http://www.freedesktop.org/software/systemd/systemd-214.tar.xz
  • 解压

  1. xz -d systemd-214.tar.xz
  2. tar -xvf systemd-214.tar
  • 安装环境准备
  1. yum -y install gcc intltool gperf glib2-devel libcap-devel xz-devel
  • 编译
  1. cd systemd-214
  2. ./configure
  3. make
  4. make install

安装遇到的问题

问题1

configure: error: ln doesn’t support —relative
办法,使用最新版本。

chkconfig

chkconfig命令检查、设置系统的各种服务。
可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。

  • 等级0表示:表示关机
  • 等级1表示:单用户模式
  • 等级2表示:无网络连接的多用户命令行模式
  • 等级3表示:有网络连接的多用户命令行模式
  • 等级4表示:不可用
  • 等级5表示:带图形界面的多用户模式
  • 等级6表示:重新启动
  1. chkconfig --list #列出所有的系统服务。
  2. chkconfig --add httpd #增加httpd服务。
  3. chkconfig --del httpd #删除httpd服务。
  4. chkconfig --level httpd 2345 on #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态。
  5. chkconfig --list #列出系统所有的服务启动情况。
  6. chkconfig --list mysqld #列出mysqld服务设置情况。
  7. chkconfig --level 35 mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭。
  8. # 这可以理解为开机自启了。
  9. chkconfig mysqld on #设定mysqld在各等级为on,“各等级”包括2、3、4、5等级。