gitlab 部署 + cicd 集成

一. gitlab 安装

##设置hosts
 

在gitlab 服务端 /etc/hosts
192.168.xx.140 gitlab.sxw.com

1.1 centos7 上安装gitlab ,设置 gitlab yum 源
 

vim /etc/yum.repos.d/gitlab-ce.repo

 [root@test-gitlab ~]# cat /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1


1.2 yum 安装

yum install gitlab-ce -y


1.3 设置gitlabrb

cp /etc/gitlab/gitlab.rb{,.bk}

##配置gitlab.rb 的文件,这里省略修改成自己的域名
vim /etc/gitlab/gitlab.rb
external_url 'http://gitlab.sxw.com'


###设置成https
# vim /etc/gitlab/gitlab.rb
external_url 'https://gitlab.sxw.com'

nginx['enable'] = true
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/server.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/server.key"

##生成的ca证书在 /etc/gitlab/ssl/中,gitlab-runner 需要证书才能注册

##设计成https 时,gitlab-runner 注册时要增加ca 证书,需要把gitlab server 端的证书copy 到gitlab-ruuner 机器上

gitlab-runner register -n \
--tls-ca-file=/root/key/server.crt \
--url=https://gitlab.xxx.com/ \
--registration-token=yeN77YKpPHVPgsWkJMhj \
--name=test1 \
--run-untagged=true \
--locked=true \
--executor=shell 

1.5 启动 gitlab
 

gitlab-ctl reconfigure
gitlab-ctl status

 ##检查gitlab 设置

gitlab-rake gitlab:check SANITIZE=true --trace 


 首次登陆会提示修改密码,https://ip


1.6 客户端 安装git
 

 yum install git -y


 #常用命令

git config --global user.name "Administrator"
git config --global user.email "admin@example.com"

Create a new repository

git clone git@gitlab.sxw.com:root/test3.git
cd test3
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Existing folder

cd existing_folder
git init
git remote add origin git@gitlab.sxw.com:root/test3.git
git add .
git commit -m "Initial commit"
git push -u origin master

Existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.sxw.com:root/test3.git
git push -u origin --all
git push -u origin --tags


二.安装gitlab-runner

2.1 下载

curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh |bash


2.2 安装gitlab-runner

yum install gitlab-runner

systemctl status gitlab-runner

2.2 gitlab-runner 注册的时候需要 查看 gitlab 的token ,在管理中心,手动设置


[root@test-gitlab gitlab-runner]#

gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=1372 revision=4745a6f3 version=11.8.0
Running in system-mode.                            
                                                   
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://192.168.xxx.159
Please enter the gitlab-ci token for this runner:
6LtpK4-yDVEPVv5uxPiM
Please enter the gitlab-ci description for this runner:
[test-gitlab]: gitlab-runner-test
Please enter the gitlab-ci tags for this runner (comma separated):
test.tag,test2.tag
Registering runner... succeeded                     runner=6LtpK4-y
Please enter the executor: kubernetes, shell, ssh, virtualbox, docker+machine, docker, docker-ssh, parallels, docker-ssh+machine:
shell

##把gitlab-ci.yml 放到 项目代码的更目录

 

egrep -v '#|^$' .gitlab-ci.yml 
job1:
   script: "pwd"
job2:
   script: "uname -a"

##测试

##过程如下

 

##若失败,查看失败内容

    GitLab-CI: unable to access 'http://gitlab-ci-token:xxxxxx@<custom-gitlab-url>:<port>/group/project.git/'; Empty reply from server
    Running with gitlab-runner 11.8.0 (4745a6f3)
  on test1 6YpAXpZG
Using Shell executor...
Running on test-gitlab-runner...
Cloning repository...
Cloning into '/home/gitlab-runner/builds/6YpAXpZG/0/root/test1'...
fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.example.com/root/test1.git/': Could not resolve host: gitlab.example.com; Name or service not known
bash: line 66: cd: /home/gitlab-runner/builds/6YpAXpZG/0/root/test1: No such file or directory
ERROR: Job failed: exit status 1

##修改 gitlab 的配置
egrep -v '#|^$' /etc/gitlab/gitlab.rb
external_url 'http://gitlab.sxw.com'

gitlab-ctl reconfigure
gitlab-ctl start

##再重新执行,可正常运行。

接下来进行代码打包和分发、部署。

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

石兴稳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值