常用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

 

posted @ 2020-08-23 03:21  JeromePowell  阅读(372)  评论(0编辑  收藏  举报