jenkins服务基于脚本测试代码包

一、安装tomcat

[root@localhost ~]# yum -y install java-11-openjdk

下载9.0版本
https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.67/bin/apache-tomcat-9.0.67.tar.gz

//解压tomcat,并部署安装
[root@localhost ~]# ls
anaconda-ks.cfg  apache-tomcat-9.0.67.tar.gz  index.html  initial-setup-ks.cfg
[root@localhost ~]# tar -xzf apache-tomcat-9.0.67.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache-tomcat-9.0.67  etc    include  lib64    sbin   src
bin                   games  lib      libexec  share
[root@localhost local]# ln -s apache-tomcat-9.0.67/ tomcat

//启动tomcat,测试能否访问tomcat首页
[root@localhost local]# cd tomcat/
[root@localhost tomcat]# ls
bin           CONTRIBUTING.md  logs       RELEASE-NOTES  webapps
BUILDING.txt  lib              NOTICE     RUNNING.txt    work
conf          LICENSE          README.md  temp
[root@localhost tomcat]# bin/startup.sh 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.

在这里插入图片描述

二、部署jenkins服务

//下载jenkins到/usr/local/tomcat/webapps/目录下

在这里插入图片描述

在这里插入图片描述

//下载下来后会自动解压
[root@localhost webapps]# wget http://mirrors.jenkins.io/war-stable/2.346.3/jenkins.war
[root@localhost webapps]# ls
docs  examples  host-manager  jenkins  jenkins.war  manager  ROOT
//启动服务
[root@localhost tomcat]# bin/catalina.sh stop
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[root@localhost tomcat]# bin/catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.

//浏览器访问jinkins
在这里插入图片描述

三、搭建环境

1、//查看上图框出来的文件,该文件中记录这密码,复制密码并登录
[root@localhost webapps]# cat /root/.jenkins/secrets/initialAdminPassword
5df5645c44ba4fcabc530878afe6419a

在这里插入图片描述

在这里插入图片描述

2、登录用户

在这里插入图片描述

3、先在node1主机上生成一个密钥,传给node2主机

[root@node1 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
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:ojaZEA83PIZ2E74XWOBHbbPmVR+a8obt98rcimp44Qk root@node1
The key's randomart image is:
+---[RSA 3072]----+
|    o.o.         |
|   = =  +   . .  |
|  = % o. o . + . |
| . B * .o o o .  |
|  . o ooS. =     |
|   . = .E o +    |
|    *    + =     |
|   . .  . = .+.. |
|         o....=+o|
+----[SHA256]-----+

[root@node1 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.47.137
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.47.137 (192.168.47.137)' can't be established.
ECDSA key fingerprint is SHA256:cdmo9f87/nd53T0zrSlRNvEDKskgEb2tSwNZINSW84U.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.47.137's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.47.137'"
and check to make sure that only the key(s) you wanted were added.


4、在node2上部署tomcat(按上面步骤相同即可)
[root@node2 webapps]# ss -antl
State   Recv-Q  Send-Q         Local Address:Port     Peer Address:Port  Process  
LISTEN  0       128                  0.0.0.0:22            0.0.0.0:*              
LISTEN  0       128                     [::]:22               [::]:*              
LISTEN  0       1         [::ffff:127.0.0.1]:8005                *:*              
LISTEN  0       100                        *:8080                *:* 

四、部署jenkins流水线服务

发布流水线的方法我在这里给大家介绍两种,一种是脚本的方式,一种是使用文本参数的方式
首选都需要在jinkins所在服务器,也就是node1中安装git和maven工具
[root@node1 ~]# yum -y install git maven

这里安装完成后利用脚本的方式访问不到,只能在虚拟机中进行访问
http://github.com/lizhenliang/tomcat-java-demo.git

在这里插入图片描述

第二种方法呢,就是通过文本参数来实现流水线项目发布
为了实验效果呢,我们首先把node2中刚刚接收到的站点给删除掉
//新建流水线项目
在这里插入图片描述

在这里插入图片描述

//添加git下载信息 http://github.com/lizhenliang/tomcat-java-demo.git
1.添加文本参数
在这里插入图片描述

2.//添加字符参数,打包
在这里插入图片描述

3.//添加字符参数 定义tomcat路径
在这里插入图片描述

4.//添加文本参数 定义客户端ip
在这里插入图片描述

5、//编写流水线脚本
pipeline {
agent any

stages { 
	stage(‘pull code’) { 
		steps { 
			git "${git_url}"
		}
	}
	stage(‘package’) { 
		steps { 
			sh """ 
			mvn clean
			mvn package
			"""
		}
	}
	stage('deploy') { 
		steps { 
         			sh """                
         			scp target/${maven_package}.war root@${client_ip}:${tomcat_path}/webapps/
                  		ssh root@${client_ip} '${tomcat_path}/bin/catalina.sh stop && ${tomcat_path}/bin/catalina.sh start'
                  	   	"""
     		}
	}
}

}

在这里插入图片描述

6、//刚刚定义好的变量参数值
确认信息,点击build构建测试
在这里插入图片描述

如果程序执行为绿色则代表执行成功
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

此时客户端已经能够看到
在这里插入图片描述

利用客户端ip测试成功
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值