Connect to localhost slave node from Jenkins docker container - docker

I do want to connect my Jenkins master slave in a docker container to my localhost machine node slave(to be accurate my macOS High Sierra).
Here you are the steps I followed:
Run docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts.
Go to Manage Jenkins. Click on Manage Nodes.
Launch method, select: Launch slave agents on Unix machines via SSH
Host: 192.168.1.33, 127.0.0.1, localhost, 0.0.0.0
Credentials: Username and password or SSH username with private key.
I don't know what ip I should put in the Host field and which option to select in Credentials field. I've already tried several combinations but I don't get any result. In addition, when I make a ping from my container to my localhost, it is always successful.
How Can I setup the Host and Credentials fields in order to connect to my local host node slave without having to use the Launch slave agents via Java Web Start
I always get this error:
SSHLauncher{host='192.168.1.33', port=22, credentialsId='4bc9a817-edae-4806-bc55-2f5b4f5b03e7', jvmOptions='', javaPath='', prefixStartSlaveCmd='', suffixStartSlaveCmd='', launchTimeoutSeconds=210, maxNumRetries=10, retryWaitTime=15, sshHostKeyVerificationStrategy=hudson.plugins.sshslaves.verifiers.KnownHostsFileKeyVerificationStrategy, tcpNoDelay=true, trackCredentials=true}
[09/23/18 21:24:39] [SSH] Opening SSH connection to 192.168.1.33:22.
Connection refused (Connection refused)
SSH Connection failed with IOException: "Connection refused (Connection refused)", retrying in 15 seconds. There are 10 more retries left.
Connection refused (Connection refused)
SSH Connection failed with IOException: "Connection refused (Connection refused)", retrying in 15 seconds. There are 8 more retries left.
Connection refused (Connection refused)
SSH Connection failed with IOException: "Connection refused (Connection refused)", retrying in 15 seconds. There are 9 more retries left.
Connection refused (Connection refused)
SSH Connection failed with IOException: "Connection refused (Connection refused)", retrying in 15 seconds. There are 7 more retries left.

Is your slave node listening on port 22 for SSH connections ?
If yes, are you able to telnet 192.168.1.33 22 from Jenkins master ?
If no, install a basic SSH server on your slave node like open
openssh and try again ?

I just got this working with a Jenkins Docker container with my mac as the slave node.
For the Host field enter the output of the "hostname" command when you run it on terminal. To set the credential field, make a Jenkins credential with your username and password for your mac (whatever credential works when you run ssh localhost on terminal).
I also have the field "Host Key Verification Strategy" set to "non verifying Verification Strategy." But you may not need this if you manually run the ssh command on your terminal and accept the key

Related

Connect to events.pagerduty.com:443 connect timed out

Jenkins 2.82
Jenkins master - From this machine, I don't have access to internet/outside world.
Jenkins slave server, running docker containers (for slave server), do have access to outside world/internet.
I installed PagerDuty Plugin and configured it correctly in a job to send notification per failure and when the status is back to normal.
When I ran the job, I got the following error mesg com.mashape.unirest.http.exceptions.UnirestException: org.apache.http.conn.ConnectTimeoutException: Connect to events.pagerduty.com:443 [events.pagerduty.com/54.244.255.45, events.pagerduty.com/54.241.36.66, events.pagerduty.com/104.45.235.10] failed: connect timed out.
0:49:44
10:49:44 Resolving incident
10:50:14 Error while trying to resolve
10:50:14 com.mashape.unirest.http.exceptions.UnirestException: org.apache.http.conn.ConnectTimeoutException: Connect to events.pagerduty.com:443 [events.pagerduty.com/54.244.255.45, events.pagerduty.com/54.241.36.66, events.pagerduty.com/104.45.235.10] failed: connect timed out
10:50:14 Build step 'PagerDuty Incident Trigger' marked build as failure
10:50:14 Notifying upstream projects of job completion
10:50:14 Finished: FAILURE
I logged onto the slave machine first and tried to ping the IPs next to events.pagerduty.com server (as listed above) and ping worked fine. Doing telnet on port 443 (ssh) also gave valid output.
As the slave servers are actually docker containers, I went inside one of the container slave server and did the same (ping, telnet on 443 for those
events.pagerduty.com IPs, nslookup and nc / ncat etc and output looks good).
Here, Im inside the docker slave container's host i.e. I ran docker exec -it shenazi_ninza bash and I'm now inside the container's host/IP:
root#da5ca3fef1c8:/data# hostname
da5ca3fef1c8
root#da5ca3fef1c8:/data# hostname; hostname -i
da5ca3fef1c8
172.17.137.77
root#da5ca3fef1c8:/data# nslookup events.pagerduty.com
Server: 17.178.6.10
Address: 17.178.6.10#53
Non-authoritative answer:
events.pagerduty.com canonical name = events.gslb.pagerduty.com.
Name: events.gslb.pagerduty.com
Address: 54.241.36.66
Name: events.gslb.pagerduty.com
Address: 54.245.112.46
Name: events.gslb.pagerduty.com
Address: 104.45.235.10
root#da5ca3fef1c8:/data#
root#da5ca3fef1c8:/data# for s in `nslookup events.pagerduty.com|grep "Address: [0-9]"|sed "s/ //g"|cut -d':' -f2`; do echo Server: $s; telnet $s 443; done
Server: 54.245.112.46
Trying 54.245.112.46...
Connected to 54.245.112.46.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
Server: 104.45.235.10
Trying 104.45.235.10...
Connected to 104.45.235.10.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
Server: 54.241.36.66
Trying 54.241.36.66...
Connected to 54.241.36.66.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
root#da5ca3fef1c8:/data# for s in `nslookup events.pagerduty.com|grep "Address: [0-9]"|sed "s/ //g"|cut -d':' -f2`; do echo Server: $s; telnet $s 443; done
Server: 54.245.112.46
Trying 54.245.112.46...
Connected to 54.245.112.46.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
Server: 54.241.36.66
Trying 54.241.36.66...
Connected to 54.241.36.66.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
Server: 54.244.255.45
Trying 54.244.255.45...
Connected to 54.244.255.45.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
root#da5ca3fef1c8:/data# ^C
root#da5ca3fef1c8:/data# nc -v -w 1 events.pagerduty.com 443
Connection to events.pagerduty.com 443 port [tcp/https] succeeded!
root#da5ca3fef1c8:/data#
PagerDuty integration in Jenkins job's configuration is available under POST Built Actions area.
My question is, isn't the whole job running on the slave server (aka container's slave from where I have access to the outside world and Im able to connect to events.pagerduty.com server)?
It seems like Jenkins is running anything under the POST Build Data section, on the master Jenkins instance from where I don't have access to events.pagerduty.com (ping/telnet etc)? As we don't want Jenkins master to have outside world access, how can this issue be resolved so that I can get alerted if a build fails for that job?
So, instead of opening all access, added the route to use a given gateway / route to access only events.pagerduty.com server
/sbin/route add -net 50.0.0.0/8 x.x.x.x dev eth0
/sbin/route add default gw x.y.z.someIP
/sbin/route add -net 50.0.0.0 netmask 255.0.0.0 gw x.y.z.ip
and now from master Jenkins I'm able to see/access just the events.pagerduty.com server / it's IPs.
x.y.z.ip is what you'll have to put.

why can't i access the docker based zookeeper port

on OS X i started kafka docker image successfully,but it seems that i can't access it on localhost
➜ ~ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1f931da3d661 wurstmeister/zookeeper:3.4.6 "/bin/sh -c '/usr/..." About an hour ago Up About an hour 22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp docker_zookeeper_1
8bc36bcf8fdf wurstmeister/kafka:0.10.1.1 "start-kafka.sh" About an hour ago Up About an hour 0.0.0.0:9092->9092/tcp docker_kafka_1
➜ ~ telnet 0.0.0.0:2181
0.0.0.0:2181: nodename nor servname provided, or not known
➜ ~ telnet 0.0.0.0 2181
Trying 0.0.0.0...
telnet: connect to address 0.0.0.0: Connection refused
telnet: Unable to connect to remote host
➜ ~ telnet 192.168.43.193 2181
Trying 192.168.43.193...
telnet: connect to address 192.168.43.193: Connection refused
telnet: Unable to connect to remote host
➜ ~ telnet 127.0.0.1 2181
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
my docker file is here kafka.yml and use this command to up:
docker-compose -f src/main/docker/kafka.yml up -d
when i use
./mvnw
the console is:
2017-09-15 17:05:46.433 WARN 15871 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn : Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
how can i access the 2181 port
EDIT
docker logs 8bc36bcf8fdf
[2017-09-15 08:14:13,386] FATAL Fatal error during KafkaServerStartable startup. Prepare to shutdown (kafka.server.KafkaServerStartable)
java.lang.RuntimeException: A broker is already registered on the path /brokers/ids/1001. This probably indicates that you either have configured a brokerid that is already in use, or else you have shutdown this broker and restarted it faster than the zookeeper timeout so it appears to be re-registering.
at kafka.utils.ZkUtils.registerBrokerInZk(ZkUtils.scala:393)
at kafka.utils.ZkUtils.registerBrokerInZk(ZkUtils.scala:379)
at kafka.server.KafkaHealthcheck.register(KafkaHealthcheck.scala:70)
at kafka.server.KafkaHealthcheck.startup(KafkaHealthcheck.scala:51)
at kafka.server.KafkaServer.startup(KafkaServer.scala:270)
at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:39)
at kafka.Kafka$.main(Kafka.scala:67)
at kafka.Kafka.main(Kafka.scala)
[2017-09-15 08:14:13,393] INFO [Kafka Server 1001], shutting down (kafka.server.KafkaServer)
docker logs 1f931da3d661
2017-09-14 08:53:05,878 [myid:] - WARN [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn#357] - caught end of stream exception
EndOfStreamException: Unable to read additional data from client sessionid 0x15e7ea74c8e0000, likely client has closed socket
at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:228)
at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208)
at java.lang.Thread.run(Thread.java:745)
2017-09-14 08:53:05,887 [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn#1007] - Closed socket connection for client /172.18.0.2:54222 which had sessionid 0x15e7ea74c8e0000
Have you tried using host networking as in this example? https://docs.confluent.io/current/cp-docker-images/docs/quickstart.html#zookeeper
That looks like it will simplify and solve this. I'd also recommend checking out these images instead of the custom ones it looks like you are using because these are being run in production for people so they are known to work well.

How to connect a service running inside a docker with consul?

I am trying to run a docker container that takes the CONSUL_URL as an ENV Variable. For now, I have set up the consul on my localhost and I run it like this: consul agent -dev -bind=127.0.0.1 -ui-dir /usr/local/Cellar/consul/0.7.0/share/consul/web-ui
I am able to access the consul ui this way when I go to http://localhost:8500. But, now that I am running the docker container through this, docker run -e CONSUL_URL=127.0.0.1:8500 -p 8500:8500 b321825a6c7a, it gives me the following error:
2016/10/05 09:38:38 [ERR] (view) "key_or_default(foo.appconfig.properties/logger.name, "foo_PERF_LOG")" store key: error fetching: Get http://127.0.0.1:8500/v1/kv/foo.appconfig.properties/logger.name?stale=&wait=60000ms: dial tcp 127.0.0.1:8500: getsockopt: connection refused
2016/10/05 09:38:38 [ERR] (runner) watcher reported error: store key: error fetching: Get http://127.0.0.1:8500/v1/kv/foo.appconfig.properties/logger.name?stale=&wait=60000ms: dial tcp 127.0.0.1:8500: getsockopt: connection refused
Consul Template returned errors:
store key: error fetching: Get http://127.0.0.1:8500/v1/kv/foo.appconfig.properties/logger.name?stale=&wait=60000ms: dial tcp 127.0.0.1:8500: getsockopt: connection refusedexecuting: 'myscript.sh run'
Why am I not able to connect with the consul URL? I also tried changing the localhost url to the IP Address of my machine, but, I get the same error with that too. I have done the port mapping, so, I guess it should work. Where am I going wrong?
You have to use the --net=host flag.
This flag will create sockets for the exposed ports for all interfaces in the main OS.
docker run --net=host -e CONSUL_URL=127.0.0.1:8500 b321825a6c7a

Connecting Jenkins slave agent on windows failed with connection timeout

Connecting Jenkins slave agent on windows failed with connection timeout.
Environment:
Windows server 2003 R2
Java6
Master: Linux
Slave: Windows
I tried to run it as jnlp and also java -jar cmd but it fails consistently.
INFO: Connecting to [ec2-machine_url]:4317
5 (retrying:2)
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at hudson.remoting.Engine.connect(Engine.java:304)
at hudson.remoting.Engine.run(Engine.java:193)
You don't give much information, but from the error message, you seem to be suggesting that your build machine is running on Amazon EC2.
In that case, it's likely that your security group for the EC2 instance isn't allowing TCP connections from your Jenkins master server to port 4317 on the build machine.
Check that your security group is configured correctly and, if you're using the JNLP client, you can also ensure that the Jenkins master server listens on a fixed port, to make firewall configuration easier:
Manage Jenkins > Configure Global Security > Enable security > TCP port for JNLP agents: Fixed

Neo4j remote shell connection refused on AWS database server

My Neo4j database server is hosted in AWS.
I am using from my Mac this command:
$ ./bin/neo4j-shell -host xx.xxx.xxx.xxx -port 1337 -name shell
The port 1337 is enabled in the AWS Neo4j database server.
I have these lines uncommented in the file neo4j.properties:
remote_shell_enabled=true
remote_shell_host=127.0.0.1
remote_shell_port=1337
I am getting the error: Connection refused
Having the details:
java.rmi.ConnectException: Connection refused to host: xx.xxx.xxx.xxx; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:341)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at org.neo4j.shell.impl.RmiLocation.getBoundObject(RmiLocation.java:261)
at org.neo4j.shell.impl.RemoteClient.findRemoteServer(RemoteClient.java:69)
at org.neo4j.shell.impl.RemoteClient.<init>(RemoteClient.java:62)
at org.neo4j.shell.impl.RemoteClient.<init>(RemoteClient.java:45)
at org.neo4j.shell.ShellLobby.newClient(ShellLobby.java:178)
at org.neo4j.shell.StartClient.startRemote(StartClient.java:302)
at org.neo4j.shell.StartClient.start(StartClient.java:179)
at org.neo4j.shell.StartClient.main(StartClient.java:124)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:147)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 13 more
Don't know how to fix it.
I think you have to open quite a few ports on your server, besides 1337 and 1099 also a port range for RMI ports.
e.g. What port is used by Java RMI connection?
you can also use neo4j over http (e.g. in the browser with /webadmin) or via this script: https://gist.github.com/jexp/a9bf4cd3a16eb6c5997b
This key remote_shell_host=127.0.0.1 that enables you to just connect via loopback. You have to specify by which network adapter you will receive the connection. You can also specify 0.0.0.0 for any your network interfaces.

Resources