持续集成环境-Maven安装和配置、Tomcat配置

在这里插入图片描述

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 73 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 730 00:05 aopalliance
drwxr-xr-x  4 jenkins jenkins   35 730 00:05 asm
drwxr-xr-x  3 jenkins jenkins   38 730 00:05 backport-util-concurrent
drwxr-xr-x  3 jenkins jenkins   17 730 00:04 ch
drwxr-xr-x  3 jenkins jenkins   25 730 00:05 classworlds
drwxr-xr-x 10 jenkins jenkins  126 730 00:05 com
drwxr-xr-x  3 jenkins jenkins   27 730 00:06 commons-codec
drwxr-xr-x  3 jenkins jenkins   24 730 00:05 commons-io
drwxr-xr-x  3 jenkins jenkins   29 730 00:06 commons-logging
drwxr-xr-x  8 jenkins jenkins  105 730 00:04 io
drwxr-xr-x  5 jenkins jenkins   53 730 00:05 jakarta
drwxr-xr-x  5 jenkins jenkins   56 730 00:05 javax
drwxr-xr-x  3 jenkins jenkins   19 730 00:05 junit
drwxr-xr-x  5 jenkins jenkins   50 730 00:06 net
drwxr-xr-x 25 jenkins jenkins 4096 730 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 730 18:10 README.md
drwxr-xr-x 5 jenkins jenkins 104 730 18:12 springboot
[root@jenkins test01]# cd springboot/
[root@jenkins springboot]# ll
总用量 24
-rwxr-xr-x  1 jenkins jenkins 10070 730 18:10 mvnw
-rw-r--r--  1 jenkins jenkins  6608 730 18:10 mvnw.cmd
-rw-r--r--  1 jenkins jenkins  1664 730 18:10 pom.xml
drwxr-xr-x  4 jenkins jenkins    30 730 18:10 src
drwxr-xr-x 10 jenkins jenkins   266 730 18:12 target

3.会产生一个target目录,里面记录着拉去的代码war包
[root@jenkins springboot]# cd target/
[root@jenkins target]# ll
总用量 27944
drwxr-xr-x 3 jenkins jenkins       47 730 18:12 classes
drwxr-xr-x 3 jenkins jenkins       25 730 18:12 generated-sources
drwxr-xr-x 3 jenkins jenkins       30 730 18:12 generated-test-sources
drwxr-xr-x 4 jenkins jenkins       37 730 18:12 GitLab-0.0.1-SNAPSHOT
-rw-r--r-- 1 jenkins jenkins 17055419 730 18:12 GitLab-0.0.1-SNAPSHOT.war
-rw-r--r-- 1 jenkins jenkins 11558066 730 18:12 GitLab-0.0.1-SNAPSHOT.war.original
drwxr-xr-x 2 jenkins jenkins       28 730 18:12 maven-archiver
drwxr-xr-x 3 jenkins jenkins       35 730 18:12 maven-status
drwxr-xr-x 2 jenkins jenkins      117 730 18:12 surefire-reports
drwxr-xr-x 3 jenkins jenkins       17 730 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 720 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 730 00:22 apache-tomcat-9.0.20
drwxr-xr-x 4 root root  53 729 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.


测试访问:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值