目录
1. gitlab简介
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。主要针对软件开发过程中产生的代码和文档进行管理, Gitlab主要针对group
和project
两个维度进行代码和文档管理, 其中group
是群组, project
是工程项目, 一个group
可以管理多个project
, 可以理解为一个群组中有多项软件开发任务, 而一个project
中可能包含多个branch
, 意为每个项目中有多个分支, 分支间相互独立, 不同分支可以进行归并。
2. gitlab部署
2.1 配置yum源
阿里云yum源
https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.77d61b114IRn5w
阿里云Epel 镜像
https://developer.aliyun.com/mirror/epel?spm=a2c6h.13651102.0.0.77d61b114IRn5w
国内可以使用的清华大学的镜像源安装GitLab,相关配置及安装参照:
https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/
[root@node1 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@node1 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@node1 ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@node1 ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@node1 ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@node1 ~]# cat > /etc/yum.repos.d/gitlab-ce.repo <<EOF
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
gpgcheck=0
enabled=1
EOF
[root@node1 ~]# yum clean all
[root@node1 ~]# yum makecache
2.2 关闭防火墙 SElinux
// 关闭防火墙
[root@node1 ~]# systemctl disable --now firewalld
// 关闭selinux
[root@node1 ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
[root@node1 ~]# setenforce 0
2.3 安装epel git 等依赖包
极狐GitLab:https://gitlab.cn/install/
[root@node1 ~]# yum -y install perl git curl epel-release openssh-server openssh-clients postfix cronie wget vim
[root@node1 ~]# rpm -qa |grep policy
policycoreutils-2.9-9.el8.x86_64
selinux-policy-3.14.3-41.el8.noarch
selinux-policy-targeted-3.14.3-41.el8.noarch
[root@node1 ~]# rpm -e policycoreutils --nodeps
[root@node1 ~]# rpm -qa |grep policy
selinux-policy-3.14.3-41.el8.noarch
selinux-policy-targeted-3.14.3-41.el8.noarch
[root@node1 ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/policycoreutils-python-2.5-34.el7.x86_64.rpm
[root@node1 ~]# rpm -ivh --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm
warning: policycoreutils-python-2.5-34.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:policycoreutils-python-2.5-34.el7################################# [100%]
2.4 启动 Postfix
为了发送电子邮件通知
[root@node1 ~]# systemctl enable --now postfix
2.5 安装gitlab
yum安装
[root@node1 ~]# yum install gitlab-ce
或wget下载本地安装
[root@node1 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
[root@node1 ~]# rpm -ivh gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
2.6 修改配置文件
[root@node1 ~]# vim /etc/gitlab/gitlab.rb
......
external_url 'http://192.168.226.128' //将此处设为gitlab的服务器ip地址亦或域名
......
2.7 重载配置文件并重启gitlab
[root@node1 ~]# reboot
[root@node1 ~]# gitlab-ctl reconfigure
......
gitlab Reconfigured!
[root@node1 ~]# gitlab-ctl restart
ok: run: alertmanager: (pid 2478) 1s
ok: run: gitaly: (pid 2488) 0s
ok: run: gitlab-exporter: (pid 2504) 0s
ok: run: gitlab-kas: (pid 2519) 0s
ok: run: gitlab-workhorse: (pid 2529) 0s
ok: run: logrotate: (pid 2541) 1s
ok: run: nginx: (pid 2547) 0s
ok: run: node-exporter: (pid 2555) 1s
ok: run: postgres-exporter: (pid 2561) 0s
ok: run: postgresql: (pid 2571) 0s
ok: run: prometheus: (pid 2580) 0s
ok: run: puma: (pid 2595) 0s
ok: run: redis: (pid 2600) 1s
ok: run: redis-exporter: (pid 2609) 0s
ok: run: sidekiq: (pid 2622) 1s
[root@node1 ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 16.4.1
2.8 破解管理员密码,重新设置
[root@node1 ~]# gitlab-rails console -e production
irb(main):001:0> user = User.where(id: 1).first //id为1的是超级管理员
irb(main):002:0> user.password = 'xixi610000' //密码必须至少8个字符
irb(main):003:0> user.password_confirmation = 'xixi610000'
irb(main):004:0> user.save
irb(main):005:0> exit
2.9 登录
3. gitlab管理
3.1 项目创建
权限分为私有、内部和公开三种可见性级别
私有(Private):项目访问必须明确授予每个用户。 如果此项目是在一个群组中,群组成员将会获得访问权限。
内部( Internal):该项目允许所有已登录到当前GitLab服务器的用户访问。
公开(Public):该项目允许任何人访问。
创建新储存库 存放一个test.txt文件
[root@node1 ~]# git config --global user.name "Administrator"
[root@node1 ~]# git config --global user.email "admin@example.com"
[root@node1 ~]# git clone http://192.168.226.128/root/test.git
Cloning into 'test'...
Username for 'http://192.168.226.128': root
Password for 'http://root@192.168.226.128':
warning: You appear to have cloned an empty repository.
[root@node1 ~]# cd test
[root@node1 test]# git switch --create main
Switched to a new branch 'main'
[root@node1 test]# echo "hello word" > test.txt
[root@node1 test]# git add test.txt
[root@node1 test]# git commit -m "add test.txt"
[main (root-commit) 774b986] add test.txt
1 file changed, 1 insertion(+)
create mode 100644 test.txt
[root@node1 test]# git push --set-upstream origin main
Username for 'http://192.168.226.128': root
Password for 'http://root@192.168.226.128':
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 221 bytes | 221.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To http://192.168.226.128/root/test.git
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.