gitlab安装,使用,备份和恢复

Gitlab安装

Yum安装:

官网:https://about.gitlab.com

官方安装文档:https://about.gitlab.com/install/#centos-7

清华大学源:https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/

rpm包下载地址:https://packages.gitlab.com/gitlab/gitlab-ce

新建 /etc/yum.repos.d/gitlab_gitlab-ce.repo

[root@jinkai gitlab]# vim /etc/yum.repos.d/gitlab_gitlab-ce.repo

[root@jinkai gitlab]# cat !$

cat /etc/yum.repos.d/gitlab_gitlab-ce.repo

[gitlab-ce]

name=Gitlab CE Repository

baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/

gpgcheck=0

enabled=1

安装依赖包:

[root@jinkai gitlab]#yum -y install curl openssh-server openssh-clients postfix cronie

安装gitlab:

[root@jinkai gitlab]# yum install gitlab-ce

Rpm包安装:

[root@jinkai tools]# mkdir -p /service/tools

[root@jinkai tools]# cd /service/tools/

[root@jinkai tools]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.8.4-ce.0.el7.x86_64.rpm

配置生效并重启服务

[root@jinkai gitlab]#gitlab-ctl reconfigure

[root@jinkai gitlab]# gitlab-ctl restart

常用命令:

gitlab-ctl start # 启动所有 gitlab 组件;

gitlab-ctl stop # 停止所有 gitlab 组件;

gitlab-ctl restart # 重启所有 gitlab 组件;

gitlab-ctl status # 查看服务状态;

vim /etc/gitlab/gitlab.rb # 修改gitlab配置文件;

gitlab-ctl reconfigure # 重新编译gitlab的配置;

gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab;

gitlab-ctl tail # 查看日志;

gitlab-ctl tail nginx/gitlab_access.log

配置域名: vim /var/opt/gitlab/nginx/conf/gitlab-http.conf

# ``外网访问的端口,如果服务器已经有服务器占用了80,那么这里可以改成其它
  listen *:8888;
  server_name gitlab.test.domain.com;

  set $http_host_with_default "gitlab.test.domain.com:8888";

补充说明:因为编译gitlab的配置 /etc/gitlab/gitlab.rb 时会重新生成这个自定义nginx 配置,所以只要 gitlab 的配置配得好,上面的nginx其实不需要自定义的。

网页输入IP就可直接访问

img

遇到502报错可能就是权限问题

chmod -R 755 /var/log/gitlab

然后重新输入IP网页访问,默认管理员root,无密码,它会让我们去定义一个密码

img

img

可以根据需要选择新建项目、新建组合新建用户

新建项目:

img

创建时可以选择在自己用户下创建或者某个群组内创建

img

项目名称,项目名称可以为字母、数字、空格、下划线、中划线和英文点号组成,且必须以字母或数字开头,不能使用中文

项目描述

可见性(库类别)

私有库:只有被赋予权限的用户可见

内部库:登录用户可以下载

公开库:所有人可以下载

创建项目成功,此时若客户端想使用该项目还需要建立与客户端的密钥文件以进行客户端对项目的操作

img

客户端生成秘钥

[root@jinkai tools]# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:h/2mcO56hbV3gyPf8SpVO98XY1ykyjbLVtaUzuQwiTE [email protected]

The key's randomart image is:

+---[RSA 2048]----+

| |

| E .|

| + .o.|

| o ..+.o+|

| S o+ oX+o|

| ..oBo=&o|

| . .+=B+.X|

| +.o=. .=|

| .++. ....|

+----[SHA256]-----+

[root@jinkai tools]# cat /root/.ssh/id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6uxDaTJEtRnM65QQJ2NsKjPLQ8FOvAs18gySLJvRKi/9XTS01n13uwwYtekkR4QvIQsiai7ndhuEv22UZtCiwEkCTw7xAUyCuOzBe81E8jSSaU3cpqK7p67hveyxRUbLG7B3aHwfGFw1xy/mJr1GL96nRJFah9E/cODfdfjIX+tL56jtgpygL3yIUW7fowvwjAjpgkJp8N6Idw6AxD3nrVjATV8Kf2GssnkbIAQ2TI4YrpXh6DLS2exkW1HVRgQdj3ZzFP8PVJCF5Ve9xV7DclXJP4l6X2Lyi3Bx9U50L8SzMesQEFeGdZVFCGBe6AfuIoRHr4dp5j39CREIOhF83 [email protected]

将上面的公钥复制到gitlab中

img img

创建组:

img img img

新建用户:

img img

用户的密码会以邮件的形式发送,但目前没有开启邮箱服务,下面创建用户后,重新编辑用户密码

img img

验证密码是否生效,退出后重新登录

img img

新建用户linuxprobe下也可以创建新的项目和组

img

GitLab备份和恢复

备份:

# ``可以将此命令写入crontab,以实现定时备份

[root@jinkai tools]# gitlab-rake gitlab:backup:create

备份的数据会存储在/var/opt/gitlab/backups

[root@jinkai tools]# ls /var/opt/gitlab/backups/

1607965594_2020_12_15_10.8.4_gitlab_backup.tar

恢复:

# ``停止unicorn和sidekiq,保证数据库没有新的连接,不会有写数据情况

[root@jinkai tools]# gitlab-ctl stop unicorn

ok: down: unicorn: 0s, normally up

[root@jinkai tools]# gitlab-ctl stop sidekiq

ok: down: sidekiq: 0s, normally up

1607965594为备份文件的时间戳

[root@jinkai tools]# gitlab-rake gitlab:backup:restore BACKUP=1607965594

若再次出现502:

chmod -R o+x /var/opt/gitlab/gitlab-rails

备份和恢复参考链接:

https://cloud.tencent.com/developer/article/1622317?from=article.detail.1622316

扩展内容

同学分享的svn文档

http://note.youdao.com/noteshare?id=1bb87a28a2973ae5722bf765882c2d8f

svn 多仓库管理 http://elim.iteye.com/blog/1171108

svn+ssh http://www.linuxfly.org/post/450/

svn清除保存的用户名和密码

http://holy2010.blog.51cto.com/1086044/645944

svn命令详解 http://blog.sina.com.cn/s/blog_963453200101eiuq.html

svn的钩子 http://coolnull.com/1716.html

gitlab修改端口 http://blog.csdn.net/arybd/article/details/54635295

修改主机名 http://www.mamicode.com/info-detail-1316828.html

第三方邮件 http://blog.csdn.net/liuruiqun/article/details/50000213

server ssh 端口并不是22

http://www.cnblogs.com/limx/p/5709101.html http://www.linuxidc.com/Linux/2017-02/141043.htm

应该修改

/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

“# If you use non-standard ssh port you need to specify it”

ssh_port: xxxxx

gitlab的钩子相关配置 http://fighter.blog.51cto.com/1318618/1670667

猜你喜欢

转载自blog.51cto.com/11451960/2640806