jenkins无法通过ip地址连接

时间:2017-06-05 09:27:11

标签: jenkins

我通过yum install jenkins在centOS 7上安装jenkins,然后启动jenkins service jenkins start

现在我可以通过localhost127.0.0.1访问它,但我无法通过ip访问它(例如:192.168.1.77)。

  1. 防火墙关闭
  2. jeakins config是默认的
  3. jenkins版本:v2.64
  4. netstat -nltp结果:(我现在使用端口:8088)

    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 127.0.0.1:9100          0.0.0.0:*               LISTEN      23208/node_exporter 
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      23200/nginx: master 
    tcp        0      0 127.0.0.1:9168          0.0.0.0:*               LISTEN      23177/ruby          
    tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      3053/dnsmasq        
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1503/sshd           
    tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1495/cupsd          
    tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2856/master         
    tcp        0      0 0.0.0.0:8060            0.0.0.0:*               LISTEN      23200/nginx: master 
    tcp        0      0 127.0.0.1:9121          0.0.0.0:*               LISTEN      23224/redis_exporte 
    tcp        0      0 127.0.0.1:9090          0.0.0.0:*               LISTEN      23166/prometheus    
    tcp        0      0 127.0.0.1:8899          0.0.0.0:*               LISTEN      23258/unicorn maste 
    tcp        0      0 127.0.0.1:9187          0.0.0.0:*               LISTEN      23214/postgres_expo 
    tcp6       0      0 ::1:9168                :::*                    LISTEN      23177/ruby          
    tcp6       0      0 :::22                   :::*                    LISTEN      1503/sshd           
    tcp6       0      0 ::1:631                 :::*                    LISTEN      1495/cupsd          
    tcp6       0      0 :::8088                 :::*                    LISTEN      886/java            
    tcp6       0      0 ::1:25                  :::*                    LISTEN      2856/master         
    

    ifconfig结果:

    enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.2.99  netmask 255.255.255.0  broadcast 192.168.2.255
            inet6 fe80::a62:66ff:fe9e:fba3  prefixlen 64  scopeid 0x20<link>
            ether 08:62:66:9e:fb:a3  txqueuelen 1000  (Ethernet)
            RX packets 501018  bytes 502734098 (479.4 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 167889  bytes 16471815 (15.7 MiB)
            TX errors 14  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 0  (Local Loopback)
            RX packets 11265076  bytes 8998994558 (8.3 GiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 11265076  bytes 8998994558 (8.3 GiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
            ether 52:54:00:e3:8b:e1  txqueuelen 0  (Ethernet)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

    使用@StephenKing帮助,现在可以使用了:

    我认为,当我执行service iptables stop时,结果是:

    Redirecting to /bin/systemctl stop  iptables.service
    Failed to stop iptables.service: Unit iptables.service not loaded.
    

    所以我认为防火墙是关闭的。实际上,CentOS 7使用firewall-cmd --state结果为running

    运行iptables -F后,我不知道为什么,但它现在有效。这不是一个好方法!!!

1 个答案:

答案 0 :(得分:0)

从您的netstat输出中可以看出,这是一个IpV6绑定问题,因为Jenkins的Java进程仅在侦听IpV6:

tcp6       0      0 :::8088                 :::*                    LISTEN      886/java

似乎您的ISP并没有通过IpV6地址将您拒之门外,这就是为什么您无法访问Jenkins。在我使用CentOS 7的情况下,您可以在sysconfig文件中配置Java默认值,因此我在/etc/sysconfig/jenkins中修改了这一行:

JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true"

然后systemctl restart jenkins,现在它正在侦听IPv4:

[root@jenkins ~]# netstat -lntup | grep 8080
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      1300/java

感谢Link