前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >跟我学 systemd

跟我学 systemd

作者头像
netkiller old
发布2018-03-05 15:58:42
7690
发布2018-03-05 15:58:42
举报
文章被收录于专栏:NetkillerNetkiller

跟我学 systemd

摘要

我的系列文档

Netkiller Architect 手札

Netkiller Developer 手札

Netkiller PHP 手札

Netkiller Python 手札

Netkiller Testing 手札

Netkiller Cryptography 手札

Netkiller Linux 手札

Netkiller Debian 手札

Netkiller CentOS 手札

Netkiller FreeBSD 手札

Netkiller Shell 手札

Netkiller Security 手札

Netkiller Web 手札

Netkiller Monitoring 手札

Netkiller Storage 手札

Netkiller Mail 手札

Netkiller Docbook 手札

Netkiller Project 手札

Netkiller Database 手札

Netkiller PostgreSQL 手札

Netkiller MySQL 手札

Netkiller NoSQL 手札

Netkiller LDAP 手札

Netkiller Network 手札

Netkiller Cisco IOS 手札

Netkiller H3C 手札

Netkiller Multimedia 手札

Netkiller Perl 手札

Netkiller Amateur Radio 手札

Netkiller DevOps 手札

您可以使用iBook阅读当前文档


目录

  • 1. 什么是 systemd
  • 2. why-为什么做
  • 3. systemd 是何时被采用的
  • 4. 那些系统使用 systemd
  • 5. system 是谁开发的
  • 6. 怎样编写systemd脚本
    • 6.1. Unit
    • 6.2. Service
    • 6.3. Install

1. 什么是 systemd

systemd是Linux电脑操作系统之下的一套中央化系统及设置管理程序(init软件),包括有守护进程、程序库跟应用软件,由Lennart Poettering带头开发。 其开发目标是提供更优秀的框架以表示系统服务间的依赖关系,并依此实现系统初始化时服务的并行启动,同时达到降低Shell的系统开销的效果,最终代替现在常用的System V与BSD风格init程序。

2. why-为什么做

与多数发行版使用的System V风格init相比,systemd采用了以下新技术:

  1. 采用Socket激活式与D-Bus激活式服务,以提高相互依赖的各服务的并行运行性能;
  2. 用cgroups代替进程ID来追踪进程,以此即使是两次fork之后生成的守护进程也不会脱离systemd的控制。

3. systemd 是何时被采用的

CentOS 7 开始系统默认使用 systemd,对于用户来说就是service被systemctl替代了。

4. 那些系统使用 systemd

基本上从 Redhat 派生出的Linux操作系统基本都切换到了 systemd,Ubuntu也采用了systemd

5. system 是谁开发的

由Lennart Poettering带头开发

6. 怎样编写systemd脚本

下面是一个启动tomcat的systemd脚本,以此脚本为例我带大家进入 systemd 的世界。

例 1. /usr/lib/systemd/system/tomcat.service

			####################################################
# Homepage: http://netkiller.github.io
# Author: netkiller<netkiller@msn.com>
# Script: https://github.com/oscm/shell
# Date: 2015-11-03
####################################################

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
After=syslog.target

[Service]
Type=forking

User=www
Group=www

#EnvironmentFile=/etc/sysconfig/tomcat
ExecStartPre="rm -rf /srv/apache-tomcat/logs/*"
ExecStart=/srv/apache-tomcat/bin/startup.sh
#ExecStartPost=

ExecStop=/srv/apache-tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target			

脚本安装到 /usr/lib/systemd/system/tomcat.service 下面

systemctl enable tomcat
systemctl start tomcat
systemctl stop tomcat
systemctl disable tomcat			

启用脚本的时候会创建一个符号链接

[neo@netkiller ~]# ll /etc/systemd/system/multi-user.target.wants/tomcat.service 
lrwxrwxrwx 1 root root 38 Nov  3 04:06 /etc/systemd/system/multi-user.target.wants/tomcat.service -> /usr/lib/systemd/system/tomcat.service			

6.1. Unit

Description 写一段文字描述该脚本

After 等待网络就绪后运行

6.2. Service

Type 启动类型

User, Group 运行 ExecStart 脚本的用户,相当于 su - user -c ExecStart

Environment 环境变量,EnvironmentFile 环境变量文件

ExecStartPre 开始之前运行的脚本,ExecStart 启动脚本, ExecStartPost 启动之后运行的脚本

ExecStop 停止脚本

6.3. Install

WantedBy=multi-user.target 安装到多用户模式

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2015-11-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Netkiller 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 跟我学 systemd
  • 1. 什么是 systemd
  • 2. why-为什么做
  • 3. systemd 是何时被采用的
  • 4. 那些系统使用 systemd
  • 5. system 是谁开发的
  • 6. 怎样编写systemd脚本
    • 6.1. Unit
      • 6.2. Service
        • 6.3. Install
        相关产品与服务
        云数据库 MySQL
        腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档