- 前言
- 安装 Gitlab
- 使用 Gitlab
今天帮客户迁移代码到自建 gitlab 平台,之前一直是使用的 gitee,企业版本是要收费的,使用 gitlab 功能更加的全面,代码更加安全,再搭配上自带的CI/CD,连 jenkins 自动化都不用配了,非常的nice。
安装配置也非常的简单,让我们一起踏上 Gitlab 的学习之旅吧。
一、安装Gitlab
1. 下载rpm安装包
下载地址(清华镜像):
<https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/>
下载命令:
wget <https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.6.10-ce.0.el7.x86_64.rpm>
2. 文件提权
chmod 777 gitlab-ce-11.6.10-ce.0.el7.x86_64.rpm
3. 安装
rpm -ivh gitlab-ce-11.6.10-ce.0.el7.x86_64.rpm
可能会遇到的问题:
- 提示缺少“policycoreutils-python”依赖
# 安装依赖
yum -y install policycoreutils-python

4. 配置
打开配置文件命令:
vim /etc/gitlab/gitlab.rb
gitllab内部包含的模块会占用80(nginx)、8082(sidekiq)以及9090(prometheus)端口,可能会系统默认的端口产生冲突,因此建议修改默认端口配置:
external_url '<http://ip:8083/gitlab>'
unicorn['port'] = 8081
重启服务
#(每次修改完gitlab.rb文件需要执行该操作)
gitlab-ctl reconfigure
gitlab-ctl restart
gitlab-ctl status
5. 访问
访问 [<http://ip:8083/gitlab>](<http://ip:8083/gitlab>)
地址就可以看到这个界面了:

遇到问题:
- 检查防火墙有没有关闭,没有的话先关闭防火墙,不让会访问失败
#查看防火墙状态
firewall-cmd --state
#停止firewall
systemctl stop firewalld.service
#禁止firewall开机启动
systemctl disable firewalld.service
二、使用Gitlab
创建项目

配置ssh密钥
这个是重点,不配置的话就不能 close
或者 push
代码。
- 找到用户根目录文件夹,查找是否有
.ssh
文件夹,没有则新建
cd ~/.ssh
- 检查
.ssh
文件下有没有id_rsa
和id_rsa.pub
文件,没有则通过下面命令创建
#这里注意‘C’ 是大写的
ssh-keygen -t rsa -C "your_email@youremail.com"
一路回车就行,到此为止,你本地的密钥对就生成了。
- 配置Gitlab SSH Keys
打开你的gitlab,点击你的头像,然后 Settings -> 左栏点击 SSH keys

通过命令复制你的公钥文件 id_rrsa.pub
,你也可以手动复制粘贴到上面的key输入框
cat ~/.ssh/id_rsa.pub
点击 Add key,添加完成。
提交项目
这个就不多说了,程序员都知道,先配置下git信息:
git config --global user.name "root"
git config --global user.email "youremail.com"
初始化个git项目
git init
关联远程库
git remote add origin xxx.git //你的git项目地址
本地提交
git commit -am "init project"
推送到远程仓库
git push -u origin master
ok,完成了。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。