1.部署maven编译环境(在Jenkins服务器上部署)
1.下载maven
[root@jenkins opt]# wget https://mirrors.aliyun.com/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
[root@jenkins opt]# ll
总用量 563300
-rw-r--r-- 1 root root 9506321 7月 3 2020 apache-maven-3.6.3-bin.tar.gz
2.解压
root@jenkins opt]# tar xf apache-maven-3.6.3-bin.tar.gz -C /usr/local/
3.查看java版本
[root@jenkins opt]# java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
4.添加环境变量
[root@jenkins opt]# vim /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export MAVEN_HOME=/usr/local/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$JAVA_HOME:$PATH
5.重载环境变量,测试mvn
[root@jenkins opt]# source /etc/profile
6.mvn的版本
[root@jenkins opt]# mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/apache-maven-3.6.3
Java version: 1.8.0_292, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.21.1.el7.x86_64", arch: "amd64", family: "unix"
2. 全局工具配置关联JDK和Maven
Jenkins->Global Tool Configuration->JDK->新增JDK,配置如下:
Jenkins->Global Tool Configuration->Maven-> 新增Maven,配置如下:
3.添加 Jenkins全局变量
Manage Jenkins->Configure System->Global Properties ,添加三个全局变量
JAVA_HOME、M2_HOME、PATH+EXTRA
4.创建maven仓库(Jenkins服务器)
1.创建maven仓库
[root@jenkins ~]# mkdir -pv /data/software/repository
mkdir: 已创建目录 "/data"
mkdir: 已创建目录 "/data/software"
mkdir: 已创建目录 "/data/software/repository"
[root@jenkins ~]# chown jenkins.jenkins /data/software/repository/
2.修改配置文件
[root@jenkins ~]# vim /usr/local/apache-maven-3.6.3/conf/settings.xml
<!--本地仓库-->
<localRepository>/data/software/repository</localRepository>
<mirrors>
<!--阿里云镜像-->
<mirror>
<id>aliyun-maven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven mirror</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
注意:
相当于把maven阿里云的仓库下载到本地仓库
5.测试Maven是否配置成功
1.查看本地仓库可以看见拉取的依赖
[root@jenkins ~]# cd /data/software/repository
[root@jenkins repository]# ll
总用量 4
drwxr-xr-x 3 jenkins jenkins 25 7月 30 00:05 aopalliance
drwxr-xr-x 4 jenkins jenkins 35 7月 30 00:05 asm
drwxr-xr-x 3 jenkins jenkins 38 7月 30 00:05 backport-util-concurrent
drwxr-xr-x 3 jenkins jenkins 17 7月 30 00:04 ch
drwxr-xr-x 3 jenkins jenkins 25 7月 30 00:05 classworlds
drwxr-xr-x 10 jenkins jenkins 126 7月 30 00:05 com
drwxr-xr-x 3 jenkins jenkins 27 7月 30 00:06 commons-codec
drwxr-xr-x 3 jenkins jenkins 24 7月 30 00:05 commons-io
drwxr-xr-x 3 jenkins jenkins 29 7月 30 00:06 commons-logging
drwxr-xr-x 8 jenkins jenkins 105 7月 30 00:04 io
drwxr-xr-x 5 jenkins jenkins 53 7月 30 00:05 jakarta
drwxr-xr-x 5 jenkins jenkins 56 7月 30 00:05 javax
drwxr-xr-x 3 jenkins jenkins 19 7月 30 00:05 junit
drwxr-xr-x 5 jenkins jenkins 50 7月 30 00:06 net
drwxr-xr-x 25 jenkins jenkins 4096 7月 30 00:06 org
2.进入代码目录test01下
[root@jenkins repository]# cd /var/lib/jenkins/workspace/test01
[root@jenkins test01]# ll
总用量 4
-rw-r--r-- 1 jenkins jenkins 23 7月 30 18:10 README.md
drwxr-xr-x 5 jenkins jenkins 104 7月 30 18:12 springboot
[root@jenkins test01]# cd springboot/
[root@jenkins springboot]# ll
总用量 24
-rwxr-xr-x 1 jenkins jenkins 10070 7月 30 18:10 mvnw
-rw-r--r-- 1 jenkins jenkins 6608 7月 30 18:10 mvnw.cmd
-rw-r--r-- 1 jenkins jenkins 1664 7月 30 18:10 pom.xml
drwxr-xr-x 4 jenkins jenkins 30 7月 30 18:10 src
drwxr-xr-x 10 jenkins jenkins 266 7月 30 18:12 target
3.会产生一个target目录,里面记录着拉去的代码war包
[root@jenkins springboot]# cd target/
[root@jenkins target]# ll
总用量 27944
drwxr-xr-x 3 jenkins jenkins 47 7月 30 18:12 classes
drwxr-xr-x 3 jenkins jenkins 25 7月 30 18:12 generated-sources
drwxr-xr-x 3 jenkins jenkins 30 7月 30 18:12 generated-test-sources
drwxr-xr-x 4 jenkins jenkins 37 7月 30 18:12 GitLab-0.0.1-SNAPSHOT
-rw-r--r-- 1 jenkins jenkins 17055419 7月 30 18:12 GitLab-0.0.1-SNAPSHOT.war
-rw-r--r-- 1 jenkins jenkins 11558066 7月 30 18:12 GitLab-0.0.1-SNAPSHOT.war.original
drwxr-xr-x 2 jenkins jenkins 28 7月 30 18:12 maven-archiver
drwxr-xr-x 3 jenkins jenkins 35 7月 30 18:12 maven-status
drwxr-xr-x 2 jenkins jenkins 117 7月 30 18:12 surefire-reports
drwxr-xr-x 3 jenkins jenkins 17 7月 30 18:12 test-classes
二、运行环境====Tomcat服务器
1.安装tomcat
```bash
1.下载
[root@gdx1 ~]# yum install java-1.8.0-openjdk* -y
[root@web ~]# rz
[root@web ~]# ll
-rw-r--r-- 1 root root 10851264 7月 20 17:52 apache-tomcat-9.0.20.tar.gz
2.解压
[root@web ~]# tar -xf apache-tomcat-9.0.20.tar.gz -C /usr/local/
[root@web ~]# cd /usr/local/
[root@web local]# ll
总用量 0
drwxr-xr-x 9 root root 220 7月 30 00:22 apache-tomcat-9.0.20
drwxr-xr-x 4 root root 53 7月 29 19:14 jenkins-tomcat
3.启动Tomcat
[root@web local]# /usr/local/apache-tomcat-9.0.20/bin/startup.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-9.0.20
Using CATALINA_HOME: /usr/local/apache-tomcat-9.0.20
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-9.0.20/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/apache-tomcat-9.0.20/bin/bootstrap.jar:/usr/local/apache-tomcat-9.0.20/bin/tomcat-juli.jar
Tomcat started.
2.配置tomcat权限
后续Jenkins部署项目到Tomcat服务器,需要用到Tomcat的用户,所以修改tomcat以下配置, 添加用户及权限。
```bash
[root@web ]# vim /usr/local/apache-tomcat-9.0.45/conf/tomcat-users.xml
#插入到倒数第二行
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,tomcat,admin-gui,admin-script"/>
[root@web ]# vim /usr/local/apache-tomcat-9.0.45/webapps/manager/META-INF/context.xml
#注释掉这段内容
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
原因:他只默认127.0.0.%来访问,其他不允许。
注意:但是以后在生产中这段配置jenkins的内网的ip
#重启
[root@web local]# /usr/local/apache-tomcat-9.0.20/bin/shutdown.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-9.0.20
Using CATALINA_HOME: /usr/local/apache-tomcat-9.0.20
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-9.0.20/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/apache-tomcat-9.0.20/bin/bootstrap.jar:/usr/local/apache-tomcat-9.0.20/bin/tomcat-juli.jar
[root@web local]# /usr/local/apache-tomcat-9.0.20/bin/startup.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-9.0.20
Using CATALINA_HOME: /usr/local/apache-tomcat-9.0.20
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-9.0.20/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/apache-tomcat-9.0.20/bin/bootstrap.jar:/usr/local/apache-tomcat-9.0.20/bin/tomcat-juli.jar
Tomcat started.
测试访问: