简体   繁体   English

如何部署 Netty 服务器?

[英]How to deploy a Netty Server?

I've developed a Netty application that allows connections through TCP from various devices.我开发了一个 Netty 应用程序,它允许从各种设备通过 TCP 进行连接。 However i'm not entirely sure what is the best way to deploy the application for production use.但是,我不完全确定部署应用程序以供生产使用的最佳方法是什么。 Right now i package it up in a JAR file and run a screen session on the target server like so:现在我将它打包在一个 JAR 文件中,并在目标服务器上运行一个屏幕会话,如下所示:

screen -S Nettyjava -jar  Server-Netty.jar

Is this the recommended way to deploy it or is screen the best option available?这是推荐的部署方式还是 screen 是可用的最佳选择?

screen is not the right tool to run a service in production.screen不是在生产中运行服务的正确工具。 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 .在大多数当前的 linux 发行版上,您可以使用systemd 服务单元文件来处理此问题。 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这允许您定义工作目录、用户、要运行的命令...这里是从 Unix 和 Linux StackExchange 问题配置 java 守护进程与 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

A good practice consists in creating a specific user for running the service and to restrain his right on the filesystem.一个好的做法是创建一个特定的用户来运行服务并限制他对文件系统的权利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM