阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 7.4下部署GitLab+Jenkins持续集成环境

161次阅读
没有评论

共计 4365 个字符,预计需要花费 11 分钟才能阅读完成。

GitLab 介绍
GitLab 是一个用于仓库管理系统的开源项目,使用 Git 作为代码管理工具,并在此基础上搭建起来的 web 服务。

系统环境准备

建议:内存 4G 以上不然带不动
[root@linuxidc-jenkins ~]# cat /etc/RedHat-release
CentOS Linux release 7.4.1708 (Core)
[root@linuxidc-jenkins ~]# uname -r
3.10.0-693.el7.x86_64

# 关闭 firewalld 和 NetWorkManager

[root@linuxidc-jenkins ~]# systemctl stop firewalld
[root@linuxidc-jenkins ~]# systemctl stop NetWorkManager

# 永久关闭
[root@linuxidc-jenkins ~]# systemctl disable firewalld
[root@linuxidc-jenkins ~]# systemctl disable NetWorkManager

# 关闭 selinux
[root@linuxidc-jenkins ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
[root@linuxidc-jenkins ~]# setenforce 0

# 更换阿里源和下载 epel 源
[root@linuxidc-jenkins ~]#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@linuxidc-jenkins ~]#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@linuxidc-jenkins ~]#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

#yum 源更新,重启系统

[root@linuxidc-jenkins ~]# yum update && reboot

# 安装相应工具
[root@linuxidc-jenkins ~]yum install curl policycoreutils openssh-server openssh-clients postfix -y
[root@linuxidc-jenkins ~]systemctl start postfix

# 新建 GitLab 源
[root@linuxidc-jenkins ~]# vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
[root@linuxidc-jenkins ~]# yum makecache
[root@linuxidc-jenkins ~]# yum install -y gitlab-ce

# 安装 git 工具
[root@linuxidc-jenkins ~]# yum install git -y

# 加载配置文件并启动,时间稍长
[root@linuxidc-jenkins ~]# gitlab-ctl reconfigure

#gitlab-ctl 其他命令
启动:gitlib-ctl start
关闭:gitlab-ctl stop
重启:gitlab-ctl restart
重载配置:gitlab-ctl reconfigure
查看状态:gitlab-ctl status

# 查看端口保证 80 端口不被占用
[root@linuxidc-jenkins ~]# lsof -i:80
COMMAND PID      USER  FD  TYPE DEVICE SIZE/OFF NODE NAME
nginx  700      root    7u  IPv4  16903      0t0  TCP *:http (LISTEN)
nginx  804 gitlab-www    7u  IPv4  16903      0t0  TCP *:http (LISTEN)

#gitlab 配置文件路径
/etc/gitlab/gitlab.rb 

浏览器登录 gitlab,输入 http://ip 进入下图:

入下图:

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

先输入密码,然后 Register 填写账户信息进入新建项目

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

填写 ssh 认证

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境]

测试拉取代码

[root@linuxidc-jenkins ~]# git clone git@linuxidc-jenkins:web/web-demo.git
Cloning into ‘web-demo’…
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
[root@linuxidc-jenkins ~]# ls
anaconda-ks.cfg  epel-release-latest-7.noarch.rpm  web-demo
[root@linuxidc-jenkins ~]# ls web-demo/
index.html  README.md

上传代码

[root@linuxidc-jenkins web-demo]# echo “test” >>test.txt
 
[root@linuxidc-jenkins web-demo]# git config –global user.email “you@example.com”
[root@linuxidc-jenkins web-demo]# git config –global user.name “Your Name”
[root@linuxidc-jenkins web-demo]# git add *
[root@linuxidc-jenkins web-demo]# git commit -m “add test.txt”
[master 5df66f7] add test.txt
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt
[root@linuxidc-jenkins web-demo]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from ‘matching’ to ‘simple’. To squelch this message
and maintain the current behavior after the default changes, use:
 
  git config –global push.default matching
 
To squelch this message and adopt the new behavior now, use:
 
  git config –global push.default simple
 
See ‘git help config’ and search for ‘push.default’ for further information.
(the ‘simple’ mode was introduced in Git 1.7.11. Use the similar mode
‘current’ instead of ‘simple’ if you sometimes use older versions of Git)
 
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 314 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@linuxidc-jenkins:web/web-demo.git
  18a57cf..5df66f7  master -> master

GitLab 上查看:

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

# 安装 JenKins

[root@linuxidc-jenkins web-demo]# sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
 
[root@linuxidc-jenkins web-demo]# sudo rpm –import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
[root@linuxidc-jenkins web-demo]# yum install Java jenkins –y
#JenKins 默认端口为 8080,因为 gitlab 已经占用我们需要更改。
 
[root@linuxidc-jenkins web-demo]# vim /etc/sysconfig/jenkins
 
JENKINS_PORT=”8080″  —> JENKINS_PORT=”8081″

# 启动 JenKins

[root@linuxidc-jenkins web-demo]# /etc/init.d/jenkins start
Starting jenkins (via systemctl):                          [OK]

# 浏览器登录 JenKins,地址:http://192.168.247.135:8081/

正在启动;

正在启动;

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

进入有个密码路径,系统上查看这个文件并把密码复制粘贴才能登录;

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

选择推荐安装;

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

创建一个管理员

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

开始使用 jenkins

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

下面实现持续集成

进入主页 – 创建一个新任务

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

输入项目名称 — 构建一个自由风格的软件项目 — 确认

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

General– 填写项目描述

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

源码管理 – 安装 git 插件 – 授权认证

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

ssh 私钥认证我们在系统上查看粘贴进去即可。

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

Credentials—选择 root

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

查看 gitlab 版本

[root@linuxidc-jenkins ~]# rpm -aq|grep gitlab

gitlab-ce-10.6.0-ce.0.el7.x86_64

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

点击立即构建

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

点击控制台输出查看

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

控制台输出,SUCCESS 则构建成功

CentOS 7.4 下部署 GitLab+Jenkins 持续集成环境

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计4365字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中