systemd 文件学习

1. redis

vim /etc/systemd/system/redis.service

bash 复制代码
[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
Type=forking
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
TimeoutStartSec=30
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target

2. nginx

vim /etc/systemd/system/nginx.service

bash 复制代码
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

3. java程序

以下程序依次依赖,需要按照顺序启动

程序1:

vim /etc/systemd/system/ifmscloud-auth.service

bash 复制代码
[Unit]
Description=IFMSCloud Auth Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/java/jdk1.8.0_391/bin/java -jar /root/jar/ifmscloud-auth.jar
ExecStop=/bin/kill $MAINPID
SuccessExitStatus=143
Restart=always
RestartSec=5
WorkingDirectory=/root/jar
StandardOutput=file:/var/log/ifmscloud/ifmscloud-auth.log
StandardError=file:/var/log/ifmscloud/ifmscloud-auth-error.log

[Install]
WantedBy=multi-user.target

程序2:

vim /etc/systemd/system/ifmscloud-upms-biz.service

bash 复制代码
[Unit]
Description=IFMSCloud UPMS Biz Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/java/jdk1.8.0_391/bin/java -jar /root/jar/ifmscloud-upms-biz.jar
SuccessExitStatus=143
Restart=always
RestartSec=5
WorkingDirectory=/root/jar
StandardOutput=file:/var/log/ifmscloud/ifmscloud-upms-biz.log
StandardError=file:/var/log/ifmscloud/ifmscloud-upms-biz-error.log
TimeoutStartSec=180
Requires=ifmscloud-auth.service
After=ifmscloud-auth.service

[Install]
WantedBy=multi-user.target

程序3:

vim /etc/systemd/system/ifmscloud-gateway.service

bash 复制代码
[Unit]
Description=IFMSCloud Gateway Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/java/jdk1.8.0_391/bin/java -jar /root/jar/ifmscloud-gateway.jar
SuccessExitStatus=143
Restart=always
RestartSec=5
WorkingDirectory=/root/jar
StandardOutput=file:/var/log/ifmscloud/ifmscloud-gateway.log
StandardError=file:/var/log/ifmscloud/ifmscloud-gateway-error.log
TimeoutStartSec=180
Requires=ifmscloud-auth.service ifmscloud-upms-biz.service
After=ifmscloud-auth.service ifmscloud-upms-biz.service

[Install]
WantedBy=multi-user.target

程序4:

vim /etc/systemd/system/ifmscloud-ocrm-biz.service

bash 复制代码
[Unit]
Description=IFMSCloud OCRM Biz Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/java/jdk1.8.0_391/bin/java -jar /root/jar/ifmscloud-ocrm-biz.jar
SuccessExitStatus=143
Restart=always
RestartSec=30
WorkingDirectory=/root/jar
StandardOutput=file:/var/log/ifmscloud/ifmscloud-ocrm-biz.log
StandardError=file:/var/log/ifmscloud/ifmscloud-ocrm-biz-error.log
TimeoutStartSec=180
Requires=ifmscloud-auth.service ifmscloud-upms-biz.service ifmscloud-gateway.service
After=ifmscloud-auth.service ifmscloud-upms-biz.service ifmscloud-gateway.service

[Install]
WantedBy=multi-user.target

4. nacos

vim /lib/systemd/system/nacos.service

bash 复制代码
[Unit]
Description=nacos
After=network.target

[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_391"
ExecStart=/usr/local/nacos/nacos/bin/startup.sh -m standalone
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/usr/local/nacos/nacos/bin/shutdown.sh
Restart=always
LimitNOFILE=65536
PrivateTmp=true

[Install]
WantedBy=multi-user.target

自动日志轮转: 使用logrotate工具来管理这些日志文件的大小、备份和压缩。创建一个/etc/logrotate.d/ifmscloud文件,内容如下:

bash 复制代码
/var/log/ifmscloud/ifmscloud-gateway*.log {
    daily
    rotate 7
    compress
    missingok
    notifempty
    copytruncate
}

这样就可以每天自动轮转日志,并保持最近7天的日志备份。

相关推荐
zjnlswd1 天前
C#学习笔记4
笔记·学习·c#
minglie11 天前
在linux环境烧录esp8266
学习
xqqxqxxq1 天前
AI Agent学习:MCP与工具生态:工具选择的挑战(李博杰《深入理解 AI Agent》4.3观后总结)
人工智能·学习
青山是哪个青山1 天前
LangChain 学习笔记(九):上下文与记忆
笔记·学习·langchain
KaKa_大王1 天前
关于秒杀项目的一些理解
java·学习
Z5998178411 天前
c#软件开发学习笔记--Modbus-TCP/UDP网口通讯
笔记·学习·c#
zyf1044161 天前
暑期实践日志 Day29:根据修改要求,进行视频字幕添加
学习·计算机网络·剪辑·暑期实践·课题任务
田径他爸来了1 天前
嵌入式学习第27天——线程(创建,执行,退出)
java·开发语言·学习
xqqxqxxq1 天前
AI Agent学习:打通真实世界:Agent 工具分类与设计原则(李博杰《深入理解 AI Agent》4.1 4.2观后总结)
学习·ai
TJHHH.1 天前
SQL注入学习总结
数据库·笔记·sql·学习·注入