仓库管理系统之:GitLab

xiaohai 2019-05-25 08:53:50 2109人围观 标签: Git 
简介GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。

GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。

GitLab拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

1、安装相关依赖
yum install curl policycoreutils openssh-server openssh-clients postfix systemctl enable postfix systemctl start postfix
2、添加GitLab仓库
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
3、安装GitLab
yum install -y gitlab-ce
4、配置GitLab
gitlab-ctl reconfigure

这一步执行时间较长。执行完后可以先查看下GitLab的状态

[root@localhost ~]# gitlab-ctl status run: alertmanager: (pid 37068) 556s; run: log: (pid 26280) 1061s run: gitaly: (pid 36057) 569s; run: log: (pid 24906) 1258s run: gitlab-monitor: (pid 36992) 562s; run: log: (pid 25965) 1102s run: gitlab-workhorse: (pid 36959) 565s; run: log: (pid 25681) 1132s run: logrotate: (pid 25765) 1122s; run: log: (pid 25781) 1121s run: nginx: (pid 25709) 1128s; run: log: (pid 25724) 1127s down: node-exporter: 0s, normally up, want up; run: log: (pid 25866) 1115s run: postgres-exporter: (pid 37083) 555s; run: log: (pid 26428) 1034s run: postgresql: (pid 25127) 1246s; run: log: (pid 25173) 1243s run: prometheus: (pid 37014) 561s; run: log: (pid 26155) 1077s run: redis: (pid 24778) 1268s; run: log: (pid 24827) 1265s run: redis-exporter: (pid 37003) 562s; run: log: (pid 26051) 1090s run: sidekiq: (pid 25552) 1141s; run: log: (pid 25578) 1138s run: unicorn: (pid 25469) 1146s; run: log: (pid 25496) 1145s

一切都正常后,可以通过http://ip进行访问,第一次进入需要设置root的密码,设置完后会重新进行登录。登录后的界面如下:

image.png

5、配置仓库的地址
[root@localhost ~]# cd /opt/gitlab/embedded/service/gitlab-rails/config [root@localhost config]# vim gitlab.yml #编辑,修改host为自己域名或IP ## GitLab settings gitlab: ## Web server settings (note: host is the FQDN, do not include http://) host: 192.168.71.109 port: 80 https: false [root@localhost config]# gitlab-ctl restart #重启
6、创建一个项目

点击Create a project后

image.png

7、添加秘钥
$ ssh-keygen $ cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDP12ov0WzL9iE+ZjLE1ZrHe+YyUYg7ngPs9laamn1wge/4aLhD5whiSed2lx9TTbHgUegiuJGSbhCxaWMZzDi9ffHxvrEeK9AAR5zwVMjS35CxfKGkcZMjdev8d27HD3sz91j1t0wr8NToEvgDwaVVxNwP1sg1lCVSkUDZXzGZMaporW7vkhYdT8ZJeKv5oqiKokXkMYc8h85n64nk9nEyycaQ08aAc2M/GcLSzqt2xLkCbgoXMhzzEq0VDn8d+8Y66nEPDWPuqqK6qYS20mUCbrap/Y1vIJMlSsS/z1S+G/kZQh2Lkbri/H4HAoYkT5koaKOd2eE8YQU2k2YPc7t xxxxxx@qq.com
8、配置免密验证

image.png

9、测试提交
$ git clone git@192.168.71.109:root/test-project-1.git $ cd test-project-1/ $ touch README.md $ echo "test-project-1" > README.md $ git add README.md $ git commit -m "add README.md" $ git push -u origin master

以上就是整个GitLab的安装、配置和使用的方式。如果想使用中文的界面,可以参考https://gitlab.com/xhang/gitlab