jenkins swarm插件:无法连接到master。拒绝连接

时间:2017-04-09 18:11:17

标签: jenkins jenkins-slave

我正在使用jenkins swarm插件将从节点连接到主节点。但是,它会出现Connection Refused错误。

我正在使用docker swarm在多节点集群上部署它。现在我只使用单节点设置进行测试,这里是我的用于设置的撰写文件:

version: '3.1'

    services:
      viz:
        image: manomarks/visualizer
        volumes:
          - "/var/run/docker.sock:/var/run/docker.sock"
        ports:
          - "8090:8080"

      master:
        image: myproject-jenkins-master
        ports:
          - "8080:8080"
          - "50000:50000"
        volumes:
          - ./jenkins_home:/var/jenkins_home

      nginx:
        image: myproject-jenkins-nginx
        ports:
          - "80:80"

      linuxagent:
        image: myproject-jenkins-linuxagent

使用docker stack deploy命令部署它,以便上述每个服务都获得自己的内部负载均衡器。

Jenkins通过nginx在网上提供服务。但我也保留了8080端口进行调试。如果我打开浏览器并点击http://localhosthttp://localhost:8080,我可以访问jenkins网络界面。在master上,我安装了jenkins swarm插件。如果我从我的linuxagent容器进入bash shell,这是一个从属节点,我可以ping其他docker服务,但是当我尝试运行swarm-client-3.3.jar文件时会发生这种情况。

如果我尝试访问jenkins,我可以访问http://myproject_master:8080

root@d139902be5de:~# curl http://myproject_master:8080
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>


Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
 ... which is implied by: hudson.security.Permission.GenericRead
 ... which is implied by: hudson.model.Hudson.Administer
-->

</body></html>                                                                                                                                                                                                                                                                                                            root@d139902be5de:~# 

另外,我可以通过http://myproject_nginx

访问相同内容
root@d139902be5de:~# curl http://myproject_nginx      
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>


Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
 ... which is implied by: hudson.security.Permission.GenericRead
 ... which is implied by: hudson.model.Hudson.Administer
-->

</body></html>                                                                                                                                                                                                                                                                                                            root@d139902be5de:~# 

如果我尝试为swarm启动jar文件,我会收到此错误:

root@d139902be5de:~# java -jar swarm-client-3.3.jar -username mandeep -password 12213 -master http://myproject_nginx      
Apr 09, 2017 5:52:44 PM hudson.plugins.swarm.Client main
INFO: Client.main invoked with: [-username mandeep -password 12213 -master http://myproject_nginx]
Apr 09, 2017 5:52:44 PM hudson.plugins.swarm.Client run
INFO: Discovering Jenkins master
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Apr 09, 2017 5:52:44 PM hudson.plugins.swarm.Client run
INFO: Attempting to connect to http://myproject_nginx/ bc1be8e7-eaf0-47ff-8aeb-36f75d6ba081 with ID c84ce43b
Apr 09, 2017 5:52:45 PM hudson.remoting.jnlp.Main createEngine
INFO: Setting up slave: d139902be5de-c84ce43b
Apr 09, 2017 5:52:45 PM hudson.remoting.jnlp.Main$CuiListener <init>
INFO: Jenkins agent is running in headless mode.
Apr 09, 2017 5:52:45 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Locating server among [http://myproject_nginx/]
Apr 09, 2017 5:52:45 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Agent discovery successful
  Agent address: myproject_nginx
  Agent port:    50000
  Identity:      86:5b:f3:77:84:92:21:87:95:4c:4b:0e:f7:4e:e5:1d
Apr 09, 2017 5:52:45 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Handshaking
Apr 09, 2017 5:52:45 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connecting to myproject_nginx:50000
Apr 09, 2017 5:52:55 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connecting to myproject_nginx:50000 (retrying:2)
java.io.IOException: Failed to connect to myproject_nginx:50000
  at org.jenkinsci.remoting.engine.JnlpAgentEndpoint.open(JnlpAgentEndpoint.java:243)
  at hudson.remoting.Engine.connect(Engine.java:500)
  at hudson.remoting.Engine.innerRun(Engine.java:364)
  at hudson.remoting.Engine.run(Engine.java:287)
Caused by: java.net.ConnectException: Connection refused
  at sun.nio.ch.Net.connect0(Native Method)
  at sun.nio.ch.Net.connect(Net.java:454)
  at sun.nio.ch.Net.connect(Net.java:446)
  at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648)
  at java.nio.channels.SocketChannel.open(SocketChannel.java:189)
  at org.jenkinsci.remoting.engine.JnlpAgentEndpoint.open(JnlpAgentEndpoint.java:204)
  ... 3 more

似乎问题是slave希望master为myproject_nginx,因此命中端口50000失败,因为此服务没有暴露端口50000。因此,为此,我在8080服务上公开了端口50000myproject_master。但是当我尝试这个网址时,我得到了一个不同的错误

root@d139902be5de:~# java -jar swarm-client-3.3.jar -username mandeep -password 12213 -master http://myproject_master:8080
Apr 09, 2017 5:57:01 PM hudson.plugins.swarm.Client main
INFO: Client.main invoked with: [-username mandeep -password 12213 -master http://myproject_master:8080]
Apr 09, 2017 5:57:01 PM hudson.plugins.swarm.Client run
INFO: Discovering Jenkins master
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Apr 09, 2017 5:57:01 PM hudson.plugins.swarm.Client run
SEVERE: IOexception occurred
java.net.ConnectException: Connection refused (Connection refused)
  at java.net.PlainSocketImpl.socketConnect(Native Method)
  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
  at java.net.Socket.connect(Socket.java:589)
  at java.net.Socket.connect(Socket.java:538)
  at java.net.Socket.<init>(Socket.java:434)
  at java.net.Socket.<init>(Socket.java:286)
  at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
  at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
  at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
  at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
  at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
  at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
  at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
  at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
  at hudson.plugins.swarm.SwarmClient.discoverFromMasterUrl(SwarmClient.java:224)
  at hudson.plugins.swarm.Client.run(Client.java:115)
  at hudson.plugins.swarm.Client.main(Client.java:88)

这是我完全陷入困境,无法理解如何解决问题的地方。是否会出现问题,因为从站在负载均衡器后面运行?或者我想要完成的架构中有什么根本错误的吗?我希望能够动态扩展linuxagent服务,以便每个节点都充当从属代理,并且只要它在启动时就与主节点连接。我读了jenkins的swarm插件,发现它可以用来实现这种设置

2 个答案:

答案 0 :(得分:0)

为我改变修复它的参数顺序。 请将-master移动到swarm参数的开头:

java -jar /usr/share/jenkins/swarm-client-3.4.jar -disableSslVerification -master

这应该修复我看到的以下错误:

Jul 25, 2017 6:26:23 PM hudson.plugins.swarm.Client run
INFO: Discovering Jenkins master
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for 
further details.
Exception in thread "main" java.lang.IllegalArgumentException: Host 
name may not be null
at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:68)
at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:107)
at org.apache.commons.httpclient.HttpMethodBase.setURI(HttpMethodBase.java:280)
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
at hudson.plugins.swarm.SwarmClient.discoverFromMasterUrl(SwarmClient.java:220)
at hudson.plugins.swarm.Client.run(Client.java:114)
at hudson.plugins.swarm.Client.main(Client.java:87)

答案 1 :(得分:0)

尝试为TCP端口443和50000打开入站。

相关问题