1

我已经在 debian 7 上安装了 Jenkins。现在我想在端口 80 上运行它,这样我就可以简单地http://jenkins在我的本地 LAN 上键入而不是http://jenkins:8080(目前可以工作)。我已将文件修改/etc/default/jenkins为:

# port for HTTP connector (default 8080; disable with -1)
#HTTP_PORT=8080
#HTTP_PORT=88
HTTP_PORT=80

但是当我重新启动 jenkins 服务sudo service jenkins restart并尝试访问时http://jenkins:80,我只会得到一个空白/错误页面。日志显示 ( /var/log/jenkins/jenkins.log ):

java.io.IOException: Failed to start a listener: winstone.HttpListener
    at winstone.Launcher.spawnListener(Launcher.java:229)
    at winstone.Launcher.<init>(Launcher.java:181)
    at winstone.Launcher.main(Launcher.java:384)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at Main._main(Main.java:288)
    at Main.main(Main.java:98)
Caused by: java.io.IOException: Failed to listen on port 80
    at winstone.HttpListener.getServerSocket(HttpListener.java:122)
    at winstone.HttpListener.start(HttpListener.java:75)
    at winstone.Launcher.spawnListener(Launcher.java:220)
    ... 8 more
Caused by: java.net.BindException: Permission denied
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:353)
    at java.net.ServerSocket.bind(ServerSocket.java:336)
    at java.net.ServerSocket.<init>(ServerSocket.java:202)
    at java.net.ServerSocket.<init>(ServerSocket.java:158)
    at winstone.HttpListener.getServerSocket(HttpListener.java:117)
    ... 10 more
Sep 11, 2013 9:09:30 PM jenkins.InitReactorRunner$1 onAttained
INFO: Started initialization
Sep 11, 2013 9:09:30 PM hudson.WebAppMain$3 run
SEVERE: Failed to initialize Jenkins
java.lang.InterruptedException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:502)
    at org.jvnet.hudson.reactor.Reactor.execute(Reactor.java:244)
    at jenkins.InitReactorRunner.run(InitReactorRunner.java:43)
    at jenkins.model.Jenkins.executeReactor(Jenkins.java:906)
    at jenkins.model.Jenkins.<init>(Jenkins.java:806)
    at hudson.model.Hudson.<init>(Hudson.java:81)
    at hudson.model.Hudson.<init>(Hudson.java:77)
    at hudson.WebAppMain$3.run(WebAppMain.java:221)
Exception in thread "pool-2-thread-1" java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:679)

我尝试运行sudo netstat -lp但没有看到任何端口信息(看起来没有任何应用程序在端口 80 上运行)。我也尝试过使用 port=88 但它给出了相同的结果。

有什么建议么?

4

2 回答 2

5

我也有同样的问题,发现没有root权限是无法监听1024以下的端口的。

我们可以做几件事,但我认为最安全的是:

  • 使用iptables将端口 80 重定向到 8080

# iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

除此之外,您可以通过chownchmod以 root 身份运行 jenkins,但我认为这可能很危险。

其他可能性在这里介绍:

https://serverfault.com/questions/112795/how-can-i-run-a-server-on-linux-on-port-80-as-a-normal-user

于 2013-09-11T20:47:45.733 回答
0

确保 apache 或其他东西没有在端口 80 上运行

netstat -utanp | grep 80

tcp 0 0 :::80 :::* 听 1428/httpd

如果在 80 上运行其他任何东西,请确保在 80 上启动 Jenkins 之前停止它

于 2013-09-11T21:20:03.877 回答