git是一个版本控制器
在分布式版本控制系统里,客户端并不仅提取最新版本的文件快照,而是把代码仓库完整地镜像下来。linux
这么一来,任何一处协同工做用的服务器发生故障,过后均可以用任何一个镜像出来的本地仓库恢复。由于每一次的提取操做,实际上都是一次对代码仓库的完整备份。git
GitLab 是一个用于仓库管理系统的开源项目,使用Git做为代码管理工具,并在此基础上搭建起来的web服务,操做起来特别方便。github
2.1yum安装软件包yum install curl openssh-server openssh-clients postfix cronie -y
web
2.2开启postfix服务数据库
service postfix start chkconfig postfix on
2.3关闭防火墙json
service iptables stop setenforce 0
2.4上传软件包rpm -ivh gitlab-ce-8.9.9-ce.0.el6.x86_64.rpm
vim
2.5Gitlab命令浏览器
gitlab-ctl reconfigure #启动github gitlab-ctl status #查看状态 gitlab-ctl start #启动 gitlab-ctl restart #重启 gitlab-ctl stop #中止
2.6Gitlab修改密码]bash
gitlab-rails console production #修改普通用户 #user=User.where(name: "chenhao").first user.password="密码" => "密码" irb(main):004:0> user.save! => true irb(main):005:0> quit #修改root用户 irb(main):001:0> user = User.where(id: 1).first => #<User id: 1, email: "admin@example.com"。。。。。 irb(main):002:0> user.password="密码" => "密码" irb(main):003:0> user.password_confirmation="密码" => "密码" irb(main):004:0> user.save! => true irb(main):005:0> quit
2.8Gitlab修改为员权限服务器
2.9Gitlab 添加ssh
ssh-keygen -t rsa -C "312779641@qq.com" cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAu0ysR63bNLLla2X2AvAC8egFCeGR7PgZZsYwg8a7SrZ4lTHN+AxPzTuRtvGOEPIsLpRiY2fpGe3zIc047uxMM5aqSD8+JzNhZCBtR7YJEuypbn7lSlM9dCHwpc2OtT+crp5Jz20oL+T5mWqZG17ERzDTsqCm/PLSekmIFJfKmCmY70JzRajqzAirOtSAdfQjXyVoJUJ0u4LHixQtafIoq3jNSIUWvWuYnNHo/xDfP8KVja4ihKXsjAjBDZrIPpJ7I3WjgsZvOO06Q/eDxNKKYYF1E71rN/qbe6am1HVfeFyAlVRZsd3GaUaqgLQXCn+6MyKetLSHHtOJ2+nPLhBMhQ== root@cluster4
#把上面的内容复制到web的ssh keys里面
2.10Gitlab linux clone项目
#Git global setup git config --global user.name "chenhao" git config --global user.email "312779641@qq.com" Create a new repository git clone git@cluster4:chenhao/vasp.git cd vasp touch README.md git add README.md git commit -m "add README" git push -u origin master Existing folder or Git repository cd existing_folder git init git remote add origin git@cluster4:chenhao/vasp.git git add . git commit git push -u origin master
已经同步
2.11Gitlab window clone项目
把下面的keys内容复制到web的ssh keys里面
下载https://git-scm.com/download/win/git-bash 打开git-bash key 目录C:\Users\Administrator\.ssh\id_rsa.pub $ cd E: $ ssh-keygen -t rsa -C "admin@example.com" The key fingerprint is: SHA256:sQ+BeFwWzi5EuwzmPHM6e2sw5YDMNeMRY0blCDuGseA admin@example.com The key's randomart image is: +---[RSA 2048]----+ |o ..*oo +. | |o+ ==B B | |oE++=+B = | | .+=o=.o + | | =+= S | | o=.. o | | oo . | | oo | | .o.. | +----[SHA256]-----+ Administrator@hh-PC MINGW64 /e/ceshi $ git init Initialized empty Git repository in E:/ceshi/.git/ $ git remote add origin git@cluster4:root/ceshi.git $ git add . $ git clone git@cluster4:root/ceshi.git Cloning into 'ceshi' The authenticity of host 'cluster4 (61.147.124.76)' can't be established. RSA key fingerprint is SHA256:AHmI2s+c2ShCK6dG4oTGoiBlY/qmCLlwzgtR01CDVm0. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'cluster4,61.147.124.76' (RSA) to the list of known osts. remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. Administrator@hh-PC MINGW64 /e/ceshi (master)
备份:# gitlab-rake gitlab:backup:create
/var/opt/gitlab/backups/1520825715_gitlab_backup.tar
恢复测试:
cp 1520825715_gitlab_backup.tar /var/opt/gitlab/backups/ cd /var/opt/gitlab/backups/ gitlab-rake gitlab:backup:restore BACKUP=1520825715
确认yes
”在恢复数据库以前,咱们建议删除全部现有的数据库。“
98/5000
这将重建authorized_keys文件。
您将丢失存储在authorized_keys文件中的任何数据。
gitlab-ctl restart #重启
完成备份数据
4.1浏览器访问的时候,时不时的会报502错误,须要增长服务器虚拟内存
dd if=/dev/zero of=/var/swap bs=1024 count=2048000 2048000+0 records in 2048000+0 records out 2097152000 bytes (2.1 GB) copied, 37.1219 s, 56.5 MB/s #增长2G左右SWAP mkswap /var/swap #设置交换文件 swapon /var/swap #激活启用交换分区 vim /etc/fstab #在最后一行添加 /var/swap swap swap defaults 0 0
4.2备份还原数据后浏览器访问的时候,时不时的会报500错误。
那是由于key值没有覆盖(这个问题找了很久)终于解决
并记录下来。
一、覆盖原来gitlab的 db_key_base 到新的gitlab db_key_base 位置在 /etc/gitlab/gitlab-secrets.json 二、 EE版本执行 sudo gitlab-rails runner "Project.where(mirror: false).where.not(import_url: nil).each { |p| p.import_data.destroy if p.import_data }" CE版本执行 sudo gitlab-rails runner "Project.where.not(import_url: nil).each { |p| p.import_data.destroy if p.import_data }"
由于我是CE版本执行成功,后重启服务,能够正常访问web页面。