版本控制系统/版本控制器 —— 部署gitlab服务

一、部署gitlab服务

1、准备环境:

(1)关闭防火墙和selinux

(2)准备 gitlab 的 yum源   或者  本地上传 gitlab 的 .rpm包

(3)安装 gitlab 

rpm -ivh gitlab-ce-12.6.3-ce.0.el7.x86_64.rpm 

(4)安装 依赖包

yum install -y    postfix    curl     policycoreutils-python     openssh-server

(5)确保 ssh 是开启的

systemctl enable sshd
systemctl start sshd

2、配置gitlab登录链接

(1)配置 gitlab 登录 —— vim /etc/gitlab/gitlab.rb

[root@git-server ~]# vim /etc/gitlab/gitlab.rb
1. 添加对外的域名(gitlab.papamk.com请添加A记录指向本服务器的公网IP):将原来的修改为
external_url 'http://192.168.85.123'
2. 设置地区
gitlab_rails['time_zone'] = 'Asia/Shanghai'

3.将数据路径的注释去掉,可以更改

4.开启ssh服务

5.初始化Gitlab

gitlab-ctl reconfigure   #重新加载,需要等很长时间

6.启动Gitlab服务

gitlab-ctl start  #启动

拓 —— Gitlab 设置 HTTPS 方式

如果想要以上的 https 方式正常生效使用,则需要把 letsencrypt 自动生成证书的配置打开,这样在执行重
新让配置生效命令 (gitlab-ctl reconfigure) 的时候会自动给域名生成免费的证书并自动在 gitlab 自带的
 nginx 中加上相关的跳转配置,都是全自动的,非常方便。
letsencrypt['enable'] = true 
letsencrypt['contact_emails'] = ['caryyu@qq.com']     # 这应该是一组要添加为联系人的电子邮件地址

3、测试访问:http://192.168.85.123

(1)用户为:root

(2)密码:本人设置的密码是12345678

(3)创建项目,为项目起名字

用 SSH 克隆。需要创建秘钥,并将公钥内容添加到 SSH 秘钥里。

[root@client ~]# ssh-keygen
[root@client ~]# cd .ssh/
[root@client .ssh]# ls 
[root@client .ssh]# cat id_rsa.pub 
      公钥内容

(4)创建文件

(5)上传项目

4、在git客户端

(1)用 SSH 克隆。

[root@client ~]# git clone git@192.168.246.214:root/testapp.git
[root@client ~]# ls
testapp
[root@client ~]# cd testapp/
[root@client testapp]# ls
test.txt  同步时间.txt

(2)使用 http 克隆。

[root@client ~]# rm -rf testgit/
[root@client ~]# git clone http://192.168.85.123/root/testapp.git
Cloning into 'testapp'...
Username for 'http://192.168.246.214': root
Password for 'http://root@192.168.246.214':12345678  #为自己设置的密码
[root@client ~]# ls
testapp

(3)提交到远程 gitlab 仓库

[root@client testapp]# vim update.txt
1000phone
[root@client testapp]# git add .
[root@client testapp]# git commit -m "update_version1"
[root@nginx-server testapp2]# git push origin master
Username for 'http://192.168.62.166': root
Password for 'http://root@192.168.62.166': 密码

拓 —— 

1.cat /proc/swaps 查看swap分区是否启动(无)
2.创建 :
dd  if=/dev/zero   of=/data/swap   bs=1024M   count=4
创建swap大小为bs*count=4294971392(4G);
/data/swap目录若无则找/mnt/swap
3.通过mkswap命令将上述空间制作成swap分区:
mkswap /data/swap
4.查看内核参数vm.swappiness中的数值是否为0,如果为0则根据实际需要调整成60:
查看: cat /proc/sys/vm/swappiness
设置: sysctl -w vm.swappiness=60
若想永久修改,则编辑/etc/sysctl.conf文件,改文件中有vm.swappiness变量配置,默认为0
5.启用分区:
swapon   /data/swap
echo “/data/swap swap swap defaults 0 0” >> /etc/fstab
6.再次使用cat /proc/swaps 查看swap分区是否启动

二、Gitlab 备份与恢复

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

[root@git-server ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core)
​
[root@git-server ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
8.15.4

2、数据备份

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

[root@git-server backups]# vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"    #备份的路径
gitlab_rails['backup_archive_permissions'] = 0644        #备份文件的默认权限
gitlab_rails['backup_keep_time'] = 604800                #保留时长,秒为单位

(2)使服务生效

[root@git-server backups]# gitlab-ctl reconfigure
或者
[root@git-server backups]# gitlab-ctl  restart

(3)执行备份命令进行备份

[root@git-server backups]# /opt/gitlab/bin/gitlab-rake gitlab:backup:create 

 

 

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

[root@git-server ~]# ll /var/opt/gitlab/backups/

 

3、数据恢复

特别注意:

  • 备份目录和gitlab.rb中定义的备份目录必须一致

  • GitLab的版本和备份文件中的版本必须一致,否则还原时会报错。

(1)在恢复之前,可以删除一个文件,以便查看效果

(2)执行恢复操作

[root@git-server  backups]# gitlab-rake gitlab:backup:restore BACKUP=1588700546_2020_05_06_12.6.3
注意恢复文件的名称

(3)恢复完成后,启动刚刚的两个服务,或者重启所有服务,使服务生效

[root@git-server backups]# gitlab-ctl reconfigure
或者
[root@git-server backups]# gitlab-ctl  restart

再打开浏览器进行访问,发现数据和之前的一致

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

查看 gitlab 端,可以看到数据恢复成功。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值