美文网首页
GitLab安装及使用

GitLab安装及使用

作者: 想成为大师的学徒小纪 | 来源:发表于2020-09-05 15:49 被阅读0次

一、GitLab安装

==安装GitLab的主机,建议内存至少2个G==

1、安装软件及依赖

yum install -y curl policycoreutils-python openssh-server
yum install postfix
systemctl start postfix
systemctl enable postfix
cd /opt
rpm -ivh gitlab-ce-12.0.3-ce.0.el7.x86_64.rpm

2、修改配置文件

vim /etc/gitlab/gitlab.rb
external_url 'http://10.0.0.200'            #gitlab主机IP地址或域名
gitlab-ctl reconfigure

3、启动服务

gitlab-ctl start

二、GitLab使用

1、进入网页进行基础设置

2、创建用户组

3、创建项目设置归属组

4、创建用户添加到组

5、取消用户创建用户功能

三、用户拉取上传代码测试

1、添加用户SSH公钥

在gitlab主机上创建密钥对,复制公钥信息

ssh-keygen -t dsa
cat /root/.ssh/id_dsa.pub

使用创建的用户登录

2、克隆仓库到本地

gitlab主机使用克隆命令克隆仓库

[root@gitlab ~ 17:00:52]# git clone git@10.0.0.200:dev/gitlab_test.git
正克隆到 'gitlab_test'...
The authenticity of host '10.0.0.200 (10.0.0.200)' can't be established.
ECDSA key fingerprint is SHA256:E9nSorXO6eYUohzvtsDF4DtmaZSR51Ts7R/Xa0DLjx4.
ECDSA key fingerprint is MD5:2a:dd:3d:a0:02:eb:7c:4f:32:02:fd:f6:59:f2:45:25.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.200' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
接收对象中: 100% (3/3), done.
[root@gitlab ~ 17:14:39]# ll
总用量 4
-rw-------. 1 root root 1534 4月  21 19:48 anaconda-ks.cfg
drwxr-xr-x  3 root root   35 9月   3 17:14 gitlab_test

3、创建新分支添加新代码

cd gitlab_test/
git checkout -b dev
echo "good good study" >test.txt
git add .
git commit -m "add newfile test.txt"
git push origin dev

4、进入网页发送合并分支请求

5、登录管理员用户同意请求

6、查看是否合并成功

四、GitLab备份与恢复

1、备份

(1)、修改配置文件

vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/backup_gitlab"      #指定备份目录路径   

(2)、重新加载配置

gitlab-ctl reconfigure

(3)、创建备份目录进行备份

mkdir /backup_gitlab
[root@gitlab gitlab_test 18:11:04]# gitlab-rake gitlab:backup:create
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data 
    #gitlab.rb和gitlab-secrets.json文件需要手动备份
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
Backup task is done.

cp /etc/gitlab/gitlab.rb /backup_gitlab
cp /etc/gitlab/gitlab-secrets.json /backup_gitlab

(4)、查看是否备份成功

[root@gitlab gitlab_test 18:27:36]# ll /backup_gitlab/
总用量 260
-rw------- 1 git  git  153600 9月   3 18:12 1599127956_2020_09_03_12.0.3_gitlab_backup.tar
-rw------- 1 root root  91593 9月   3 18:27 gitlab.rb
-rw------- 1 root root  15553 9月   3 18:27 gitlab-secrets.json

2、恢复

(1)、停止服务

gitlab-ctl stop

(2)、将两个文件恢复

cp /backup_gitlab/gitlab* /etc/gitlab

(3)、执行恢复命令

gitlab-rake gitlab:backup:restore BACKUP=1599127956_2020_09_03_12.0.3_gitlab_backup.tar

(4)、重新加载配置

gitlab-ctl reconfigure

(5)、开启服务

gitlab-ctl start

相关文章

网友评论

      本文标题:GitLab安装及使用

      本文链接:https://www.haomeiwen.com/subject/ltkfektx.html