Jenkins+git+docker构建持续化集成环境

该博客介绍了如何搭建一个基于Jenkins、Git和Docker的持续集成环境。首先,讲解了CI/CD的基本概念和发布流程设计。接着,部署了Harbor镜像仓库和Git服务器。在Jenkins服务器上,详细说明了Jenkins的安装、配置和项目创建过程,包括构建业务基础镜像(tomcat:v1)、配置SSH连接凭据和创建maven构建任务。最后,演示了如何在构建后通过脚本将war包封装进tomcat镜像并推送到Harbor,以及自动化部署到远程测试主机。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CI/CD介绍

在这里插入图片描述在这里插入图片描述

发布流程设计

在这里插入图片描述

Jenkins服务器 192.168.100.109
Git/Harbor 192.168.100.110
Docker 192.168.100.111
工具 版本
CentOS 7.5_x64
Maven 3.5
Tomcat 8
JDK 1.8
Jenkins 2.6
Docker CE 18.03.1
部署Harbor镜像仓库
服务器 IP地址
Git/Harbor 192.168.100.110
#创建ca证书
[root@localhost ~]# mkdir -p /data/ssl
[root@localhost ~]# cd /data/ssl
[root@localhost ssl]# which openssl
/usr/bin/openssl
[root@localhost ssl]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout ca.key -x509 -days 365 -out ca.crt
Generating a 4096 bit RSA private key
...........................++
.............................................................................................................................................................................++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Beijing
Locality Name (eg, city) [Default City]:Beijing
Organization Name (eg, company) [Default Company Ltd]:yunjisuan
Organizational Unit Name (eg, section) []:yunjisuan
Common Name (eg, your name or your server's hostname) []:www.yunjisuan.com
Email Address []:

#生成证书请求
[root@localhost ssl]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout www.yunjisuan.com.key -out www.yunjisuan.com.csr
Generating a 4096 bit RSA private key
..........................................................................................................................................................................................................................................................++
.......................................++
writing new private key to 'www.yunjisuan.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Beijing
Locality Name (eg, city) [Default City]:Beijing
Organization Name (eg, company) [Default Company Ltd]:yunjisuan
Organizational Unit Name (eg, section) []:yunjisuan
Common Name (eg, your name or your server's hostname) []:www.yunjisuan.com
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

#生成注册表主机的证书
[root@localhost ssl]# openssl x509 -req -days 365 -in www.yunjisuan.com.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out www.yunjisuan.com.crt
Signature ok
subject=/C=CN/ST=Beijing/L=Beijing/O=yunjisuan/OU=yunjisuan/CN=www.yunjisuan.com
Getting CA Private Key
[root@localhost ssl]# ll
total 24
-rw-r--r--. 1 root root 2049 Jan 17 02:37 ca.crt
-rw-r--r--. 1 root root 3272 Jan 17 02:37 ca.key
-rw-r--r--. 1 root root   17 Jan 17 02:39 ca.srl
-rw-r--r--. 1 root root 1931 Jan 17 02:39 www.yunjisuan.com.crt
-rw-r--r--. 1 root root 1716 Jan 17 02:39 www.yunjisuan.com.csr
-rw-r--r--. 1 root root 3272 Jan 17 02:39 www.yunjisuan.com.key

#信任自签发的证书
[root@localhost ssl]# cp www.yunjisuan.com.crt /etc/pki/ca-trust/source/anchors/
[root@localhost ssl]# update-ca-trust enable
[root@localhost ssl]# update-ca-trust extract

#安装docker-ce社区版
[root@localhost ssl]#  yum -y install yum-utils device-mapper-persistent-data lvm2
[root@localhost ssl]# curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2424  100  2424    0     0   2681      0 --:--:-- --:--:-- --:--:--  2681
[root@localhost ssl]# yum -y install docker-ce
[root@localhost ssl]# systemctl start docker
[root@localhost ssl]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ssl]# docker version
Client:
 Version:           18.09.1
 API version:       1.39
 Go version:        go1.10.6
 Git commit:        4c52b90
 Built:             Wed Jan  9 19:35:01 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.1
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       4c52b90
  Built:            Wed Jan  9 19:06:30 2019
  OS/Arch:          linux/amd64
  Experimental:     false
#安装ha
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值