• 常用systemd服务配置示例


    常用命令

    systemctl daemon-reload
    systemctl enable nginx.service
    systemctl status nginx.service
    systemctl stop nginxsy
    stemctl start nginx
    systemctl restart nginx
    journalctl -xe

    SSH

    # cat /usr/lib/systemd/system/sshd.service
    
    [Unit] # 系统服务描述及说明模块
    Description=OpenSSH server daemon # 描述性说明。
    Documentation=man:sshd(8) man:sshd_config(5) # 文档列表说明
    After=network.target sshd-keygen.service # 服务依赖类别说明
    Wants=sshd-keygen.service # 可选的依赖服务
    
    [Service] # 系统服务的运行参数设置模块
    Type=notify # 服务类型,可选有forking、notify、simple等
    EnvironmentFile=/etc/sysconfig/sshd # 环境变量等的配置文件
    ExecStart=/usr/sbin/sshd -D $OPTIONS # 服务的启动程序
    ExecReload=/bin/kill -HUP $MAINPID   # 重启程序
    KillMode=process
    Restart=on-failure
    RestartSec=42s
    
    [Install] # 服务安装的相关设置
    WantedBy=multi-user.target # 设置多用户级别。可为空格分隔的列表,表示在使用systemctl enable启用此单元时,将会在对应的目录设置对应文件的软连接

    Nginx

    [Unit]
    Description=nginx - high performance web server
    Documentation=http://nginx.org/en/docs/
    After=network-online.target remote-fs.target nss-lookup.target
    Wants=network-online.target
    
    [Service]
    Type=forking
    PIDFile=/var/run/nginx.pid
    ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s TERM $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    [Unit]
    Description=The NGINX HTTP and reverse proxy server
    After=syslog.target network.target remote-fs.target nss-lookup.target
    
    [Service]
    Type=forking
    PIDFile=/usr/local/nginx/logs/nginx.pid
    ExecStartPre=/usr/local/nginx/sbin/nginx -t
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    Maxwell
    # Maxwell systemd service file
    [Unit]
    Description=Maxwell Sync binlog
    After=network.target
    
    [Install]
    WantedBy=multi-user.target
    
    [Service]
    User=maxwell
    Group=maxwell
    Type=forking
    Environment="JAVA_HOME=/usr/local/jdk"
    ExecStartPre=/usr/bin/cd /maxwell
    WorkingDirectory=/data/server/maxwell
    ExecStart=/maxwell/bin/maxwell --daemon --config config.properties
    ExecReload=/bin/kill -s HUP $MAINPID 
    ExecStop=/bin/kill -s QUIT $MAINPID

    Copyright © 2021 Primzahl. All rights reserved.

  • 相关阅读:
    nc之二:nc命令详解
    memcache redundancy机制分析及思考
    memcache和redis区别
    java操作mongodb
    Memcache缓存与Mongodb数据库的优势和应用
    memcache 存储单个KEY,数据量过大的时候性能慢!以及简单的memcache不适合用到的场景
    pkill详解
    修改linux用户密码
    Mysql函数INSTR、LOCATE、POSITION VS LIKE
    Servlet3.0之九:web模块化
  • 原文地址:https://www.cnblogs.com/Primzahl/p/13548043.html
Copyright © 2020-2023  润新知