Jenkins配置节点(master和slave同一台机器)

前提:
1、本案例是在VMware安装CentOS7的环境完成的
2、CentOS7已配置java环境
3、CentOS7安装tomcat下启动的jenkins

Jenkins配置节点

ssh-keygen配置证书,三次回车

[root@bogon ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:dOVo3O2Iz9RQ4c/nTdgIjrwznDAUU2S6q/kCS6n8tPs root@bogon
The key's randomart image is:
+---[RSA 2048]----+
|        oo+ . o. |
|         * = +   |
|        + = = o  |
|       o = + * * |
|     .  S + + = *|
|    +    = *   oo|
| . o.o  . * o   o|
|  o....o   o     |
|   .+oEo.        |
+----[SHA256]-----+

ssh连接slave机ip,自动生成known_hosts文件

# 连接slave机ip
[root@bogon ~]# ssh 192.168.111.129
The authenticity of host '192.168.111.129 (192.168.111.129)' can't be established.
ECDSA key fingerprint is SHA256:M5BalHyNXU5W49c5/9iZgC4Hl370O0Wr/c5S/FYFIvw.
ECDSA key fingerprint is MD5:28:23:b8:eb:af:d1:bd:bb:8c:77:e0:01:3c:62:7a:cb.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.111.129' (ECDSA) to the list of known hosts.
root@192.168.111.129's password: # 输入登录账户密码
Last login: Wed Jan  5 16:10:37 2022 from bogon

[root@bogon ~]# cd .ssh/
[root@bogon .ssh]# ll
总用量 12
-rw-------. 1 root root 1675 15 16:09 id_rsa
-rw-r--r--. 1 root root  392 15 16:09 id_rsa.pub
-rw-r--r--. 1 root root  177 15 16:10 known_hosts

给known_hosts文件赋予可700权限

[root@bogon .ssh]# chmod 700 known_hosts 
[root@bogon .ssh]# ll
总用量 12
-rw-------. 1 root root 1675 15 16:09 id_rsa
-rw-r--r--. 1 root root  392 15 16:09 id_rsa.pub
-rwx------. 1 root root  177 15 16:10 known_hosts

系统管理–>节点管理–>新增节点
在这里插入图片描述
连接成功
在这里插入图片描述
在这里插入图片描述

遇到问题1

在这里插入图片描述

SSHLauncher{host='192.168.111.129', port=22, credentialsId='aa9fc1b1-ccc2-470f-a612-f20e32b55dea', jvmOptions='', javaPath='', prefixStartSlaveCmd='', suffixStartSlaveCmd='', launchTimeoutSeconds=60, maxNumRetries=10, retryWaitTime=15, sshHostKeyVerificationStrategy=hudson.plugins.sshslaves.verifiers.KnownHostsFileKeyVerificationStrategy, tcpNoDelay=true, trackCredentials=true}
[01/05/22 17:08:28] [SSH] Opening SSH connection to 192.168.111.129:22.
/root/.ssh/known_hosts [SSH] No Known Hosts file was found at /root/.ssh/known_hosts. Please ensure one is created at this path and that Jenkins can read it.
Key exchange was not finished, connection is closed.
SSH Connection failed with IOException: "Key exchange was not finished, connection is closed.", retrying in 15 seconds. There are 10 more retries left.
/root/.ssh/known_hosts [SSH] No Known Hosts file was found at /root/.ssh/known_hosts. Please ensure one is created at this path and that Jenkins can read it.
Key exchange was not finished, connection is closed.
SSH Connection failed with IOException: "Key exchange was not finished, connection is closed.", retrying in 15 seconds. There are 9 more retries left.

解决办法:
注意:要用登录slave节点的用户操作

cd ~ # 回到家目录
ssh-keygen # 三次回车
ssh 192.168.111.129 # Slave节点机的ip地址
cd .ssh/
chmod 700 known_hosts

遇到问题2

在这里插入图片描述

SSHLauncher{host='192.168.111.129', port=22, credentialsId='aa9fc1b1-ccc2-470f-a612-f20e32b55dea', jvmOptions='', javaPath='', prefixStartSlaveCmd='', suffixStartSlaveCmd='', launchTimeoutSeconds=60, maxNumRetries=10, retryWaitTime=15, sshHostKeyVerificationStrategy=hudson.plugins.sshslaves.verifiers.KnownHostsFileKeyVerificationStrategy, tcpNoDelay=true, trackCredentials=true}
[01/05/22 17:34:03] [SSH] Opening SSH connection to 192.168.111.129:22.
Searching for 192.168.111.129 in /root/.ssh/known_hosts
Searching for 192.168.111.129:22 in /root/.ssh/known_hosts
[01/05/22 17:34:03] [SSH] SSH host key matches key in Known Hosts file. Connection will be allowed.
[01/05/22 17:34:03] [SSH] 认证成功。
[01/05/22 17:34:04] [SSH] The remote user's environment is:
BASH=/usr/bin/bash
BASHOPTS=cmdhist:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_EXECUTION_STRING=set
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="2" [2]="46" [3]="2" [4]="release" [5]="x86_64-redhat-linux-gnu")
BASH_VERSION='4.2.46(2)-release'
DIRSTACK=()
EUID=0
GROUPS=()
HOME=/root
HOSTNAME=bogon
HOSTTYPE=x86_64
ID=0
IFS=$' \t\n'
LANG=zh_CN.UTF-8
LESSOPEN='||/usr/bin/lesspipe.sh %s'
LOGNAME=root
MACHTYPE=x86_64-redhat-linux-gnu
MAIL=/var/mail/root
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
PIPESTATUS=([0]="0")
PPID=5436
PS4='+ '
PWD=/root
SELINUX_LEVEL_REQUESTED=
SELINUX_ROLE_REQUESTED=
SELINUX_USE_CURRENT_RANGE=
SHELL=/bin/bash
SHELLOPTS=braceexpand:hashall:interactive-comments
SHLVL=1
SSH_CLIENT='192.168.111.129 37138 22'
SSH_CONNECTION='192.168.111.129 37138 192.168.111.129 22'
TERM=dumb
UID=0
USER=root
XDG_RUNTIME_DIR=/run/user/0
XDG_SESSION_ID=25
_=/etc/bashrc
[01/05/22 17:34:04] [SSH] Checking java version of /root/.jenkins/jdk/bin/java
Couldn't figure out the Java version of /root/.jenkins/jdk/bin/java
bash: /root/.jenkins/jdk/bin/java: 没有那个文件或目录

[01/05/22 17:34:04] [SSH] Checking java version of java
Couldn't figure out the Java version of java
bash: java: 未找到命令

[01/05/22 17:34:04] [SSH] Checking java version of /usr/bin/java
Couldn't figure out the Java version of /usr/bin/java
bash: /usr/bin/java: 没有那个文件或目录

[01/05/22 17:34:04] [SSH] Checking java version of /usr/java/default/bin/java
Couldn't figure out the Java version of /usr/java/default/bin/java
bash: /usr/java/default/bin/java: 没有那个文件或目录

[01/05/22 17:34:04] [SSH] Checking java version of /usr/java/latest/bin/java
Couldn't figure out the Java version of /usr/java/latest/bin/java
bash: /usr/java/latest/bin/java: 没有那个文件或目录

[01/05/22 17:34:04] [SSH] Checking java version of /usr/local/bin/java
Couldn't figure out the Java version of /usr/local/bin/java
bash: /usr/local/bin/java: 没有那个文件或目录

[01/05/22 17:34:04] [SSH] Checking java version of /usr/local/java/bin/java
Couldn't figure out the Java version of /usr/local/java/bin/java
bash: /usr/local/java/bin/java: 没有那个文件或目录

java.io.IOException: Java not found on hudson.slaves.SlaveComputer@331d1385. Install a Java 8 version on the Agent.
	at hudson.plugins.sshslaves.JavaVersionChecker.resolveJava(JavaVersionChecker.java:89)
	at hudson.plugins.sshslaves.SSHLauncher$1.call(SSHLauncher.java:454)
	at hudson.plugins.sshslaves.SSHLauncher$1.call(SSHLauncher.java:423)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
[01/05/22 17:34:04] Launch failed - cleaning up connection
[01/05/22 17:34:04] [SSH] 连接关闭。

解决办法一:
在Slave机上找到java命令目录,配置在节点上
在这里插入图片描述
解决办法二:建立软连接

cd /root/.jenkins/
mkdir jdk
cd jdk/
mkdir bin
cd bin/
ln -s /usr/local/jdk1.8.0_231/bin/java /root/.jenkins/jdk/bin/java
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值