jenkins不能通过ip地址连接

eoigrqb6  于 2022-12-22  发布在  Jenkins
关注(0)|答案(3)|浏览(310)

我通过yum install jenkins在centOS 7上安装jenkins,并启动jenkins service jenkins start
Now I can access it by localhost and 127.0.0.1 , but I can't access it by ip (like: 192.168.1.77).
1.防火墙已关闭

  1. jeakins配置是默认的
    1.Jenkins版本:v2.64
    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时,result为:

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之后,不知道为什么,但是现在起作用了,这不是一个好办法!!!

x7rlezfr

x7rlezfr1#

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

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

看起来你的ISP没有通过IpV6地址让你出去,这就是为什么你不能访问Jenkins.你可以在sysconfig文件中配置Java默认值,在我的场景中我使用的是CentOS 7,所以我修改了/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

dzhpxtsq

dzhpxtsq2#

在这里添加这个,因为它是谷歌上的第一个点击。我还必须配置防火墙。

firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload
l2osamch

l2osamch3#

我在Red Hat Enterprise Linux版本9.1(Plow)上使用过这种方法。
防火墙命令-区域=公共-添加端口=8080/tcp a-永久
防火墙命令--区域=公共--添加服务=http --永久
防火墙-cmd-重新加载
谢谢你@Balazs Gunics,因为你节省了我很多时间。

相关问题