GitLab的使用(内网"GitHub"==GitLab, 商业公司不想公开代码可以用,但没必要,GitHub不公开代码每年才几百块钱)

GitLab是DevOps全系列的工具,我们只讲代码版本管理
安装:
yum install -y curl policycoreutils-python openssh-server
//下载版本GitLab_V10.2.2,
//官网地址:https://packages.gitlab.com/gitlab/gitlab-ce
//清华镜像:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
把文件"gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm"拷贝到/usr/local/src/目录
rpm -ivh gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm
//GitLab最好装在独立的机器上,内存最好4G以上,因为GitLab有十几个服务,监听了多个端口
配置文件:vim /etc/gitlab/gitlab.rb
修改:external_url 'http://192.168.1.2'
gitlab-ctl reconfigure //改了配置文件要执行这句话
gitlab-ctl status //查看GitLab服务状态
gitlab-ctl restart/start/stop //重启启动停止GitLab服务
gitlab-ctl tail //看日志的,整体的日志,具体某个服务的日志在对于目录里
访问GitLab:http://192.168.1.2/


1.初次登录系统要求修改root的密码
2.改了密码后使用root账户登录系统


GitLab服务的构成:
.....
Nginx,做静态web服务器
gitlab-workhorse:反向代理
logrotate:日志
postgresql:数据库
redis:缓存
sidekiq:任务队列
unicorn:任务托管
..

GitLab目录:
配置文件:/etc/gitlab/gitlab.rb
数据:/var/opt/gitlab/
仓库:/var/opt/gitlab/git-data
备份:/var/opt/gitlab/backups
程序的安装位置:/opt/gitlab


GitLab的使用:
1.配置GitLab
**取消登录界面的"注册"功能:
导航条--'扳手'设置--settings--Sign-up Restrictions-sign-up enabled的勾去掉即可--保存退出
**改登录页面定制Log等:
导航条--'扳手'设置--Appearance--改log和欢迎标语
'组'里有'仓库','组'里有'人','人'就和'仓库'对应上了
**创建组:
导航条--'扳手'设置--New Group--输入的路径和名称保持一致,例如"group1"--选Private
private-组里才能看到,internal-能登录的就能看到,public-都能看到
**创建用户:
导航条--'扳手'设置--New user--输入必填项--确定--点edit设置初始密码
点击"Impersonate"可以模拟用户登录
**把用户加入组里:
导航条--'扳手'设置--Group
Add user to the group:
选择组,选择角色(角色是内置的固定角色)
**建立仓库
建仓库需要选组,设置仓库名称,点击创建即可
仓库加入到组里,组里的用户就能看到组里的仓库了
**
把node1客户机的公钥添加到GitLab的root用户的设置里,
这时,node1客户机就可以推送仓库到master分支。
git remote add gitlab git@10.0.0.11:oldboy/git_test.git //gitlab是远程仓库名称
git push -u gitlab master
推送成功。
现在,GitLab里就有了master分支了。现在把master分支克隆到第二台客户机node2上
git clone git@10.0.0.11:oldboy/git_test.git
在node2上生成公钥,把node2上的公钥添加到dev用户上
//我们可以配给root,这样node1和node2都会上传到master分支
git remote //自动就有连接了
在node2上建一个分支:
git branch dev
git checkout dev
touch dev
git add .
git commit -m "commit dev"
这里报错,需要创建用户信息:user和email
创建完后,可以推送成功。

**master分支是稳定的,不是谁都能推送到master分支
所以root才有权限推送到master分支,开发人员clone下来之后
必须先创建一个'dev'分支,在'dev'分支上进行推送,推送完后
提交合并分支申请,由root用户去合并到master分支,
这时候,需要把master设置为保护分支,这个分支不能被masters角色之外的用户推送:

root用户登录--在仓库页面--Repository-ProtectedBranches--选择master--选择具有"Masters"角色的人才能合并保护分支
查看角色权限:https://docs.gitlab.com/ee/user/permissions.html

推完后提交合并分支的申请:
点击CreateMergeRequest,有两个必填参数:
1.提交给谁 Assigraee参数 2.哪个分支合并到哪个分支


GitLab仓库的备份和还原:
配置文件中加入(备份)
gitlab_rails['backup_path'] = '/data/backup/gitlab' #备份路径
gitlab_rails['backup_keep_time'] = 604800 #备份文件保存多少秒,这里是7天
###### 赋予权限,这是自动的,不需要设置 ######
# mkdir /data/backup/gitlab
##### chown -Rf git.git /data/backup/gitlab #####
/usr/bin/gitlab-rake gitlab:backup:create #备份命令
0 2 * * * /usr/bin/gitlab-rake gitlab:backup:create #加入corntab定时任务

恢复
先删库:找到库--Settings--General--RemoveProject
停止数据写入服务:
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
开始恢复:
gitlab-rake gitlab:backup:restore BACKUP=1533732629_2018_08_08_10.2.2 #备份文件只写数字部分
重启服务:
gitlab-ctl restart
原文地址:https://www.cnblogs.com/staff/p/11555061.html