代码管理平台(三)——GITLAB

版权声明:欢迎转载,转载请注明出处 https://blog.csdn.net/miss1181248983/article/details/82598250

22.4 GITLAB

在讲完搭建GIT服务器之后,我们都知道这并不完美,只适用于开发人员较少的公司。所以寻求一种更好的解决方案,国内有CODING、码云等都可以作为选择,这样可以不用自己维护;另外一种比较好的方法就是搭建GITLAB服务器。

官方网站:https://about.gitlab.com/
安装文档:https://about.gitlab.com/installation/#centos-7 (针对的是企业版ee)
我们要使用的是社区版本ce,不管是哪个版本,都要求服务器内存不低于4G。

安装gitlab

  • 编辑repo文件:
[root@localhost ~]# vim /etc/yum.repos.d/gitlab.repo           //写入下面内容
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
  • 安装gitlab:
[root@localhost ~]# yum install -y gitlab-ce
[root@localhost ~]# gitlab-ctl reconfigure          //自动配置gitlab

Running handlers:
Running handlers complete
Chef Client finished, 432/614 resources updated in 05 minutes 39 seconds
gitlab Reconfigured!

上面配置过程会花费一些时间,因为gitlab会将它启动所需要的服务全部配置好后打开

[root@localhost ~]# netstat -lntp 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:9100          0.0.0.0:*               LISTEN      4376/node_exporter  
tcp        0      0 127.0.0.1:9229          0.0.0.0:*               LISTEN      5000/gitlab-workhor 
tcp        0      0 127.0.0.1:9168          0.0.0.0:*               LISTEN      5043/ruby           
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      3903/unicorn master 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4078/nginx: master  
tcp        0      0 127.0.0.1:8082          0.0.0.0:*               LISTEN      3949/sidekiq 5.1.3  
tcp        0      0 127.0.0.1:9236          0.0.0.0:*               LISTEN      5020/gitaly         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1029/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1394/master         
tcp        0      0 0.0.0.0:8060            0.0.0.0:*               LISTEN      4078/nginx: master  
tcp        0      0 127.0.0.1:9121          0.0.0.0:*               LISTEN      4503/redis_exporter 
tcp        0      0 127.0.0.1:9090          0.0.0.0:*               LISTEN      5053/prometheus     
tcp        0      0 127.0.0.1:9187          0.0.0.0:*               LISTEN      5098/postgres_expor 
tcp        0      0 127.0.0.1:9093          0.0.0.0:*               LISTEN      5069/alertmanager   
tcp6       0      0 ::1:9168                :::*                    LISTEN      5043/ruby           
tcp6       0      0 :::22                   :::*                    LISTEN      1029/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1394/master         
tcp6       0      0 :::9094                 :::*                    LISTEN      5069/alertmanager   
tcp6       0      0 :::3306                 :::*                    LISTEN      1352/mysqld   
  • 查看gitlab状态:
[root@localhost ~]# gitlab-ctl status          //查看gitlab服务状态
run: alertmanager: (pid 5069) 372s; run: log: (pid 5091) 371s
run: gitaly: (pid 5020) 374s; run: log: (pid 5023) 374s
run: gitlab-monitor: (pid 5043) 373s; run: log: (pid 5072) 371s
run: gitlab-workhorse: (pid 5000) 375s; run: log: (pid 5022) 374s
run: logrotate: (pid 4127) 538s; run: log: (pid 5011) 375s
run: nginx: (pid 4078) 544s; run: log: (pid 5010) 375s
run: node-exporter: (pid 4376) 501s; run: log: (pid 5024) 374s
run: postgres-exporter: (pid 5098) 371s; run: log: (pid 5106) 371s
run: postgresql: (pid 3594) 614s; run: log: (pid 4995) 376s
run: prometheus: (pid 5053) 372s; run: log: (pid 5059) 372s
run: redis: (pid 3465) 625s; run: log: (pid 4990) 376s
run: redis-exporter: (pid 4503) 488s; run: log: (pid 5073) 371s
run: sidekiq: (pid 3949) 556s; run: log: (pid 4994) 376s
run: unicorn: (pid 3882) 562s; run: log: (pid 4996) 376s
gitlab-ctl start        启动gitlab服务 
gitlab-ctl stop         关闭gitlab服务
gitlab-ctl restart      重启gitlab服务

安装完gitlab之后,直接在浏览器访问gitlab,输入服务器ip即可(访问之前打开80端口)

这里写图片描述

打开之后默认让你更改密码,更改完密码让你登录,默认用户名是root

这里写图片描述

登录进来后,可以新建项目、组、用户和配置gitlab

这里写图片描述

在实际使用过程中,可以配置域名和服务器代理,这样就不用直接输入IP登录了。

  • 新建组(group):

这里写图片描述

  • 新建项目(project):

这里写图片描述

提示没有任何的ssh key,之前Git有配置过ssh key,gitlab也需要配置ssh key。
这里写图片描述

[root@localhost ~]# ssh-keygen            //生成密钥
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):          //直接按Enter键
Created directory '/root/.ssh'. 
Enter passphrase (empty for no passphrase):         //直接按Enter键(要用密码可以输入密码)
Enter same passphrase again:           //直接按Enter键
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:/+ZKFg/6CnK4OgwCYy13LCfhVTKREWNUZaA46oYd/50 [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|    .XB+oo       |
|   .oo= .        |
|  oo+.           |
|oo.*.+           |
|oo+ =   S o      |
|=. o .   o +     |
|o=. + o . + .    |
|. o  = o = ..    |
|  .o. . E.o+o    |
+----[SHA256]-----+
[root@localhost ~]# cat .ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnIOQIOHD1BcfDzmG5j5F6ArLbvH9tZRQLVmKqeSHfsdkFDK8WXLqmNR6pZkqfvaILKrfAGG41JuLpSa24MzHuF3Owzh+2ZszwiaaO8KaxCIQCT+8Lbwq4wtqmGnByEmLi+SJrkj6o3ZYgHy7Y/I7LvogT7wJ+W9+iR+lL9GsTKqwIylwzfvhv9Fw19PsSAQBtWvSwuo2t+J26cr773Q/zlUhUQTA4+bDr4ABsShYZVnnMQdOkeTeisOw+Uey+G5lVnYq2lwaAlxTqWaajCHJ+7LDgU7CuzuyxgPSzRQcnR9WRThevQPxWrplcz7uMRrOG4aqSoqAyflMKdRKW4ypZ [email protected]

回到浏览器界面,右上角图标–>setting–>SSH Keys,复制粘贴公钥,新增ssh key,然后重新登录才有权限新增用户。

这里写图片描述

  • 新增用户(user):

这里写图片描述

在admin area里面新增用户。我这里稍微有点奇怪,这个图标没显示出来,是个小扳手的图标,不过不影响,鼠标点在这里会有提示,点进来就可以新增用户了。

  • 编辑用户:

这里写图片描述

直接点击Edit,编辑用户,设置密码。之后新用户使用密码登录之后第一次就会让你设置新密码,然后使用新密码在登录一次。新用户登录之后也可以创建自己的组和项目。

另外,gitlab的操作和github有些类似,具体参考这里:https://www.cnyunwei.cc/archives/1204

gitlab的备份和恢复

  • gitlab备份:
[root@localhost ~]# gitlab-rake gitlab:backup:create            //gitlab备份,会备份项目、组、用户和代码,数据量比较大的话会耗费较长时间
Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
 * lzxlinux/test ... [SKIPPED]
[SKIPPED] Wiki
 * 2/1 ... [SKIPPED]
[SKIPPED] Wiki
done
Dumping uploads ... 
done
Dumping builds ... 
done
Dumping artifacts ... 
done
Dumping pages ... 
done
Dumping lfs objects ... 
done
Dumping container registry images ... 
[DISABLED]
Creating backup archive: 1536592589_2018_09_10_11.2.3_gitlab_backup.tar ... done        //备份为该文件
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... skipping
[root@localhost ~]# ls /var/opt/gitlab/backups/           //默认备份在该目录下
1536592589_2018_09_10_11.2.3_gitlab_backup.tar           
  • gitlab的恢复:
    gitlab的恢复必须要保证gitlab的版本一致,否则会出现问题
先停两个服务,目的是让数据不在发生变更(只需要停这两个):
[root@localhost ~]# gitlab-ctl stop unicorn ; gitlab-ctl stop sidekiq        //unicorn是rubby相关的webserver,sidekiq是rubby相关的消息队列
ok: down: unicorn: 0s, normally up
ok: down: sidekiq: 0s, normally up

开始恢复:
[root@localhost ~]# gitlab-rake gitlab:backup:restore BACKUP=1536592589_2018_09_10_11.2.3          //gitlab恢复,BACKUP后面跟要恢复文件的前缀,数据量大恢复也会花费很长时间
Unpacking backup ... done
Before restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.

Do you want to continue (yes/no)? yes          //输入yes
。
。      //中间省略
。
WARNING:  no privileges were granted for "public"
GRANT
[DONE]
done
Restoring repositories ...
 * lzxlinux/test ... [DONE]
 * 2/1 ... [DONE]
done
Restoring uploads ... 
done
Restoring builds ... 
done
Restoring artifacts ... 
done
Restoring pages ... 
done
Restoring lfs objects ... 
done
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
Do you want to continue (yes/no)? yes           //输入yes

.
Deleting tmp directories ... done
done
done
done
done
done
done
done
  • 再重启gitlab:
[root@localhost ~]# gitlab-ctl restart            //重启gitlab
ok: run: alertmanager: (pid 9859) 1s
ok: run: gitaly: (pid 9873) 0s
ok: run: gitlab-monitor: (pid 9886) 0s
ok: run: gitlab-workhorse: (pid 9902) 0s
ok: run: logrotate: (pid 9915) 1s
ok: run: nginx: (pid 9921) 0s
ok: run: node-exporter: (pid 9929) 1s
ok: run: postgres-exporter: (pid 9935) 0s
ok: run: postgresql: (pid 9945) 1s
ok: run: prometheus: (pid 9953) 0s
ok: run: redis: (pid 10035) 0s
ok: run: redis-exporter: (pid 10046) 1s
ok: run: sidekiq: (pid 10053) 0s
ok: run: unicorn: (pid 10060) 0s

更多资料参考:搭建Gitlab服务器

猜你喜欢

转载自blog.csdn.net/miss1181248983/article/details/82598250
今日推荐