惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 至尊龙骑

C# 使用FFmpeg 命令录音录像时设置 水印以及水印位置 C# 使用FFmpeg 命令 水印以及水印位置 录音录像时设置分辨率-分辨率一般是宽高比是 4:3 和16:9 少数是 5:4 FFmpeg 命令 水印以及水印位置 FFmpeg 命令录音录像时分辨率 FFmpeg 查看分辨率以及指定分辨率 C# 中监听 IPv6 回环地址----HttpListener C# 中监听 IPv6 回环地址(Loopback Address)----socket和tcp IPv6 地址 后端设置了跨域但是还是提示跨域问题,原因是这里有两个独立的安全策略在起作用:Chrome和Edge浏览器安全策略强制修改方案 开放所有跨域 ----前端和后端 Win11 上遇到的 WinForm 文件拖拽功能失效,但在 Win10 或其他系统上正常的问题 设置iis的后缀名可以下载 linux执行systemctl enable redis.service 报 Failed to execute operation: Bad message linux redis 8.2.1软件开机启动redis.service与etc下的rc.local配置2种方式 Linux redis 8.2.1源码编译 Linux开机启动设置全攻略 Linux系统简单源码安装NGINX版本1.28.0 DistributedLock 实现.Net分布式锁 Windows 10\11 离线安装.NET Framework 3.5(包括.NET 2.0和3.0) - 至尊龙骑 跨域处理 utools无法搜索快捷方式和部分软件问题
Linux 设置nginx 以及java jar自启动
至尊龙骑 · 2025-09-11 · via 博客园 - 至尊龙骑

linux 设置nginx 自启动

sudo vim /etc/systemd/system/nginx.service
在文件中添加以下内容(根据你的JAR文件路径和用户需求进行调整)
[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
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

重新加载systemd,启用并启动你的服务:

sudo systemctl daemon-reload
sudo systemctl start nginx
sudo systemctl enable nginx

linux 设置java jar 自启动

在Linux系统中,要让Java的JAR文件自动启动,你可以通过几种方法来实现。以下是一些常见的方法:

1. 使用nohup和&

你可以在终端中使用nohup命令来运行你的JAR文件,并使用&将其置于后台运行。这样即使你关闭了终端,程序也会继续运行。

nohup java -jar your-application.jar &
2. 使用screen或tmux

screen或tmux是终端复用器,它们允许你启动一个或多个会话,并在这些会话中运行程序。即使你断开连接,会话也会继续运行。

首先,安装screen或tmux(如果尚未安装):

sudo apt-get install screen  # 对于Debian/Ubuntu
sudo yum install screen      # 对于CentOS/RHEL
sudo apt-get install tmux    # 对于Debian/Ubuntu
sudo yum install tmux        # 对于CentOS/RHEL
然后,使用以下命令启动一个新会话并运行你的JAR文件:

screen -S your-session-name -d -m java -jar your-application.jar
# 或者使用 tmux
tmux new -s your-session-name -d 'java -jar your-application.jar'
3. 使用systemd服务

对于更高级的自动启动和管理,你可以创建一个systemd服务。这样,你可以轻松地通过systemctl命令来启动、停止和管理你的服务。

创建一个新的服务文件:
sudo nano /etc/systemd/system/your-application.service
在文件中添加以下内容(根据你的JAR文件路径和用户需求进行调整):
[Unit]
Description=Your Java Application Service
After=network.target 
[Service]
User=your-user
ExecStart=/usr/bin/java -jar /path/to/your-application.jar
SuccessExitStatus=143
Restart=on-failure
Environment=JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 
[Install]
WantedBy=multi-user.target

重新加载systemd,启用并启动你的服务:
sudo systemctl daemon-reload
sudo systemctl enable your-application.service
sudo systemctl start your-application.service

4. 使用cron定时任务

如果你希望在特定时间自动启动JAR文件,可以使用cron定时任务。
编辑cron任务:
crontab -e
添加一行来指定任务在特定时间运行,例如每天凌晨1点:
0 1 * * * /usr/bin/java -jar /path/to/your-application.jar > /path/to/logfile.log 2>&1
确保根据你的实际路径和需求调整这些命令。这些方法中的每一种都可以帮助你实现在Linux上自动启动Java JAR文件的需求。选择最适合你的场景的方法。

posted @ 2025-09-11 13:02  至尊龙骑  阅读(17)  评论()    收藏  举报