本文共 4301 字,大约阅读时间需要 14 分钟。
git是一个版本控制器
在分布式版本控制系统里,客户端并不只提取最新版本的文件快照,而是把代码仓库完整地镜像下来。这么一来,任何一处协同工作用的服务器发生故障,事后都可以用任何一个镜像出来的本地仓库恢复。因为每一次的提取操作,实际上都是一次对代码仓库的完整备份。
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务,操作起来特别方便。
2.1yum安装软件包
yum install curl openssh-server openssh-clients postfix cronie -y
2.2开启postfix服务
service postfix startchkconfig postfix on
2.3关闭防火墙
service iptables stopsetenforce 0
2.4上传软件包
rpm -ivh gitlab-ce-8.9.9-ce.0.el6.x86_64.rpm
2.5Gitlab命令
gitlab-ctl reconfigure #启动githubgitlab-ctl status #查看状态gitlab-ctl start #启动gitlab-ctl restart #重启gitlab-ctl stop #停止
2.6Gitlab修改密码]
gitlab-rails console production#修改普通用户#user=User.where(name: "chenhao").firstuser.password="密码"=> "密码"irb(main):004:0> user.save!=> trueirb(main):005:0> quit#修改root用户irb(main):001:0> user = User.where(id: 1).first=> #user.password="密码"=> "密码"irb(main):003:0> user.password_confirmation="密码"=> "密码"irb(main):004:0> user.save!=> trueirb(main):005:0> quit
2.8Gitlab修改成员权限
2.9Gitlab 添加ssh
ssh-keygen -t rsa -C "312779641@qq.com"cat id_rsa.pubssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAu0ysR63bNLLla2X2AvAC8egFCeGR7PgZZsYwg8a7SrZ4lTHN+AxPzTuRtvGOEPIsLpRiY2fpGe3zIc047uxMM5aqSD8+JzNhZCBtR7YJEuypbn7lSlM9dCHwpc2OtT+crp5Jz20oL+T5mWqZG17ERzDTsqCm/PLSekmIFJfKmCmY70JzRajqzAirOtSAdfQjXyVoJUJ0u4LHixQtafIoq3jNSIUWvWuYnNHo/xDfP8KVja4ihKXsjAjBDZrIPpJ7I3WjgsZvOO06Q/eDxNKKYYF1E71rN/qbe6am1HVfeFyAlVRZsd3GaUaqgLQXCn+6MyKetLSHHtOJ2+nPLhBMhQ== root@cluster4
#把上面的内容复制到web的ssh keys里面
2.10Gitlab linux clone项目
#Git global setupgit config --global user.name "chenhao"git config --global user.email "312779641@qq.com"Create a new repositorygit clone git@cluster4:chenhao/vasp.gitcd vasptouch README.mdgit add README.mdgit commit -m "add README"git push -u origin masterExisting folder or Git repositorycd existing_foldergit initgit remote add origin git@cluster4:chenhao/vasp.gitgit add .git commitgit push -u origin master
2.11Gitlab window clone项目
下载https://git-scm.com/download/win/git-bash打开git-bashkey 目录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.comThe 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 initInitialized empty Git repository in E:/ceshi/.git/$ git remote add origin git@cluster4:root/ceshi.git$ git add .$ git clone git@cluster4:root/ceshi.gitCloning 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)? yesWarning: Permanently added 'cluster4,61.147.124.76' (RSA) to the list of knownosts.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
恢复测试:
cp 1520825715_gitlab_backup.tar /var/opt/gitlab/backups/cd /var/opt/gitlab/backups/gitlab-rake gitlab:backup:restore BACKUP=1520825715
确认yes
”在恢复数据库之前,我们建议删除所有现有的数据库。“这将重建authorized_keys文件。
您将丢失存储在authorized_keys文件中的任何数据。gitlab-ctl restart #重启
完成备份数据4.1浏览器访问的时候,时不时的会报502错误,需要增加服务器虚拟内存
dd if=/dev/zero of=/var/swap bs=1024 count=2048000 2048000+0 records in2048000+0 records out2097152000 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值没有覆盖(这个问题找了好久)终于解决并记录下来。1、覆盖原来gitlab的 db_key_base 到新的gitlab db_key_base 位置在 /etc/gitlab/gitlab-secrets.json2、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页面。
转载于:https://blog.51cto.com/chenhao6/2087506