gitlab详解与安装
GitLab 是一个基于Web的 Git 仓库管理工具,它为开发团队提供了完整的版本控制功能和协作平台。它与 Git 一起工作,可以帮助团队有效地管理代码,跟踪更改,并简化开发流程。
使用 GitLab,您可以创建仓库来存储代码,并在团队成员之间进行版本控制。您可以通过将代码推送到远程仓库、创建分支、合并请求和解决合并冲突等操作来管理代码的不同版本。GitLab 还提供了许多其他功能,如问题跟踪、持续集成和部署等,以帮助团队更好地协作和交付软件。
通过 GitLab,您可以实现以下功能:
- 仓库管理:创建、克隆和删除代码仓库。
- 版本控制:跟踪代码的历史记录,查看更改和回滚到先前的版本。
- 分支管理:创建和切换分支,合并分支的更改。
- 合并请求:请求将更改合并到主分支中,并进行代码审查。
- 持续集成和部署:自动化构建、测试和部署代码。
- 问题跟踪:创建和分配问题,并跟踪其解决进度。
- 协作和权限管理:与团队成员共享代码,并设置不同权限级别。
安装流程
//安装epel源和git工具
[root@localhost ~]# yum -y install epel-release git wget
//安装依赖
[root@localhost ~]# yum -y install curl openssh-server openssh-clients postfix cronie
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/policycoreutils-python-2.5-34.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh --force --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm
##这里必须装centos7的版本,gitlab不支持新版的,无视依赖强制安装
[root@localhost ~]# systemctl start postfix
[root@localhost ~]# systemctl enable postfix
//下载并安装gitlab的rpm包
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
修改配置文件,并重载配置文件
[root@localhost ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://192.168.37.120' //这一项改成你的ip或者域名
gitlab_workhorse['auth_backend'] = "http://localhost:8080" //去掉这一项的注释
puma['port'] = 8080 //去掉这一项的注释
//重载配置文件
[root@localhost ~]# gitlab-ctl reconfigure
//重启服务
[root@localhost ~]# gitlab-ctl restart
//查看服务版本
[root@localhost ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 16.4.1
这里的用户账号是root密码在/etc/gitlab/initial_root_password中
[root@localhost ~]# cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
# 2. Password hasn't been changed manually, either via UI or via command line.
#
# If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: 2hGy2bMm4zYCo4/9L3sdinhouc0EimB7VoZlxy9DIOs= //这是密码
# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
如果24小时没进行修改密码操作又忘记了密码可以进入这个服务的控制端来破解密码
//进入控制台
[root@localhost ~]# gitlab-rails console -e production
--------------------------------------------------------------------------------
Ruby: ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]
GitLab: 16.4.1 (e6801ed8d44) FOSS
GitLab Shell: 14.28.0
PostgreSQL: 13.11
------------------------------------------------------------[ booted in 32.29s ]
Loading production environment (Rails 7.0.6)
irb(main):001:0>
irb(main):001:0> user = User.where(id: 1).first //id为1的是超级管理员
=> #<User id:1 @root>
irb(main):002:0> user.password = 'ayachinene123!' //密码必须至少8个字符
=> "ayachinene123!"
irb(main):003:0> user.password_confirmation = 'ayachinene123!'
=> "ayachinene123!"
irb(main):004:0> user.save!
=> true
irb(main):005:0> quit
之后我们就可以使用新密码访问界面了
项目管理
创建一个测试项目
上传项目文件到仓库
//Git全局设置
[root@localhost ~]# git config --global user.name "root"
[root@localhost ~]# git config --global user.email "123@163.com"
//上传项目文件
[root@localhost ~]# git clone http://192.168.37.120/root/test.git
Cloning into 'test'...
Username for 'http://192.168.37.120': root
Password for 'http://root@192.168.37.120':
warning: You appear to have cloned an empty repository.
[root@localhost ~]# ls
anaconda-ks.cfg test
[root@localhost test]# git switch --create main //创建一个main项
Switched to a new branch 'main'
[root@localhost test]# echo "nihao" >> ayachinene
[root@localhost test]# git add ayachinene
[root@localhost test]# git commit -m "add ayachinene"
[main (root-commit) 7c56501] add ayachinene
1 file changed, 1 insertion(+)
create mode 100644 ayachinene
[root@localhost test]# git push --set-upstream origin main
主项目就创建好了
内容也是没有问题的
权限管理
创建一个组
在Admin Area
选项中选择Groups选项,上面有个蓝色的new group
按钮
然后创建一个用户加进这个组里
点击旁边的Users按钮
密码只有创建用户后才能定义
重新设置一个密码
我们想让这个用户对这个项目有编辑权限
选中你想要给权限的项目
进入项目的编辑界面
权限要给足,如果选的是Developer权限就不能上传文件而是提交申请
然后我们切换用户
我们试一下上传编辑文件到项目里