阿里云登录远程服务器
登录成功会出现命令行
环境初始化
# 1.配置相关环境,依赖安装
yum -y install policycoreutils openssh-server openssh-clients postfix
yum install policycoreutils-python # 命令行问:is this ok? 输入:Y
systemctl enable sshd && sudo systemctl start sshd
systemctl enable postfix && systemctl start postfix
# 2.关闭防火墙或者防火墙增加白名单
systemctl stop firewalld.service
安装gitlab-ce
清华园地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
安装版本的链接地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.9.0-ce.0.el7.x86_64.rpm
# 下载软件
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.9.0-ce.0.el7.x86_64.rpm --no-check-certificate
# 开始安装:yum install -y gitlab-ce-12.9.0-ce.0.el7.x86_64.rpm
rpm -ivh gitlab-ce-12.9.0-ce.0.el7.x86_64.rpm
# 编辑站点地址
vi /etc/gitlab/gitlab.rb
# 在文件中修改 external_url 和 nginx['listen_port']的 key 对应的内容 # vi编辑器三种模式:
# - 命令模式(默认模式,按字母i进入插入模式),输入:/external_url就可以定位external_url处
# - 插入模式(可编辑文本,此模式左下方会有-- INSERT --提示),按键盘Esc退出键返回到命令模式
# - 输入完成并推出到命令模式,输入" :wq "执行退出并保存
external_url 'http://11.111.11.111:8000' # 把IP改为你自己的云服务器公网IP
nginx['listen_port'] = 8000 # 文本中的源码是:# nginx['listen_port'] = nil
# 配置和重启
gitlab-ctl reconfigure
gitlab-ctl restart
# 其他相关命令
gitlab-ctl start
gitlab-ctl stop
gitlab-ctl status
在浏览器输入:http://11.111.111.111:8000进入gitlab登录页
初始账号为:root, 进入页面的时候会提示你修改密码
安装 git
yum install git -y
安装 gitlab runner
清华园镜像: https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/
安装版本的链接地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-12.9.0-1.x86_64.rpm
通过包管理工具安装
# 下载软件
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-12.9.0-1.x86_64.rpm --no-check-certificate
# 安装
rpm -ivh gitlab-runner-12.9.0-1.x86_64.rpm
# 启动
systemctl start gitlab-runner
# 查看状态
systemctl status gitlab-runner
# 查看是否存在此命令
gitlab-runner -h
gitlab-runner 注册
gitlab-runner注册的三种类型
获取token
- 获取share类型的token(对所有项目有效)
- 获取group类型的token(对一个组的项目有效),我创建了一个项目组,取名为:frontend
- 获取specific类型的token(对当前项目有效),需要先创建一个项目
交互式注册
# 注册指令
gitlab-runner register
# 注册过程中需要要回答5个问题
# 1. Enter the GitLab instance URL (for example, https://gitlab.com/):服务器地址
输入获取到的url: http://11.111.111.111:8000
# 2. Enter the registration token:
输入获取到的token
# 3. Enter a description for the runner:
随便输入点描述
# 4. Enter tags for the runner (comma-separated):tags的名称
随便输:test
# 5. Enter an executor: custom, docker, instance, kubernetes, docker-windows, parallels, shell, ssh, virtualbox, docker-autoscaler, docker+machine:
输入:shell
测试项目自动化部署
- 创建一个项目并克隆到本地,添加一个文件
.gitlab-ci.yml
stages:
- build-prod # 打包
- deploy-prod # 部署
cache: # 缓存
paths:
- node_modules
# 生产打包
build-job:
stage: build-prod
tags:
- build
script:
- echo "=====start build======"
when: manual # 手动触发流程
artifacts:
paths:
- dist
# 生成部署
deploy-job:
stage: deploy-prod
tags:
- deploy
script:
- echo "=====start deploy======"
when: manual # 手动触发流程
artifacts:
paths:
- dist
- git提交修改,可以看到该项目生成了一条流水。