Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Jenkins to run on port 80 on Centos 7

I've installed Jenkins, based on Jetty server on Centos 7. In the configuration file : /etc/sysconfig/jenkins default port is 8080, and everything works perfectly, but I need to move jenkins on 80 port.

When I change JENKINS_PORT="8080" to JENKINS_PORT="80" - jenkins no longer available. Firewall I turned off.

in log messages: /var/log/jenkins/jenkins.log

Aug 17, 2017 12:07:45 PM org.eclipse.jetty.util.log.JavaUtilLog warn
WARNING: FAILED ServerConnector@4082ba93{HTTP/1.1}{0.0.0.0:80}: java.net.SocketException: Permission denied
java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:321)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.server.Server.doStart(Server.java:366)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at winstone.Launcher.<init>(Launcher.java:152)
at winstone.Launcher.main(Launcher.java:352)
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 Main._main(Main.java:293)
at Main.main(Main.java:132)    

Can anyone help me with that problem?

like image 346
nimda Avatar asked Jan 03 '23 14:01

nimda


2 Answers

Google led me to https://confluence.atlassian.com/confkb/permission-denied-error-when-binding-a-port-290750651.html

Ports below 1024 are called Privileged Ports and in Linux (and most UNIX flavors and UNIX-like systems), they are not allowed to be opened by any non-root user.

So as I run startup script as JENKINS_USER="jenkins" the Permission denied error has appeared.

like image 56
nimda Avatar answered Jan 13 '23 13:01

nimda


As @Nimda answered https://stackoverflow.com/a/45754065/3471694
I got the same issue below

SEVERE: Container startup failed
java.io.IOException: Failed to start Jetty
        at winstone.Launcher.<init>(Launcher.java:186)
        at winstone.Launcher.main(Launcher.java:354)
        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 Main._main(Main.java:344)
        at Main.main(Main.java:160)
Caused by: java.net.SocketException: Permission denied
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:433)
        at sun.nio.ch.Net.bind(Net.java:425)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:339)
        at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:307)
        at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
        at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:235)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.server.Server.doStart(Server.java:395)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at winstone.Launcher.<init>(Launcher.java:184)
        ... 7 more

Solution: Edit file /etc/sysconfig/jenkins or any jenkins' configuration file
- Change #JENKINS_USER="jenkins" to any user that can run as root
example: JENKINS_USER="root"
Hope this help

like image 29
Bui Anh Tuan Avatar answered Jan 13 '23 14:01

Bui Anh Tuan