Gitlab 部署与使用

一、下载安装

1.1 、下载安装包

安装包下载地址:https://packages.gitlab.com/gitlab/gitlab-ce rpm
包国内下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/ ubuntu
国内下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/

1.1.1 Ubuntu 安装

root@ubuntu-node1:~# cd /usr/local/src/

## 下载安装包
root@ubuntu-node1:/usr/local/src# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/bionic/main/g/gitlab-ce/gitlab-ce_11.11.8-ce.0_amd64.deb

## 安装
root@ubuntu-node1:/usr/local/src#  dpkg -i gitlab-ce_11.11.8-ce.0_amd64.deb

在这里插入图片描述

1.2 、修改配置

oot@ubuntu-node1:/usr/local/src# vim /etc/gitlab/gitlab.rb
#访问url配置
external_url 'http://10.10.100.101'

#邮箱配置(可选)
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "1052513265@qq.com"
#填写自己邮箱的授权码
gitlab_rails['smtp_password'] = "xxxxxxxxx"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = :login
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = "1052513265@qq.com"

1.3、初始化服务

root@ubuntu-node1:/usr/local/src# gitlab-ctl reconfigure

在这里插入图片描述

1.4、访问验证

在这里插入图片描述

二、 Gitlab使用

2.1、常用命令

# 进入数据库控制台
root@ubuntu-node1:~# gitlab-rails dbconsole
psql (9.6.11)
Type "help" for help.

gitlabhq_production=>

#数据库命令行
root@ubuntu-node1:~# gitlab-psql
psql (9.6.11)
Type "help" for help.

gitlabhq_production=#

# gitlab-rake #数据备份恢复等数据操作 
# gitlab-ctl #客户端命令行操作行 
# gitlab-ctl stop #停止 gitlab 
# gitlab-ctl start #启动 gitlab 
# gitlab-ctl restar #重启 gitlab 
# gitlab-ctl status #查看组件运行状态
#  gitlab-ctl tail nginx #查看某个组件的日志

2.2 创建git账号

在这里插入图片描述
在这里插入图片描述
创建账号后会发送邮件到刚填写的邮箱,点击连接设置密码

2.3 创建组

使用管理员 root 创建组,一个组里面可以有多个项目分支,可以将开发添加到组里面进行设置权限,不同的组就是公司不同的开发项目或者服务模块,不同的组添加不同的开发即可实现对开发设置权限的管理。

在这里插入图片描述

在这里插入图片描述

2.4 创建项目

在这里插入图片描述
在这里插入图片描述
查看创建的项目
在这里插入图片描述

2.5 将用户添加到组

在这里插入图片描述
在这里插入图片描述

2.6 创建测试文件

在这里插入图片描述
在这里插入图片描述

2.7 git 客户端测试 clone 项目

git常用命令

git config --global user.name “name“ #设置全局用户名
git config --global user.email xxx@xx.com #设置全局邮箱
git config --global --list #列出用户全局设置
git add index.html / . #添加指定文件、目录或当前目录下所有数据到暂存区
git commit -m “11“ #提交文件到工作区
git status #查看工作区的状态
git push #提交代码到服务器
git pull #获取代码到本地
git log #查看操作日志
vim .gitignore #定义忽略文件
git reset --hard HEAD^^ #git 版本回滚, HEAD 为当前版本,加一个^为上一个,^^为上上一个
版本
git reflog # #获取每次提交的 ID,可以使用–hard 根据提交的 ID 进行版本回退
git reset --hard 5ae4b06 #回退到指定 id 的版本
git branch #查看当前所处的分支
git checkout -b develop #创建并切换到一个新分支
git checkout develop #切换分支

2.7.1 clone项目


root@ubuntu-node1:/data# git clone http://10.10.100.101/app2/web1.git
Cloning into 'web1'...
Username for 'http://10.10.100.101': cwy  #账号
Password for 'http://cwy@10.10.100.101':  #密码
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.

root@ubuntu-node1:/data# cat web1/index.html
<h1>web1  v1</h1>

2.7.2 编辑文件并测试提交

#设置全局用户名 
root@ubuntu-node1:/data# git config --global user.name "cwy"
#设置全局邮箱 
root@ubuntu-node1:/data# git config --global user.email 1052513265@qq.com

root@ubuntu-node1:/data/web1# vim index.html
<h1>web1  v1</h1>
<h1>web2  v2</h1>

#保存本地
root@ubuntu-node1:/data/web1# git add .
root@ubuntu-node1:/data/web1# git commit -m "v2"
[master 6cdc46b] v2
 1 file changed, 2 insertions(+), 1 deletion(-)
#提交git
root@ubuntu-node1:/data/web1# git push
Username for 'http://10.10.100.101': cwy
Password for 'http://cwy@10.10.100.101':
Counting objects: 3, done.
Writing objects: 100% (3/3), 255 bytes | 255.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://10.10.100.101/app2/web1.git
   02ea716..6cdc46b  master -> master

三、gitlab 数据备份恢复

3.1 备份数据

#停止 gitlab 数据服务
root@ubuntu-node1:~# gitlab-ctl stop unicorn
root@ubuntu-node1:~# gitlab-ctl stop sidekiq
#手动备份数据
root@ubuntu-node1:~# gitlab-rake gitlab:backup:create
#查看备份文件
root@ubuntu-node1:~# ls /var/opt/gitlab/backups/
1646727636_2022_03_08_11.11.8_gitlab_backup.tar
#备份完成后启动gitlib
root@ubuntu-node1:~# gitlab-ctl start

3.2 恢复数据

**删除一些数据,测试能否恢复 **

#停止服务
root@ubuntu-node1:~# gitlab-ctl stop unicorn 
root@ubuntu-node1:~# gitlab-ctl stop sidekiq

#执行恢复(文件名只需填写前面的时间戳等)
root@ubuntu-node1:~# gitlab-rake gitlab:backup:restore BACKUP=1646727636_2022_03_08_11.11.8
#恢复完成后启动服务
root@ubuntu-node1:~# gitlab-ctl start

四、 gitlab 汉化

4.1、通过指定版本的语言包汉化*

4.1.1 下载汉化包

https://gitlab.com/xhang/gitlab/-/archive/v12.3.5-zh/gitlab-v12.3.5-zh.tar.gz
https://gitlab.com/xhang/gitlab/-/archive/v11.11.5-zh/gitlab-v11.11.5-zh.tar
https://gitlab.com/xhang/gitlab/-/archive/v11.9.8-zh/gitlab-v11.9.8-zh.tar
https://gitlab.com/xhang/gitlab

#停止服务
root@ubuntu-node1:~# gitlab-ctl stop
root@ubuntu-node1:~# tar xf gitlab-v11.11.8-zh.tar.gz
#备份
root@ubuntu-node1:~# cp -rp /opt/gitlab/embedded/service/gitlab-rails /opt/gitlab-rails.bak
#替换文件 
root@ubuntu-node1:~# cp -rpf gitlab-v11.11.8-zh/* /opt/gitlab/embedded/service/gitlab-rails/

root@ubuntu-node1:~# gitlab-ctl reconfigure
root@ubuntu-node1:~# gitlab-ctl start

4.1.2 web界面修改语言

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值