Gitlab安装
Gitlab 是一个用于仓库管理系统的开源项目。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。可通过web界面进行访问公开或者私人项目。它拥有与Github类似的功能,能够游览源代码,管理缺陷和注释。可以管理团队对仓库的访问。它还提供一个代码片段收集功能实现代码的复用
处理器
- 1个核心最多支持100个用户,但由于所有工作和后台作业都在同一个核心上运行,因此应用程序可能会慢一点
- 2核是建议的核心数,最多支持500个用户
- 4个核心最多可支持2,000个用户
- 8个核心最多支持5,000个用户
- 16个内核最多可支持10,000个用户
- 32个核心最多可支持20,000个用户
- 64个内核最多可支持40,000个用户
内存
你需要至少8GB的可寻址内存(RAM +交换)来安装和使用GitLab!操作系统和任何其他正在运行的应用程序也将使用内存,因此请记住,在运行GitLab之前,您至少需要4GB可用空间。使用较少的内存GitLab将在重新配置运行期间发出奇怪的错误,在使用期间会出现500错误。
- 4GB RAM + 4GB交换支持多达100个用户,但速度非常慢,所有安装的建议内存大小为8GB RAM,最多支持100个用户
- 16GB RAM最多支持2,000个用户
- 32GB RAM最多可支持4,000个用户
- 64GB RAM最多可支持8,000个用户
- 128GB RAM最多可支持16,000个用户
- 256GB RAM最多支持32,000个用户
常用网站:
官网:https://about.gitlab.com
- ce社区版
- ee企业版
国内镜像:https://mirrors,tuna.tsinghua.edu.cn/gitlab---ce/yum/
安装环境:
- Centos6,7
- 2G内存(实验)生产(至少4G)
- 安装包:gitlab-ce-10.2.2-ce
- 禁用防火墙,关闭selinux
官网查看帮助文档
选择,进去找就行了install,我这里选择的Centos7安装
进行下载curl,policycoreutils-python openssh-server解决gitlab的依赖环境
[root@web01 ~]# yum install -y curl policycoreutils-python openssh-server [root@web01 ~]# systemctl enable sshd [root@web01 ~]# systemctl strat sshd
gitlab安装包下载地址:https://packages.gitlab.com/gitlab/gitlab-ce
我们选10.2.2 el7版本
解决好依赖才能进行安装
[root@web01 ~]# rpm -ivh gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm
根据提示修改
GitLab was unable to detect a valid hostname for your instance. Please configure a URL for your GitLab instance by setting `external_url` configuration in /etc/gitlab/gitlab.rb file. Then, you can start your GitLab instance by running the following command: sudo gitlab-ctl reconfigure [root@web01 ~]# vim /etc/gitlab/gitlab.rb external_url 'http://gitlab.example.com' 可以改域名也可以改IP地址,不能删除http。格式不变 external_url 'http://192.168.1.7' 改好按提示输入 [root@web01 ~]# gitlab-ctl reconfigure 初始化
Gitlab相关命令
查看运行状态:
gitlab-ctl status
[root@web01 ~]# gitlab-ctl status
run: gitaly: (pid 7837) 16s; run: log: (pid 7512) 51s
run: gitlab-monitor: (pid 7861) 16s; run: log: (pid 7658) 43s
run: gitlab-workhorse: (pid 7821) 17s; run: log: (pid 7449) 65s
run: logrotate: (pid 7493) 57s; run: log: (pid 7492) 57s
run: nginx: (pid 7953) 2s; run: log: (pid 7472) 63s
run: node-exporter: (pid 7641) 45s; run: log: (pid 7640) 45s
run: postgres-exporter: (pid 7894) 15s; run: log: (pid 7770) 29s
run: postgresql: (pid 7230) 94s; run: log: (pid 7229) 94s
run: prometheus: (pid 7872) 15s; run: log: (pid 7709) 35s
run: redis: (pid 7170) 100s; run: log: (pid 7169) 100s
run: redis-exporter: (pid 7691) 37s; run: log: (pid 7690) 37s
run: sidekiq: (pid 7433) 67s; run: log: (pid 7432) 67s
run: unicorn: (pid 7395) 68s; run: log: (pid 7394) 68s
以下命令都可对单个服务使用,状态后面加服务名称就可以了 如:gitlab-ctl start nginx
启动:
gitlab-ctl start
[root@web01 ~]# gitlab-ctl start
停止:
gitlab-ctl stop
[root@web01 ~]# gitlab-ctl stop
重启:
gitlab-ctl restart
[root@web01 ~]# gitlab-ctl restart
查看版本:
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
[root@web01 ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION 10.2.2
Gitlab页面
输入前面改的URL地址
默认更改密码,用户名为root
可以修改描述信息,和logo
保存退出看看效果
Gitlab使用
顺序:首先创建组--->创建项目--->创建用户(等建立后远程仓库后再创建)
创建组
创建项目
Gitlab建立远程仓库连接
都创建好,远程仓库就建好了,下面要做的就是做认证,点击对应的组可以看到
在linux上删除原先的远程仓库(因为我有)
git remote remove 远程仓库名
[root@web01 data]# git remote remove origin
根据gitlab给的组详细说明操作就行了(根据自己的情况操作)
Existing Git repository
cd 工作目录
git remote rename origin old-origin
git remote add origin git@www.hebaobao.xx:test/git_data.git
[root@web01 data]# git remote add origin git@192.168.5.7:test/git_data.git
然后把本地仓库的代码推送上去
git push -u origin master
[root@web01 data]# git push -u origin master
Counting objects: 12, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (12/12), 887 bytes | 0 bytes/s, done.
Total 12 (delta 0), reused 0 (delta 0)
To git@192.168.5.7:test/git_data.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
测试是否成功:
做一下操作再次推送
[root@web01 data]# git log --oneline --decorate
c0df58b (HEAD, testing) echo 1234 > xx.txt
f6fac96 touch xx.txt
02f3fcf modified jin tian meichumeng
c8d21bc add a
想添加一个文件,必须要通过本地仓库才能上传远程仓库,要是想把所有数据上传到远程git仓库,首先先保证分支数据同步到master上,别忘记同步master的时候,要在master上执行(git merge 分支名)命令,才能上传
[root@web01 data]# git merge testing Merge made by the 'recursive' strategy. xx.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 xx.txt [root@web01 data]# git push -u origin master Counting objects: 10, done. Delta compression using up to 8 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (8/8), 738 bytes | 0 bytes/s, done. Total 8 (delta 0), reused 0 (delta 0) To git@192.168.5.7:test/git_data.git 8cadd36..96ce756 master -> master Branch master set up to track remote branch master from origin.
Gitlab添加用户
添加用户按步骤添加就行了,但是要添加到组里面,才能看见项目,不然登陆啥也看不见
用管理员用户进行添加dev进组
用户就可以下载代码了,更改代码以后也可以由本地仓库推送到远程仓库,这里有一个问题,普通用户可以由本地仓库,直接推送代码到远程的master主干上,这样不行,要保护master
做完这些,我们dev普通用户下载代码,到另一台服务器,再推送到master主干,测试是否成功
在web02服务器上从远程仓库下载代码
[root@web02 ~]# git clone git@192.168.5.7:test/git_data.git Warning: Permanently added '192.168.5.7' (ECDSA) to the list of known hosts. remote: Counting objects: 20, done. remote: Compressing objects: 100% (10/10), done. remote: Total 20 (delta 0), reused 0 (delta 0) Receiving objects: 100% (20/20), done. [root@web02 ~]# cd git_data/ [root@web02 git_data]# ll total 8 -rw-r--r-- 1 root root 43 Feb 13 14:02 a -rw-r--r-- 1 root root 5 Feb 13 14:02 xx.txt 添加新内容上传本地仓库 [root@web02 git_data]# echo ww >>a [root@web02 git_data]# git commit -am "echo ww >>a" *** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got 'root@web02.(none)') 提示我们没有创建用户和邮箱 [root@web02 git_data]# git config --global user.name "dev" [root@web02 git_data]# git config --global user.email "dev@qq.com" [root@web02 git_data]# git commit -am "echo ww >>a" [master c82164e] echo ww >>a 1 file changed, 1 insertion(+) 进行本地仓库代码上传远程仓库master主干 [root@web02 git_data]# git push -u origin master Counting objects: 5, done. Delta compression using up to 8 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 297 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: GitLab: You are not allowed to push code to protected branches on this project. To git@192.168.5.7:test/git_data.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'git@192.168.5.7:test/git_data.git' 说明master被保护了,我们设置成功了
Gitlab代码合并请求
既然开发人员无法直接把代码放到master上,那么就要发送一个请求由主管进行审批通过后,合并到master
注意:
每次由本地仓库向远程仓库上传代码的时候,从远程仓库下载最新的数据,保持和远程仓库一致在更新,不然上传不了远程仓库,发现上传不了就用git pull origin 分支名在拉取缺少的,进行上传
如何发送分支到master合并请求示例:
登陆管理员用户进行啥看合并请求
要是想要对远程仓库gitlab上项目的内容做更改,必须要通过本地仓库,在本地仓库上修改后,由工作目录再次上传本地仓库,在用git push -u origin 分支名上传本地仓库,经主管审核合并master
删除GitLab 上的文件夹
git rm -r
git add .
git commit
git push -u origin master

评论