[Topic DIscussion] 管理员账号如何以知名端口号(比如80)启动服务? Resolved
Tofloor
poster avatar
wang3develop
deepin
2022-07-05 17:30
Author

我这里用的是JDK8u332,给管理员账号hxxx配置了用户环境变量(~/.bashrc)。

有试过以root方式启动,启动成功了,但是日志与相关信息输出的文件的路径都和程序位置不匹配了(不好找)。

我这里启动了数据库,启动了nacos等,以8688端口号启动服务正常跑起来了,但是以80端口号启动就失败,输出信息如下:

2022-07-03 17:52:04.431 [background-preinit] INFO  org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.1.7.Final

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.3.12.RELEASE)

2022-07-03 17:52:05.561 [main] INFO  cc.helik.shop.App - No active profile set, falling back to default profiles: default
2022-07-03 17:52:06.847 [main] INFO  o.springframework.cloud.context.scope.GenericScope - BeanFactory id=3a4bdc68-03d1-3622-90ea-1822035bb16d
2022-07-03 17:52:07.331 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.hibernate.validator.internal.constraintvalidators.bv.notempty.NotEmptyValidatorForCharSequence' of type [org.hibernate.validator.internal.constraintvalidators.bv.notempty.NotEmptyValidatorForCharSequence] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-07-03 17:52:07.341 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.hibernate.validator.internal.constraintvalidators.bv.NotNullValidator' of type [org.hibernate.validator.internal.constraintvalidators.bv.NotNullValidator] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-07-03 17:52:07.425 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'spring.cloud.sentinel-com.alibaba.cloud.sentinel.SentinelProperties' of type [com.alibaba.cloud.sentinel.SentinelProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-07-03 17:52:07.547 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration' of type [com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-07-03 17:52:07.557 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration' of type [org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-07-03 17:52:07.559 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration$ReactiveLoadBalancerConfig' of type [org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration$ReactiveLoadBalancerConfig] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-07-03 17:52:07.564 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'deferringLoadBalancerExchangeFilterFunction' of type [org.springframework.cloud.client.loadbalancer.reactive.DeferringLoadBalancerExchangeFilterFunction] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-07-03 17:52:07.984 [main] INFO  com.netflix.config.sources.URLConfigurationSource - URLs to be used as dynamic configuration source: [jar:file:/data/home/helishop0628/helishop/h2/starters/shop13.jar!/BOOT-INF/classes!/config.properties]
2022-07-03 17:52:08.000 [main] INFO  com.netflix.config.sources.URLConfigurationSource - URLs to be used as dynamic configuration source: [jar:file:/data/home/helishop0628/helishop/h2/starters/shop13.jar!/BOOT-INF/classes!/config.properties]
2022-07-03 17:52:08.862 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [After]
2022-07-03 17:52:08.863 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [Before]
2022-07-03 17:52:08.863 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [Between]
2022-07-03 17:52:08.863 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [Cookie]
2022-07-03 17:52:08.863 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [Header]
2022-07-03 17:52:08.863 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [Host]
2022-07-03 17:52:08.864 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [Method]
2022-07-03 17:52:08.864 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [Path]
2022-07-03 17:52:08.864 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [Query]
2022-07-03 17:52:08.864 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [ReadBody]
2022-07-03 17:52:08.864 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [RemoteAddr]
2022-07-03 17:52:08.864 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [Weight]
2022-07-03 17:52:08.864 [main] INFO  o.s.c.gateway.route.RouteDefinitionRouteLocator - Loaded RoutePredicateFactory [CloudFoundryRouteService]
2022-07-03 17:52:08.953 [main] INFO  c.a.c.s.gateway.scg.SentinelSCGAutoConfiguration - [Sentinel SpringCloudGateway] register SentinelGatewayFilter with order: -2147483648
2022-07-03 17:52:09.197 [main] INFO  c.a.c.s.gateway.scg.SentinelSCGAutoConfiguration - [Sentinel SpringCloudGateway] register SentinelGatewayBlockExceptionHandler
2022-07-03 17:52:09.234 [main] INFO  o.s.scheduling.concurrent.ThreadPoolTaskScheduler - Initializing ExecutorService 'Nacos-Watch-Task-Scheduler'
2022-07-03 17:52:10.081 [com.alibaba.nacos.client.Worker] INFO  org.reflections.Reflections - Reflections took 158 ms to scan 1 urls, producing 3 keys and 6 values 
2022-07-03 17:52:10.209 [com.alibaba.nacos.client.Worker] INFO  org.reflections.Reflections - Reflections took 96 ms to scan 1 urls, producing 4 keys and 9 values 
2022-07-03 17:52:10.306 [com.alibaba.nacos.client.Worker] INFO  org.reflections.Reflections - Reflections took 92 ms to scan 1 urls, producing 3 keys and 10 values 
2022-07-03 17:52:10.402 [com.alibaba.nacos.client.Worker] INFO  org.reflections.Reflections - Reflections took 94 ms to scan 145 urls, producing 0 keys and 0 values 
2022-07-03 17:52:10.478 [com.alibaba.nacos.client.Worker] INFO  org.reflections.Reflections - Reflections took 75 ms to scan 1 urls, producing 1 keys and 5 values 
2022-07-03 17:52:10.543 [com.alibaba.nacos.client.Worker] INFO  org.reflections.Reflections - Reflections took 60 ms to scan 1 urls, producing 1 keys and 7 values 
2022-07-03 17:52:10.589 [com.alibaba.nacos.client.Worker] INFO  org.reflections.Reflections - Reflections took 41 ms to scan 1 urls, producing 2 keys and 8 values 
2022-07-03 17:52:10.651 [com.alibaba.nacos.client.Worker] INFO  org.reflections.Reflections - Reflections took 59 ms to scan 145 urls, producing 0 keys and 0 values 
2022-07-03 17:52:11.789 [main] WARN  c.a.c.s.datasource.converter.SentinelConverter - converter can not convert rules because source is empty
INFO: Sentinel log output type is: file
INFO: Sentinel log charset is: utf-8
INFO: Sentinel log base directory is: /home/h8/logs/csp/
INFO: Sentinel log name use pid is: false
2022-07-03 17:52:12.496 [main] WARN  o.s.b.w.r.c.AnnotationConfigReactiveWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start Netty
2022-07-03 17:52:13.108 [main] INFO  o.s.scheduling.concurrent.ThreadPoolTaskScheduler - Shutting down ExecutorService 'Nacos-Watch-Task-Scheduler'
2022-07-03 17:52:15.279 [main] INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener - 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-07-03 17:52:15.310 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start Netty
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185)
	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 cc.helik.shop.App.main(App.java:11)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
	at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start Netty
	at org.springframework.boot.web.embedded.netty.NettyWebServer.start(NettyWebServer.java:107)
	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)
	... 22 common frames omitted
Caused by: reactor.netty.ChannelBindException: Failed to bind on [0.0.0.0:80]
	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 cc.helik.shop.App.main(App.java:11)
		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
		at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
		at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
		at java.lang.reflect.Method.invoke(Method.java:498)
		at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
		at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
		at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
		at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: 权限不够
2022-07-03 17:52:15.568 [Thread-10] WARN  com.alibaba.nacos.common.notify.NotifyCenter - [NotifyCenter] Start destroying Publisher
2022-07-03 17:52:15.568 [Thread-5] WARN  com.alibaba.nacos.common.http.HttpClientBeanHolder - [HttpClientBeanHolder] Start destroying common HttpClient
2022-07-03 17:52:15.575 [Thread-10] WARN  com.alibaba.nacos.common.notify.NotifyCenter - [NotifyCenter] Destruction of the end
2022-07-03 17:52:15.577 [Thread-5] WARN  com.alibaba.nacos.common.http.HttpClientBeanHolder - [HttpClientBeanHolder] Destruction of the end

启动命令就是下面这种

java -jar s.jar > log.txt 2>&1 >&

当我在前面先执行 sudo su就直接切换到root账号了,而这也启动失败:

bash: java: 未找到命令

显然,这个是因为我只给管理员账号配置了用户环境变量的缘故。

另外一种处理方式是80端口通过NGINX转发,目前还没有尝试,不晓得是否存在问题。

不知道谁晓得在管理员账号如何以80端口号启动服务?

Reply Favorite View the author
All Replies
fxbszj
deepin
2022-07-05 17:35
#1
It has been deleted!
kero990
deepin
2022-07-05 18:40
#2

不建议使用root账户来搭建web服务,这是个安全习惯,不然别人从web入侵你的网站,直接就是root权限,你整个服务器都无所遁形,人家在浏览器里就能删除你服务器的所有文件。

一般来说web服务要严格限制权限,一般比普通账户权限还低,能访问的目录严格限制在web目录下等等。这样即使有入侵,损失最大也就是这个web,不会波及别的。假如你服务器还有别的系统,用root启用web,所有系统都受这个网站影响。

至于端口,每个软件配置端口的地方不一样,不是怎么在80端口开启服务的问题,而是你用的这个软件,怎么配置端口的问题

另外你得看看80端口是不是已经占用了

Reply View the author
wang3develop
deepin
2022-07-05 18:48
#3
kero990

不建议使用root账户来搭建web服务,这是个安全习惯,不然别人从web入侵你的网站,直接就是root权限,你整个服务器都无所遁形,人家在浏览器里就能删除你服务器的所有文件。

一般来说web服务要严格限制权限,一般比普通账户权限还低,能访问的目录严格限制在web目录下等等。这样即使有入侵,损失最大也就是这个web,不会波及别的。假如你服务器还有别的系统,用root启用web,所有系统都受这个网站影响。

至于端口,每个软件配置端口的地方不一样,不是怎么在80端口开启服务的问题,而是你用的这个软件,怎么配置端口的问题

另外你得看看80端口是不是已经占用了

我这是新建的一个管理员账号来测试启动运行看看会出什么问题,如何解决它,没打算用root账号。

启动输出日志已经打印出失败的原因了,在倒数第五行。不会是端口号占用的问题,如果是,之前改用root权限(有配置系统环境变量成功启动过,但是运行时部分文件数据路径不好找)启动会输出端口号占用的。另外,我改过端口号为8688启动成功运行了。

Reply View the author
云的眼泪
deepin
2022-07-06 00:40
#4
wang3develop

我这是新建的一个管理员账号来测试启动运行看看会出什么问题,如何解决它,没打算用root账号。

启动输出日志已经打印出失败的原因了,在倒数第五行。不会是端口号占用的问题,如果是,之前改用root权限(有配置系统环境变量成功启动过,但是运行时部分文件数据路径不好找)启动会输出端口号占用的。另外,我改过端口号为8688启动成功运行了。

修改端口号能启动,说明80端口被占用了,我的就是被lighttpd占用,我以80端口启动python服务器失败,改成8080就启动了。

image.png

Reply View the author
大泽IO
deepin
2022-07-20 05:25
#5
kero990

不建议使用root账户来搭建web服务,这是个安全习惯,不然别人从web入侵你的网站,直接就是root权限,你整个服务器都无所遁形,人家在浏览器里就能删除你服务器的所有文件。

一般来说web服务要严格限制权限,一般比普通账户权限还低,能访问的目录严格限制在web目录下等等。这样即使有入侵,损失最大也就是这个web,不会波及别的。假如你服务器还有别的系统,用root启用web,所有系统都受这个网站影响。

至于端口,每个软件配置端口的地方不一样,不是怎么在80端口开启服务的问题,而是你用的这个软件,怎么配置端口的问题

另外你得看看80端口是不是已经占用了

有道理,不过80端口除了调cap那就只剩root能开了(因为端口号太低了)

当然NGINX反代也是个招

Reply View the author
wang3develop
deepin
2022-12-31 18:32
#6

目前已经通过NGINX转发解决!

Reply View the author