首页 > 其他分享 >gateway Failed to bind on [0.0.0.0:443]

gateway Failed to bind on [0.0.0.0:443]

时间:2023-12-28 14:56:15浏览次数:36  
标签:java 443 0.0 sudo springframework Failed SpringApplication org

1. 问题背景

  项目在做非docker容器部署,直接在宿主机上部署,gateway出现端口绑定失败的问题

Caused by: reactor.netty.ChannelBindException: Failed to bind on [0.0.0.0:443]
        Suppressed: java.lang.Exception: #block terminated with an error
                at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:139)
                at reactor.core.publisher.Mono.block(Mono.java:1709)
                at reactor.netty.http.server.HttpServer.bindNow(HttpServer.java:133)
                at reactor.netty.http.server.HttpServer.bindNow(HttpServer.java:116)
                at org.springframework.boot.web.embedded.netty.NettyWebServer.startHttpServer(NettyWebServer.java:145)
                at org.springframework.boot.web.embedded.netty.NettyWebServer.start(NettyWebServer.java:99)
                at org.springframework.boot.web.reactive.context.WebServerManager.start(WebServerManager.java:54)
                at org.springframework.boot.web.reactive.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:40)
                at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182)
                at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53)
                at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360)
                at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158)
                at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122)
                at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:895)
                at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554)
                at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:62)
                at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:755)
                at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
                at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:402)
                at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
                at org.springframework.boot.SpringApplication.run(SpringApplication.java:1247)
                at org.springframework.boot.SpringApplication.run(SpringApplication.java:1236)
                at com.msxf.cc.gateway.GatewayApplication.main(GatewayApplication.java:30)
Caused by: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: 权限不够

  问题很明显:当前用户没有权限使用443端口

  在linux系统中普通用户使用的端口限制以该net.ipv4.ip_local_port_range参数为准,且端口下线不能小于默认值1024,这也是上述报错的原因

解决方式一:

  通过sudo命令普通用户提权来执行java -jar命令,此方式又延时出另一个问题

sudo: java:找不到命令

  sudo提权之后找不到java命令,登录root用户和当前普通用户分别执行java -version命令都是成功的,那么sudo之后为什么不行了呢

  查看sudo配置文件cat /etc/sudoers,可以看到sudo提权后的执行目录为:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin/

  那么我们只需要把java命令软链接到此目录下就行了

sudo ln -s /opt/jdk1.8.0_231/bin/java /usr/bin/
sudo ln -s /opt/jdk1.8.0_231/bin/javac /usr/bin/

  此时执行java -version,可以找到java命令

[finance@ecs-hostname-20230731037001 bin]$ sudo java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

  执行完上述操作之后,再次启动java服务。可以看到443端口绑定成功

 

解决方式二:

  配置路由转发,前提是服务要启用iptables,禁用firewalld

  并且保证net.ipv4.ip_forward = 1开启

  配置转发规则,这里我们使用 Iptables 来配置的转发规则,以实现端口转发到程序所在的端口。

  把443端口的请求转发到本机的10001端口

  iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 127.0.0.1:10001

解决方式三:

  使用authbind工具来实现普通用户绑定特权端口

  安装authbind: 

sudo apt-get update
sudo apt-get install authbind

  配置authbind允许普通用户绑定443端口

sudo touch /etc/authbind/byport/443
sudo chmod 500 /etc/authbind/byport/443
#test 为用户名
sudo chown test /etc/authbind/byport/443

  使用 authbind 运行指定程序

authbind --deep "java -jar xxx"

解决方式四:

  使用nginx代理,把443端口的请求转发到对应ip的8443端口

upstream gateway{
    server x.x.x.x:8443;
}

server {
    listen 443 ssl;
    server_name jstest2.cc.xinmzc.com;
    access_log  /var/log/nginx/index.access.log  main;
    error_log /var/log/nginx/index.error.log;
    ssl_certificate /etc/nginx/cert/ivr.pem;
    ssl_certificate_key /etc/nginx/cert/ivr.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ## send request back to apache ##
        
    location / {
        proxy_pass  https://gateway;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'Upgrade';
    }
}

推荐解决方式四,如果没有nginx,推荐使用方式一;不推荐使用方式二、三

标签:java,443,0.0,sudo,springframework,Failed,SpringApplication,org
From: https://www.cnblogs.com/banzhuandang/p/17929923.html

相关文章

  • Failed to convert value of type 'java.lang.String' to required type 'java.lang.L
    我测试的是一个接口接口里面没有任何参数怎么会报参数类型转换错误呢mad!!!!! 第二个接口就很蒙测了好久都是这个问题而且你打debug它不进这个接口并且你执行其他写好的接口它还是会报同样的错。。。。。。。。。。。。。。其实就是你代码的位置写错了应该写在pc......
  • ubuntu20.04最小化安装
    ubuntu20.04虚拟机安装镜像下载https://releases.ubuntu.com/focal/ubuntu-20.04.6-live-server-amd64.iso创建虚拟机执行安装过程选择系统语言配置键盘布局配置网络连接此处根据实际网络进行配置,本机VMware网络使用NAT模式,10.100.1.0/24,网关10.100.1.254无需代理......
  • k8s 安装kubesphere3.4.1 多次安装报错 Error from server (InternalError): Internal
    failed:[localhost](item={'ns':'kubesphere-system','kind':'users.iam.kubesphere.io','resource':'admin','release':'ks-core'})=>{"ansible_loop_var":"......
  • 问题1:Ubuntu执行`sudo apt install XXX`报错出现Failed to Fetch
    报错问题:解决方案:1.查看自己Ubuntu的版本:lsb_release-a(LSB是LinuxStandardBase(Linux标准库)的缩写, lsb_release命令 用来与具体Linux发行版相关的Linux标准库信息)获取版本号之后进入:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/2.进入网址......
  • rust call sqlite3 error: linking with `link.exe` failed: exit code: 1181
    rustcallsqlite3error:linkingwithlink.exefailed:exitcode:1181声明:本文禁止csdn.net及所有所有子网站转载。禁止以营利性为目的的转载。报错error:linkingwith`link.exe`failed:exitcode:1181......
  • jenkins运行任务报错Failed to initialize解决
    按照jenkins中文挂网创建了一个创建HelloWorld流水线,使用的示例为Node.js/JavaScript运行jenkins任务后,提示失败,然后在consoleoutput里发现以下错误信息Failedtoinitialize:unabletoresolvedockerendpoint:openD:/ProgramFiles/Git/certs/client/ca.pem:nos......
  • Cisco Expressway Release X15.0.0 - 统一通信网关
    CiscoExpresswayReleaseX15.0.0-统一通信网关Expressway&ExpresswaySelect请访问原文链接:https://sysin.org/blog/cisco-expressway-15/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgCiscoExpressway系列让协作变得更简单CiscoExpressway可在保证......
  • jumpserver连接ecs实例报错:UNREACHABLE! => {"changed": false, "msg": "Failed to
     报错分析思路:1.是ssh密钥设置有没有对接2.防火墙拦截问题3.用户设置问题4.sshd配置问题 问题解决: 无法与221.229.216.39端口35846进行协商:找不到匹配的主机密钥类型。他们提供的是:ssh-rsa、ssh-dss[preauth]在sshd配置中加上ssh-rsa和ssh-dss是两种主机密钥算......
  • Windows下的Redis启动报错Redis service failed to start解决方法
    报错原因:Redis服务没有找到log文件解决方法在Redis安装目录下打开redis.windows-service.conf文件搜索logfile,找到logfile存放目录,一般默认为Logs/redis_log.txt在Redis安装目录创建Logs文件夹,在Logs文件夹下创建redis_log.txt文件重新启动即可解决......
  • Ubuntu 20.04 设置开机自启脚本启动java程序
    1)cp/lib/systemd/system/rc-local.service/etc/systemd/system2)修改/etc/systemd/system/rc-local.service,在该文件的最底部添加(可用vi/etc/systemd/system/rc-local.service命令)[Install]WantedBy=multi-user.targetAlias=rc-local.service3)创建/etc/rc.lcoal文件(vi/etc/rc.l......