如何部署 Netty 服务器?

How to deploy a Netty Server?

我开发了一个 Netty 应用程序,它允许从各种设备通过 TCP 进行连接。但是,我不完全确定部署应用程序以供生产使用的最佳方式是什么。现在我将它打包在一个 JAR 文件中,并且 运行 目标服务器上的屏幕会话如下所示:

screen -S Nettyjava -jar  Server-Netty.jar

这是推荐的部署方式还是屏幕是可用的最佳选项?

screen is not the right tool to run a service in production. If the system has to reboot, you will have to relaunch the service by hand. On most current linux distributions, you can handle this with a systemd service unit file. This allows you to define the working directory, the user, the command to run... Here is an example taken from the Unix & Linux StackExchange question configure java daemon with systemd

[Unit]
Description=Some job
After=network.target

[Service]
WorkingDirectory=/home/user/tmp/testout
SyslogIdentifier=SocketTest
ExecStart=/bin/sh -c "exec java -jar /home/user/programming/tests/java/core/SocketTest/SocketTest.jar"
User=dlt
Type=simple

[Install]
WantedBy=multi-user.target

一个好的做法是为 运行 服务创建一个特定的用户并限制他对文件系统的权利。