NipGeihou's blog NipGeihou's blog
  • Java

    • 开发规范
    • 进阶笔记
    • 微服务
    • 快速开始
    • 设计模式
  • 其他

    • Golang
    • Python
    • Drat
  • Redis
  • MongoDB
  • 数据结构与算法
  • 计算机网络
  • 应用

    • Grafana
    • Prometheus
  • 容器与编排

    • KubeSphere
    • Kubernetes
    • Docker Compose
    • Docker
  • 组网

    • TailScale
    • WireGuard
  • 密码生成器
  • 英文单词生成器
🍳烹饪
🧑‍💻关于
  • 分类
  • 标签
  • 归档

NipGeihou

我见青山多妩媚,料青山见我应如是
  • Java

    • 开发规范
    • 进阶笔记
    • 微服务
    • 快速开始
    • 设计模式
  • 其他

    • Golang
    • Python
    • Drat
  • Redis
  • MongoDB
  • 数据结构与算法
  • 计算机网络
  • 应用

    • Grafana
    • Prometheus
  • 容器与编排

    • KubeSphere
    • Kubernetes
    • Docker Compose
    • Docker
  • 组网

    • TailScale
    • WireGuard
  • 密码生成器
  • 英文单词生成器
🍳烹饪
🧑‍💻关于
  • 分类
  • 标签
  • 归档
  • Linux

    • CentOS

    • Ubuntu

    • 环境安装

    • 常用命令

      • 常用命令
      • 网络配置 - ip
      • 防火墙 - iptables
      • 防火墙 - ufw
      • 服务管理 - systemd
        • 常用命令
        • 创建服务
        • 模板
        • 参考
      • 数据包分析器 - tcpdump
      • 网络工具 - netstat
      • 路由追踪-traceroute
      • 编辑器 - Vim
      • 编辑器 - nano
      • 资源监控 - glances
      • 解压缩工具 - tar
      • 后台运行 - nohup
      • 删除命令 - rm
      • SSH密钥对 - ssh-keygen
      • 守护进程 - systemd(Systemctl)
      • 文件同步 - rsync
      • 路由追踪 - NextTrace
      • 虚拟终端 - screen
      • YAML处理器 - yq
    • 常用软件

    • 最佳实践

    • 通用

  • Docker

  • 云原生

  • Kubernetes

  • KubeSphere

  • K3S

  • 笔记

  • PVE

  • 维修

  • DevOps

  • 云服务

  • 路由器

  • Hyper-V

  • Windows

  • macOS

  • 运维
  • Linux
  • 常用命令
NipGeihou
2023-11-20
目录

服务管理 - systemd

systemd 是 Linux 操作系统的系统和服务管理器。在启动时作为第一个进程运行时 (如 PID 1),它充当启动和维护用户空间服务的 init 系统。

为已登录的用户启动单独的实例以启动他们的服务。

# 常用命令

# 服务列表
systemctl list-units

# timer服务列表(定时器)
systemctl list-timers

# 状态
systemctl status <unit名称>
# systemctl status sshd.service

# 停止
systemctl stop <unit名称>

# 启动
systemctl start <unit名称>

# 开启-开机启动
systemctl enable <unit名称>

# 禁用-开机启动
systemctl disable <unit名称>

# 重新加载配置
systemctl daemon-reload

# 查看完整日志
journalctl -u <unit名称>
# journalctl -u hello-world.service

# 创建服务

# 编辑服务配置
systemctl edit <unit名称>

# 服务配置存储位置
/etc/systemd/system # 存放自定义的
/lib/systemd/system # 标准的?  弹幕说这个是/usr/lib软链接的
/usr/lib/systemd/system # 通过包管理软件安装的

创建 Service 类型

# 查看service配置说明
man 5 systemd.service

vim /etc/systemd/system/hello-world.service

[Unit]
Description=ATD daemon
[Service]
Type=forking
ExecStart=/usr/bin/atd
[Install]
WantedBy=multi-user.target

创建 Timer 类型

# 查看timer配置说明
man 5 systemd.timer

vim /etc/systemd/system/hello-world.service

[Unit]
Description=My Service Timer

[Timer] # 每隔1分钟执行一次hello-world.service
OnUnitActiceSec=1min
Unit=hello-world.service

[Install]
WantedBy=timers.target

# 模板

nano /etc/systemd/system/name.service
[Unit]
Description=Quil Node
Wants=network-online.target
After=network-online.target

[Service]
WorkingDirectory=/root/ceremonyclient/node
ExecStart=/root/ceremonyclient/node/node-2.0.4.1-linux-amd64
StandardOutput=append:/root/ceremonyclient.log
Restart=always

[Install]
WantedBy=multi-user.target

# 参考

  • man systemd
  • Linux Systemd 完全入门 | 一个视频搞懂 systemd 的使用_哔哩哔哩_bilibili (opens new window)
  • How To Use Systemctl to Manage Systemd Services and Units | DigitalOcean (opens new window)
  • Systemd 入门教程:命令篇 - 阮一峰的网络日志 (opens new window)
上次更新: 2024/11/27, 12:04:53
防火墙 - ufw
数据包分析器 - tcpdump

← 防火墙 - ufw 数据包分析器 - tcpdump→

最近更新
01
Docker Swarm
04-18
02
安全隧道 - gost
04-17
03
Solana最佳实践
04-16
更多文章>
Theme by Vdoing | Copyright © 2018-2025 NipGeihou | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式