Gitlab CI-CD自动化部署SpringBoot项目

一、概述

本文主要记录如何通过Gitlab CI/CD自动部署SpringBoot项目jar包。

二、前期准备

准备三台 CentOS7服务器,分别部署以下服务:

序号 系统 IP 服务
1 CentOS7 192.168.56.10 Gitlab
2 CentOS7 192.168.56.11 Runner (安装Docker)
3 CentOS7 192.168.56.12 SpringBoot 项目 jar 包(安装jdk、maven等)

上述服务也可以只用一台CentOS7,将所有程序都部署在同一机器上,但是更建议分开部署;

三、总体架构图

Gitlab CICD 架构图
说明:

  1. Gitlab Server 用于部署Gitlab远程仓库,对CPU和内存要求比较高,建议4核CPU,4GB以上内存;
  2. Runner Server 用于部署执行.gitlab-ci.yml 文件中定义的 stage(阶段);需要具有访问 Gitlab 仓库的权限,可以下载代码,通过注册方式(gitlab-runner register)实现;
  3. Your Laptop Server 用户部署你的应用程序,这里就是SpringBoot的 jar 包,需要提前安装 JDK 和 Maven 并配置好环境变量;

四、环境搭建

1、环境准备(可选)

三台服务器执行以下命令:

yum -y upgrade
yum -y install wget
yum -y install vim

2、Gitlab安装

参考地址:
https://about.gitlab.com/install/#centos-7
https://blog.csdn.net/duyusean/article/details/80011540

(1)安装并配置必要的依赖

sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld

(2)安装邮件服务

sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix

(3)添加 gitlab 镜像

参考地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.4.0-ce.0.el7.x86_64.rpm

(4)安装 gitlab 安装命令

rpm -i gitlab-ce-13.4.0-ce.0.el7.x86_64.rpm --nodeps --force

安装成功后图片:
gitlab安装成功

(5)修改gitlab配置文件指定服务器ip和自定义端口

vim  /etc/gitlab/gitlab.rb

(6)重置并启动GitLab

gitlab-ctl reconfigure
gitlab-ctl restart

提示 "ok: run:"表示启动成功

(7)访问 GitLab页面

如果报502,等待一段时间后再刷新试试,一般1-2分钟左右。
GitLab登录页面
本文设置的账号:root ,新密码:11112222

3、安装 Runner

参考官方文档:https://docs.gitlab.com/runner/install/linux-manually.html#install-gitlab-runner-manually-on-gnulinux 中的 Using binary file Install

(1)下载一个二进制文件

sudo curl -L --output /usr/local/bin/gitlab-runner https://g
  • 3
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值