Linux自建Gitlab代码管理平台

  • 前言
  • 安装 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
https://s3-us-west-2.amazonaws.com/secure.notion-static.com/7a71ec94-8343-46ce-b0af-c46e128e7aab/Untitled.png

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>) 地址就可以看到这个界面了:

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/2e89f220-480a-49c9-98ce-a8bccb59b941/Untitled.png

遇到问题:

  • 检查防火墙有没有关闭,没有的话先关闭防火墙,不让会访问失败

#查看防火墙状态
firewall-cmd --state

#停止firewall
systemctl stop firewalld.service

#禁止firewall开机启动
systemctl disable firewalld.service

二、使用Gitlab

创建项目

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/1497709f-f4eb-4cbf-9469-15a256b584b3/Untitled.png

配置ssh密钥

这个是重点,不配置的话就不能 close 或者 push 代码。

  1. 找到用户根目录文件夹,查找是否有 .ssh 文件夹,没有则新建
cd ~/.ssh
  1. 检查 .ssh文件下有没有 id_rsaid_rsa.pub 文件,没有则通过下面命令创建
#这里注意‘C’ 是大写的
ssh-keygen -t rsa -C "your_email@youremail.com" 

一路回车就行,到此为止,你本地的密钥对就生成了。

  1. 配置Gitlab SSH Keys

打开你的gitlab,点击你的头像,然后 Settings -> 左栏点击 SSH keys

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b501f5db-996f-4cbe-9992-160d7036a7fe/Untitled.png

通过命令复制你的公钥文件 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,完成了。

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/56cdb3e4-0341-4e79-8531-9cdd21eb3cdd/Untitled.png

本文系作者 @ 原创发布在 极客猿小兵的博客。未经许可,禁止转载。


极客猿小兵 » Linux自建Gitlab代码管理平台

发表回复