允许在 Ubuntu 17.10 上访问 Spring Boot Jar 的低级端口 [英] Allow low level port access for Spring Boot Jar on Ubuntu 17.10
问题描述
按照此处的说明,我从 Spring Boot 项目 (1.5.8) 制作了一个可执行 jar,以便将它作为服务运行(我想在端口 443
上运行它).如果我只是用 java -jar proj.jar
启动它,我会收到一个错误,说端口正在使用中,但是使用 sudo java -jar proj.jar
tomcat 可以启动并该网站有效.
Following the instructions here, I made an executable jar from my spring boot project (1.5.8) in order to run it as a service (I would like to run it on port 443
). If I just start it with java -jar proj.jar
I get an error saying the port is in use, but using sudo java -jar proj.jar
tomcat can start and the site works.
我尝试允许对 jar 的低级别端口访问,但我仍然收到错误消息.(sudo setcap CAP_NET_BIND_SERVICE=+eip/path/to/jar
或 setcap 'cap_net_bind_service=+ep'/path/to/jar
)
I tried to allow low level port access to the jar, but I still get the error. (sudo setcap CAP_NET_BIND_SERVICE=+eip /path/to/jar
or setcap 'cap_net_bind_service=+ep' /path/to/jar
)
如何为 jar/tomcat 提供低级端口访问权限,使其在 443 上运行并且我可以将其作为服务启动?
How can I give the jar/tomcat low level port access, so it runs on 443 and I could launch it as a service?
作为非 root 用户,我是这样安装 jar 的:
As a non root user, I installed the jar this way:
- 克隆了存储库
chmod +x ./mvnw
./mvnw package -Dmaven.test.skip=true
cd target
并制作 application.properties 并复制 keystore.jkssudo ln -s/home/user/projectname/target/proj-0.0.1-SNAPSHOT.jar/etc/init.d/projectname
sudo chmod +x/etc/init.d/projectname
sudo update-rc.d 项目名称默认值
sudo service projectname start
- Cloned the repo
chmod +x ./mvnw
./mvnw package -Dmaven.test.skip=true
cd target
and making application.protperties and copying keystore.jkssudo ln -s /home/user/projectname/target/proj-0.0.1-SNAPSHOT.jar /etc/init.d/projectname
sudo chmod +x /etc/init.d/projectname
sudo update-rc.d projectname defaults
sudo service projectname start
检查日志文件,我可以看到错误,但正如我所提到的,如果我使用 sudo 启动 jar,它会起作用.
Checking the logging file, I can see the error, but as I mentioned, If I start the jar using sudo it works.
配置为侦听端口 443 的 Tomcat 连接器启动失败.端口可能已在使用中,或者连接器可能配置错误.
推荐答案
我希望有人能给我一个更好的答案,但如果我直接向 Java 添加低级端口访问(我安装了 oracle),我可以启动 jar.:<代码>须藤 setcap CAP_NET_BIND_SERVICE=+eip/usr/lib/jvm/java-8-oracle/jre/bin/java我想你可以试试.:<代码>须藤 setcap CAP_NET_BIND_SERVICE=+eip/usr/lib/jvm/java-8-oracle/bin/java
I hope someone can give me a better answer, but I could start the jar If I added low level port access directly to Java (I had oracle installed).:
sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/lib/jvm/java-8-oracle/jre/bin/java
I guess you could try.:
sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/lib/jvm/java-8-oracle/bin/java
应该也适用于 OpenJDK,但具有不同的可执行位置,我使用以下方法检查我的:echo $PATH
Should work for OpenJDK too but with different executable locations, I check mine with.: echo $PATH
这篇关于允许在 Ubuntu 17.10 上访问 Spring Boot Jar 的低级端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!