🧑‍🏫
liualexiang
  • Introduction
  • Azure
    • AKS Basic
    • AKS Spark
    • AZ ACR SYNC
    • Azure CMI SDWAN
    • Azure LB DeepDive
      • Azure LB DeepDive
    • Azure Service Principal Basic
    • Azure Internal VM Network Connectivity
      • Azure Internal VM Network Connectivity
    • Azure Cli Build
    • Azure Vm Memory Monitor
  • Blockchain
    • BTC
  • CRISPR
    • 使用Parallel_Cluster提升CRISPA效率
  • OpenSource
    • ElasticSearch
      • ES Get Started
      • ES Search Query
      • Kibana 可视化
      • Logstash配置
    • Ansible 基础
    • Infra As Code
      • Pulumi Get Started
      • Terraform Basic
    • ZooKeeper 基础
    • RPC与REST
    • 使用Python申请大量内存测试
    • 使用TPC_DS产生压测数据
    • Superset
      • Superset部署手册
    • 代码扫描
    • Git
      • Git Basic
      • Github Action Basic
      • Gitlab与AzureAD集成
      • Gitbook 基础教程
    • K8S
      • enter_node
      • K8s X509 Client Cert
      • K8s Basic
      • K8s Oidc
      • Docker 基础
      • helm基础
      • K8S_Secrets管理
      • 深入了解K8S
      • 混沌工程
      • Istio
      • 生态
      • CRD开发
      • k8s网络
    • Cloud_Custodian
    • Jenkins Basic
    • Nginx
    • ETCD
    • 正则
    • VictoriaMetrics
    • Kafka
  • MySQL
    • MySQL 调优
  • Linux
    • SSH Tunnel 上网
    • 内存管理
    • 在Linux系统中通过LUKS加密磁盘
    • 量子计算 Basic
    • IO多路复用
    • Iptables
    • tmux和screen
    • Systemd
    • OS 基础
    • jq基础
    • yum
    • neovim
  • Web
    • Html Css
    • Web部署
    • 缓存
  • Programming
    • 算法
      • 返回list中最大生序子序列长度
    • Python技巧
      • Python的语法糖
      • Python常用装饰器
      • AsyncIO基础
      • 自动化测试pytest
      • python中的下划线
      • 面向对象
      • Python的坑
      • Python配置文件管理
      • HTTP Stream Response
      • Python项目管理
    • 设计模式
      • 设计模式
      • 面向对象的思想
      • 编程概念
    • Go
      • Go 基础
      • Go常用功能
      • 结构体入门
    • 前端
    • Vue
    • NodeJS
  • Math
    • 多项式插值法
  • Security
    • HTTP常见攻击
    • 加密与签名
    • RSA
    • ECDSA
  • Solidity
    • Solidity基础
    • Blockchain Testnet Faucet
  • Tools
    • 视频处理ffmpeg
    • IDE配置
    • iTerm2美化
    • 密码管理
    • FRP配置
    • 工具集
由 GitBook 提供支持
在本页
  • Systemd的进程管理文件可以存放在两个地方
  • 有关systemd 的配置
  • 有关日志
  1. Linux

Systemd

Systemd的进程管理文件可以存放在两个地方

  1. 存放在 /usr 路径下: /usr/lib/systemd/system/alertmanager.service;

  2. 存放在 /etc 路径下 /etc/systemd/system/prometheus.service;

如果两个路径冲突,那么以 /etc/路径下优先

示例:

wget https://github.com/prometheus/pushgateway/releases/download/v1.4.2/pushgateway-1.4.2.linux-amd64.tar.gz

tar zxvf pushgateway-1.4.2.linux-amd64.tar.gz

mv pushgateway-1.4.2.linux-amd64 /opt/
# create a user
useradd -s /sbin/nologin pushgateway -u 2000
chown -R pushgateway:pushgateway /opt/pushgateway-1.4.2.linux-amd64


# create systemd servcie
cat << EOF  > /usr/lib/systemd/system/pushgateway.service
[Unit]
Description=pushgateway
Wants=network-online.target
After=network-online.target

[Service]
User=pushgateway
Group=pushgateway
Type=simple
ExecStart=/opt/pushgateway-1.4.2.linux-amd64/pushgateway
Restart=on-failure

ExecReload=/bin/kill -HUP $MAINPID
KillMode=process

[Install]
WantedBy=multi-user.target

EOF

systemctl daemon-reload
systemctl enable pushgateway
systemctl start pushgateway

有关systemd 的配置

如果是一个shell程序,或者是一个前台的程序,当启动的时候,一直挂在前台,那么Type要使用 simple。如果本身是一个后台程序,那么Type 要使用 Forking。对于forking的程序,应该是会将进程挂到PID=1的进程里.

Install的位置,说明了会将 systemd 的启动脚本,放在 /etc/systemd/system/ 的那个路径下。而unit里的 wants 和 after,则说明是当计算机启动的时候,什么时候开始引导这个程序。

有关日志

在创建一个服务的时候,如果是simple类型的,默认会将日志输出到 stdout,如果我们想自定义让日志输出到某个文件中,可以借助于rsyslog服务来做。比如在systemd中,将 StandardOutput 以及StandardError 设置为 syslog,同时指定SyslogIdentifier 为服务名

cat /etc/systemd/system/xmr.service
[Unit]
Description=XMR Coin Mining

[Service]
Type=simple
ExecStart=/home/alex/xmrig
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=xmr
Restart=on-failure

LimitNOFILE=16384

[Install]
WantedBy=multi-user.target
Alias=xmr.service

然后创建 rsyslog配置文件,在配置文件中,判断日志写入的位置

cat /etc/rsyslog.d/22-xmr.conf 

if $programname == 'xmr' then /var/log/xmr.log
& stop

EOF
上一页tmux和screen下一页OS 基础

最后更新于1年前