gitlab的安装和使用

目录

安装配置gitlab

使用浏览器访问

更改字体

修改密码

创建群组

创建用户

创建项目

创建工作目录

分发用户密钥

配置git拉取代码

创建文件

修改文件,再次提交

创建合并请求

Gitlab备份与恢复

1、查看系统版本和软件版本

2、数据备份

3、测试数据恢复

(1) 安装部署 gitlab server

(2) 恢复 gitlab

4、邮箱配置


机器配置

192.168.43.129

git

4核8G

安装配置gitlab

安装

#首先关闭防火墙和selinux
systemctl stop firewalld && setenforce 0
# 安装依赖,并启动ssh、防火墙开启相应端口、postfix
[root@git ~]# yum install -y curl policycoreutils-python openssh-server perl

# 安装完成后会直接启动
[root@git ~]# yum -y install gitlab-jh-16.5.2-jh.0.el7.x86_64.rpm

安装有点慢需要耐心等待一会

装好之后是长这样的,会出现一个极狐的标

接下来就可以进行初始化了,有两种方法可以配置访问地址,第一种的话需要在yum安装前进行配置

[root@git ~]# export EXTERNAL_URL='http://192.168.43.129'
或
[root@git ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://192.168.43.129'
[root@git ~]# gitlab-ctl reconfigure

我用的是第二种方法,进去/etc/gitlab/gitlab.rb文件里面找到

external_url 'http://192.168.43.129'

这一行进行修改

修改完成后执行gitlab-ctl reconfigure

出现下图即为完成

查看一下状态

[root@git ~]#  gitlab-ctl status
run: gitaly: (pid 4491) 48s; run: log: (pid 4087) 279s
run: gitlab-monitor: (pid 4539) 44s; run: log: (pid 4251) 207s
run: gitlab-workhorse: (pid 4501) 47s; run: log: (pid 4099) 273s
run: logrotate: (pid 4125) 265s; run: log: (pid 4124) 265s
run: nginx: (pid 4112) 271s; run: log: (pid 4111) 271s
run: node-exporter: (pid 4175) 243s; run: log: (pid 4174) 243s
run: postgres-exporter: (pid 4528) 45s; run: log: (pid 4223) 219s
run: postgresql: (pid 3933) 343s; run: log: (pid 3932) 343s
run: prometheus: (pid 4514) 46s; run: log: (pid 4156) 259s
run: redis: (pid 3876) 355s; run: log: (pid 3875) 355s
run: redis-exporter: (pid 4186) 237s; run: log: (pid 4185) 237s
run: sidekiq: (pid 4078) 281s; run: log: (pid 4077) 281s
run: unicorn: (pid 4047) 287s; run: log: (pid 4046) 287s

[root@git ~]# gitlab-ctl status | wc -l
15

检查端口

[root@git ~]# netstat -lntup|grep 80
tcp        0      0 127.0.0.1:8080      0.0.0.0:*    LISTEN     4073/unicorn master 
tcp        0      0 0.0.0.0:80      0.0.0.0:*         LISTEN      4112/nginx: master  
tcp        0      0 0.0.0.0:8060       0.0.0.0:*      LISTEN      4112/nginx: master  

使用浏览器访问

登录gitlab

登录密码存放在 /etc/gitlab/initial_root_password 文件中,该文件会在24小时后删除

[root@git ~]# cat /etc/gitlab/initial_root_password 
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: Rok614QMSkXVv95uYJVUjkcdU+f48DA+ADWZk970gCc=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

用户名:root

密码: Rok614QMSkXVv95uYJVUjkcdU+f48DA+ADWZk970gCc=

更改字体

登录后首先进行语言的切换,纯英文的网页对我来说有点不太友好,所以先改一下语言,修改为中文

往下滑,找到语言,选择简体中文

保存更改,然后刷新一下,字体就切换过来了

修改密码

那个一长串的密码很不好记,存放密码的文件24小时候也会自动删除

所以我们来更改一下我们root用户的密码,

进来后我们发现主页上提示的注册限制

点击 停用 ,在跳转的页面下找到注册限制,关闭这两个选项,然后保存

创建群组

回到首页,选择创建群组

创建用户

同样的方法,再创建天天 、毛毛、阿奇 用户。注意访问级别为 普通

用户添加完毕后,gitlab会给用户发一封修改密码的邮件,各用户需要登录自己的邮箱,并点击相关的链接,设置新密码。或者使用初始密码登录然后进去修改密码

我这里创建了4个用户,一个管理员用户 莱德 ,三个普通用户

用户创建完之后将给用户设置初始密码,统一为Leyi1234

把用户添加到组里,指定 莱德 为本组的owner

回到首页后点击群组-刚才设置的群组-邀请您的同事

同样的方法将用户天天、毛毛和阿奇也添加到组中,并指定他们为Developer和maintainer:

创建项目

使用 莱德 用户的身份与密码登录到 gitlab 界面中,并创建项目 project ,如下所示:

指定项目的存储路径和项目名称,如下所示

创建工作目录

为前后端创建工作目录

分发用户密钥

在客户端上添加用户

先创建用户
[root@git ~]# useradd laide
[root@git ~]# useradd tiantian
[root@git ~]# useradd maomao
[root@git ~]# useradd aqi

分发密钥
[root@git ~]# su - maomao
[maomao@git root]$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/maomao/.ssh/id_rsa): 
Created directory '/home/maomao/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/maomao/.ssh/id_rsa.
Your public key has been saved in /home/maomao/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:rCWnTmjEOG9ciLuNaCv4frNIFbAuSEL5sg1/8UfcGDE maomao@git
The key's randomart image is:
+---[RSA 2048]----+
| .o      E.      |
|.. o     ..      |
|..o .   . +      |
|++ = + . + .     |
|o @ = = S        |
| o X + B .       |
|. o B + .        |
|o+ Boo           |
|++B.oo.          |
+----[SHA256]-----+

[maomao@git ~]$ cat /home/maomao/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJEYwamzVnt3j5XDerlJNYh4yyjl7psv0qWY7V/HePoxRlyROM/F/cvQhnVvuUMZBqTs362V+gIj1U77AlHSTPc4HYjN5xqHjgkj0Amb2KKhZJsAMLua0etrF+be3IB64aU/mELkzJY0OOSPTIwb2XP8Nb9uceDyIXaidZ/qC0+p4Sq4dtuu/kIAJjtUXE+gVmAu63Hi38e/54GT5WduEwfmau0Ul3PReHrrh24CbXaw+onwymI4c3/mGmR0elhVfSURL6/5RA+ptQvM/kq8D27CRoDs2Ic8qdBu2dvlF9rIAu7vOkg1GSjXA8qNKQIahaErsYUZojn+RE+1+36O3Z maomao@git

将毛毛的公钥复制到gitlab中: 使用毛毛用户的身份与密码登录到gitlab界面中,然后在ssh-key中添加 相关的key ,如下所示

配置git拉取代码

为 毛毛 用户配置git拉取代码 ,如下所示:

[maomao@git ~]$ git clone git@192.168.43.129:dog_wangwang/project.git
正克隆到 'project'...
The authenticity of host '192.168.43.129 (192.168.43.129)' can't be established.
ECDSA key fingerprint is SHA256:f/Gl1mimBhfo1yyk23NyyyuFC7iJuIOmTVjMnn3MzDY.
ECDSA key fingerprint is MD5:6f:e7:05:af:28:24:d8:81:1c:10:0a:b6:f8:83:33:c9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.43.129' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 14 (delta 2), reused 0 (delta 0), pack-reused 0
接收对象中: 100% (14/14), done.
处理 delta 中: 100% (2/2), done.

创建文件

创建文件,并提交到mao分支

#创建文件
[maomao@git bg]$ touch mao
[maomao@git bg]$ echo "maomao" >> mao 
[maomao@git bg]$ ll
总用量 4
-rw-rw-r--. 1 maomao maomao 7 11月 21 20:25 mao
[maomao@git bg]$ git branch mao
[maomao@git bg]$ git status
# 位于分支 main
# 未跟踪的文件:
#   (使用 "git add <file>..." 以包含要提交的内容)
#
#       mao
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)

[maomao@git bg]$ git checkout mao
切换到分支 'mao'
[maomao@git bg]$ git status
# 位于分支 mao
# 未跟踪的文件:
#   (使用 "git add <file>..." 以包含要提交的内容)
#
#       mao
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
[maomao@git bg]$ git add .
[maomao@git bg]$ git config --global user.email "maomao@qq.com"
[maomao@git bg]$ git config --global user.name "maomao"
[maomao@git bg]$ git commit -m "maocommit"
[mao 90b57bf] maocommit
 1 file changed, 1 insertion(+)
 create mode 100644 bg/mao
[maomao@git bg]$ git push origin mao
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 365 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
remote: 
remote: To create a merge request for mao, visit:
remote:   http://192.168.43.129/dog_wangwang/project/-/merge_requests/new?merge_request%5Bsource_branch%5D=mao
remote: 
To git@192.168.43.129:dog_wangwang/project.git
   6a52953..90b57bf  mao -> mao
修改文件,再次提交
[maomao@git bg]$ echo "second commit" >> mao 
[maomao@git bg]$ ll
总用量 4
-rw-rw-r--. 1 maomao maomao 21 11月 21 20:41 mao
[maomao@git bg]$ git status
# 位于分支 mao
# 尚未暂存以备提交的变更:
#   (使用 "git add <file>..." 更新要提交的内容)
#   (使用 "git checkout -- <file>..." 丢弃工作区的改动)
#
#       修改:      mao
#
修改尚未加入提交(使用 "git add" 和/或 "git commit -a")
[maomao@git bg]$ git add .
[maomao@git bg]$ git commit -m "second mao"
[mao c9ad206] second mao
 1 file changed, 1 insertion(+)
maomao@git bg]$ git push origin mao
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 383 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
remote: 
remote: To create a merge request for mao, visit:
remote:   http://192.168.43.129/dog_wangwang/project/-/merge_requests/new?merge_request%5Bsource_branch%5D=mao
remote: 
To git@192.168.43.129:dog_wangwang/project.git
   90b57bf..c9ad206  mao -> mao
创建合并请求

合并请求创建后,两位审核人员均登录进行审批

合并成功后去查看一下

Gitlab备份与恢复

1、查看系统版本和软件版本

[root@git ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@git ~]#  cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
16.5.2-jh

2、数据备份

打开/etc/gitlab/gitlab.rb配置文件,查看一个和备份相关的配置项:

gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

该项定义了默认备份出文件的路径,可以通过修改该配置,并执行 gitlab-ctl reconfigure 或者 gitlab-ctl restart 重启服务生效。

执行备份命令进行备份

[root@git ~]# /opt/gitlab/bin/gitlab-rake gitlab:backup:create 
2023-11-21 12:57:38 UTC -- Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2023-11-21 12:57:44 UTC -- Dumping database ... done
2023-11-21 12:57:44 UTC -- Dumping repositories ... 
...
2023-11-21 12:57:45 UTC -- Backup 1700571458_2023_11_21_16.5.2-jh is done.
2023-11-21 12:57:45 UTC -- Deleting backup and restore PID file ... done

也可以添加到 crontab 中定时执行:

0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

可以到/var/opt/gitlab/backups找到备份包,解压查看,会发现备份的还是比较全面的,数据库、repositories、build、upload等分类还是比较清晰的。

设置备份保留时常,防止每天执行备份,肯定有目录被爆满的风险,打开/etc/gitlab/gitlab.rb配置文件,找到如下配置:

gitlab_rails['backup_keep_time'] = 604800

设置备份保留7天(7360024=604800),秒为单位,如果想增大或减小,可以直接在该处配置,并通过gitlab-ctl restart 重启服务生效。

备份完成,会在备份目录中生成一个当天日期的tar包。

3、测试数据恢复

(1) 安装部署 gitlab server

具体步骤参见gitlab server 搭建过程

(2) 恢复 gitlab

打开/etc/gitlab/gitlab.rb配置文件,查看一个和备份相关的配置项:

gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

修改该配置,定义了默认备份出文件的路径,并执行 gitlab-ctl reconfigure 或者 gitlab-ctl restart 重启服务生效。

恢复前需要先停掉数据连接服务:

[root@git ~]# gitlab-ctl stop unicorn
[root@git ~]# gitlab-ctl stop sidekiq

如果是台新搭建的主机,不需要操作,理论上不停这两个服务也可以。停这两个服务是为了保证数据一致性。将老服务器/var/opt/gitlab/backups目录下的备份文件拷贝到新服务器上的/var/opt/gitlab/backups

注意权限:600权限是无权恢复的。 实验环境可改成了777,生产环境建议修改属主属组

[root@git backups]# pwd
/var/opt/gitlab/backups
[root@git backups]# chmod 777 1530773117_2019_03_05_gitlab_backup.tar 
[root@git backups]# ll
total 17328900
-rwxrwxrwx 1 git git 17744793600 Jul  5 14:47 1530773117_2018_07_05_gitlab_backup.tar

执行下面的命令进行恢复(在备份文件存放路径下进行恢复):后面再输入两次yes就完成恢复了。

[root@git backups]# gitlab-rake gitlab:backup:restore BACKUP=1700571458_2023_11_21_16.5.2-jh

恢复完成后,启动刚刚的两个服务,或者重启所有服务,再打开浏览器进行访问,发现数据和之前的一致:

[root@git backups]# gitlab-ctl start unicorn
[root@git backups]# gitlab-ctl start sidekiq
或
[root@git backups]# gitlab-ctl restart

注意:通过备份文件恢复gitlab必须保证两台主机的gitlab版本一致,否则会提示版本不匹配

4、 邮箱配置

[root@gitlab ]# vim /etc/gitlab/gitlab.rb
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "newrain_wang@163.com"
gitlab_rails['smtp_password'] = "UWYNCPQOBQFCDLIW"
gitlab_rails['smtp_domain'] = "smtp.163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_pool'] = false
gitlab_rails['gitlab_email_from'] = 'newrain_wang@163.com'

[root@gitlab ]# gitlab-ctl reconfigure
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你好!关于GitLab安装使用,我可以为你提供一些基本的指导。以下是一般的安装步骤: 1. 首先,你需要一个服务器来安装GitLab。可以选择自己的物理服务器或者虚拟私有服务器(VPS)。确保服务器满足GitLab的最低系统要求,如Linux操作系统、内存和存储空间等。 2. 安装所需的依赖项。GitLab依赖于一些软件包和库,如Ruby、PostgreSQL、Redis等。确保这些依赖项已经安装在你的服务器上。 3. 下载和安装GitLab。你可以从GitLab官方网站下载最新版本的安装包,然后按照官方文档提供的指南进行安装。 4. 配置和启动GitLab安装完成后,你需要进行一些配置,如设置管理员账户、域名、端口等。然后,通过命令启动GitLab服务。 安装完成后,你就可以开始使用GitLab了。以下是一些常见的使用方法: 1. 创建项目:登录到GitLab管理界面后,你可以创建新项目。选择“New project”并填写相关信息,如项目名称、描述等。 2. 添加成员:在项目中添加成员可以让其他人参与项目的开发。选择“Settings”->“Members”,然后输入成员的用户名或邮箱来邀请他们加入项目。 3. 管理代码:通过GitLab提供的Web界面,你可以管理代码仓库、分支、合并请求等。你可以上传代码、创建分支、合并代码等操作。 4. 使用CI/CD:GitLab集成了持续集成和交付(CI/CD)功能,可以自动化构建、测试和部署你的应用程序。你可以配置CI/CD管道,并触发自动化流程。 这只是GitLab的一些基本操作,还有很多功能和高级用法可以探索。希望这些信息对你有帮助!如果你有任何其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值