[kubernetes] 交付dubbo之在jenkins配置多jre版本的maven

黄沙百战穿金甲,不破楼兰终不还。这篇文章主要讲述[kubernetes] 交付dubbo之在jenkins配置多jre版本的maven相关的知识,希望能为你提供帮助。
        做这个实验目标是往kubernetes集群里交付dubbo服务,采用jenkins+maven+gitee实现,jenkins使用的是v2.303.1,maven使用3.6.3。本篇是在jenkins里配置maven,并且配置多jre版本。jenkins数据存储在nfs目录中。如下图所示:

主机名
提供服务
host11
nginx-proxy、dns
host21
kubernetes node(v.1.15.2)
host22
kubernetes node(v1.15.2)
host200
harbor、httpd、nfs



??01 配置maven -- java11??
1)在host200下载maven
https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

2)解压
tar xfv apache-maven-3.6.3-bin.tar.gz

3)登录jenkins查看默认的java版本
[root@host22 kube-scheduler]# kubectl exec -it pod/jenkins-7df8bf4ff9-qj85m /bin/bash -n infra
root@jenkins-7df8bf4ff9-qj85m:/# java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)

4)将目录mv到jenkins_home下,后面加上jre的版本,因为jenkins2.303.1默认使用的是jre11.0.12,所以这里我命名为maven-3.6.3-11.0.12
mv apache-maven-3.6.3 /data/nfs-volume/jenkins_home/maven-3.6.3-11.0.12

5)在jenkins中测试maven
root@jenkins-7df8bf4ff9-qj85m:/var/jenkins_home/maven-3.6.3-11.0.12/bin# ./mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /var/jenkins_home/maven-3.6.3-11.0.12
Java version: 11.0.12, vendor: Eclipse Foundation, runtime: /opt/java/openjdk
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"



??02 配置maven java8??
        因为用到的dubbo是使用java8编译的,所以这里需要配置maven java8环境。
1)下载jdk8 --  去oracle下载
jdk-8u291-linux-x64.tar.gz

2)解压到jenkins_home,这时候会生成一个jdk1.8.0_291的目录
tar xfv jdk-8u291-linux-x64.tar.gz -C /data/nfs-volume/jenkins_home/

3)配置新的maven环境
cd /data/nfs-volume/jenkins_home/
# 复制一份现有的maven配置
cp -a maven-3.6.3-11.0.12 maven-3.6.3-8u291
# 修改mvn文件,添加JAVA_HOME配置文件,注意这里写的是jenkins容器中的路径。
vi maven-3.6.3-8u291/bin/mvn
#!/bin/sh
JAVA_HOME=/var/jenkins_home/jdk1.8.0_291/jre

【[kubernetes] 交付dubbo之在jenkins配置多jre版本的maven】4)jenkins中测试
[root@host22 kube-scheduler]# kubectl exec -it pod/jenkins-7df8bf4ff9-qj85m /bin/bash -n infra
root@jenkins-7df8bf4ff9-qj85m:/# cd /var/jenkins_home/maven-3.6.3-8u291/bin/
root@jenkins-7df8bf4ff9-qj85m:/var/jenkins_home/maven-3.6.3-8u291/bin# ./mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /var/jenkins_home/maven-3.6.3-8u291
Java version: 1.8.0_291, vendor: Oracle Corporation, runtime: /var/jenkins_home/jdk1.8.0_291/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"


    推荐阅读