ci/cd自动化部署

官方文档

https://docs.gitlab.com/ci/#step-1-create-a-gitlab-ciyml-file

安装gitLab

下载liunx系统,使用国内镜像快点

北大镜像

bash 复制代码
https://mirrors.pku.edu.cn/centos/7.9.2009/isos/x86_64/

安装依赖

bash 复制代码
## 安装 所需依赖
sudo yum install -y curl policycoreutils-python openssh-server perl
bash 复制代码
## sshd 设置为自定启动
sudo systemctl enable sshd
## 启动 sshd
sudo systemctl start sshd
## 查看 sshd 状态
sudo systemctl status sshd
bash 复制代码
gitlab-ctl start                  # 启动所有 gitlab 组件;
gitlab-ctl stop                   # 停止所有 gitlab 组件;
gitlab-ctl restart                # 重启所有 gitlab 组件;
gitlab-ctl status                 # 查看服务状态;
gitlab-ctl reconfigure            # 启动服务;
vi /etc/gitlab/gitlab.rb         # 修改默认的配置文件;
gitlab-ctl tail

配置镜像

复制代码
curl -fsSL https://packages.gitlab.cn/repository/raw/scripts/setup.sh | /bin/bash

successfully added gitlab-jh repo. 就代表成功了

安装gitlab

复制代码
# 查看本机ip地址
ip addr
复制代码
# 将地址挂载到你本地
# sudo EXTERNAL_URL="http://你的ip地址" yum install -y gitlab-jh
sudo EXTERNAL_URL="http://192.168.126.3" yum install -y gitlab-jh

gitlab常用命令

bash 复制代码
gitlab-ctl start                  # 启动所有 gitlab 组件;
gitlab-ctl stop                   # 停止所有 gitlab 组件;
gitlab-ctl restart                # 重启所有 gitlab 组件;
gitlab-ctl status                 # 查看服务状态;
gitlab-ctl reconfigure            # 启动服务;
vi /etc/gitlab/gitlab.rb         # 修改默认的配置文件;
gitlab-ctl tail

安装完毕后启动

bash 复制代码
gitlab-ctl start   

查看初始密码

默认用户名是root

复制代码
cat /etc/gitlab/initial_root_password

gitlab-runer的安装

新启一台虚拟机 192.168.126.4

如果wget西在不下来,可以使用curl来下载

复制代码
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash

下载runner镜像到runner服务器

bash 复制代码
https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-fips-17.1.0-1.x86_64.rpm

安装

复制代码
 rpm -ivh gitlab-runner-fips-17.1.0-1.x86_64.rpm

运行命令

sudo systemctl enable --now gitlab-runner # 启动并设置开机自启

sudo systemctl status gitlab-runner # 检查运行状态

sudo gitlab-runner register #注册到gitlab cicd

sudo systemctl start gitlab-runner # 启动服务

sudo systemctl enable gitlab-runner # 设置开机自启

systemctl status gitlab-runner # 查看状态

注册runner

gitlab服务器地址 192.168.126.3

密钥: GR134894165zr_dh31udktRZVvP7X


复制代码
gitlab-runner register --url http://192.168.126.3/ --registration-token GR134894165zr_dh31udktRZVvP7X

创建runer

获取名称或token

bash 复制代码
gitlab-runner list
Runtime platform                                    arch=amd64 os=linux pid=23101 revision=4d7093e1 version=18.0.2
Listing configured runners                          ConfigFile=/etc/gitlab-runner/config.toml
shared-runner                                       Executor=shell Token=glrt-t1_S_oxATgzctBfXdcDvUt- URL=http://192.168.126.3

通过名称或者token取消注册

bash 复制代码
# 通过name取消注册# 
gitlab-runner unregister --name testci

# 通过token取消注册# 

gitlab-runner unregister --token glrt-ajwZ3Tgfxjy6tXbA2hgd

查看配置

bash 复制代码
 cat /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
connection_max_age = "15m0s"
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "shared-runner"
  url = "http://192.168.126.3"
  id = 1
  token = "glrt-t1_S_oxATgzctBfXdcDvUt-"
  token_obtained_at = 2025-06-07T05:00:35Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "shell"
  [runners.cache]
    MaxUploadedArchiveSize = 0
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
相关推荐
乘云数字DATABUFF1 天前
5分钟部署开源APM Databuff:OpenTelemetry全链路追踪入门实战
运维·后端
荣--3 天前
一键部署不是为了省时间 —— 它是把"买来的 PaaS"变成"自己的平台"的拐点
运维·zabbix·工程化·一键部署·平台化·边界设计
江华森3 天前
动手实战学 Docker — 从零到集群编排完全指南
运维
宋均浩3 天前
# Docker 镜像瘦身实战:从 1.2G 到 80MB 的五个优化步骤
ci/cd·docker
Avan_菜菜4 天前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
SelectDB5 天前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
XIAOHEZIcode6 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220707 天前
如何搭建本地yum源(上)
运维
宋均浩8 天前
# GitHub Actions 实战:从零搭建 CI/CD 流水线的 5 个核心配置
ci/cd
大树8810 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai