#下载gitlab
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-10.1.3-ce.0.el6.x86_64.rpm
sudo yum install -y curl policycoreutils-python openssh-server cronie
sudo lokkit -s http -s ssh
sudo yum install postfix
sudo service postfix start
sudo chkconfig postfix on
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
yum install gitlab-ce-10.1.3-ce.0.el6.x86_64.rpm
#修改配置,添加下面内容
vi /etc/gitlab/gitlab.rb
#域名修改
external_url 'http://newcode.topv.com'
#时区修改
gitlab_rails['time_zone'] = 'Asia/Shanghai'
#修改ssh默认端口
gitlab_rails['gitlab_shell_ssh_port'] = 22222
#存储路径修改
git_data_dir "/data/gitlab"
#备份路径设置
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/gitlab/backups"
#备份周期设置604800=7天
gitlab_rails['backup_keep_time'] = 604800
#修改访问端口
nginx['listen_port'] = 9394
#添加白名单
gitlab_rails['rack_attack_git_basic_auth'] = {
'enabled' => true,
'ip_whitelist' => ["127.0.0.1","Gitlab部署的IP地址"],
}
#配置启动
gitlab-ctl reconfigure
gitlab-ctl status
#会生成/data/gitlab/repositories/目录
##############################################################################
#汉化
yum install git
wget https://gitlab.com/xhang/gitlab/repository/10-1-stable/archive.zip
wget https://gitlab.com/xhang/gitlab/repository/10-1-stable-zh/archive.zip
#创建汉化git目录
mkdir gitlab-zh
cd gitlab-zh
git init
#解压第一个git包并创建分支
unzip ../gitlab-10-1-stable-e6142bc7e82cc2c6c25583f8c05cd36905ded87c.zip
mv gitlab-10-1-stable-e6142bc7e82cc2c6c25583f8c05cd36905ded87c/* .
rm -rf gitlab-10-1-stable-e6142bc7e82cc2c6c25583f8c05cd36905ded87c
git add *
git commit -m "++"
git branch gitlab-10-1-stable
#解压第二个git包并创建分支
unzip ../gitlab-10-1-stable-zh-1219a5ae0f40121fe7243d5e74a87bd17e1adc76.zip
cp -rp gitlab-10-1-stable-zh-1219a5ae0f40121fe7243d5e74a87bd17e1adc76/* .
rm -rf gitlab-10-1-stable-zh-1219a5ae0f40121fe7243d5e74a87bd17e1adc76
git add *
git commit -m "++"
git branch gitlab-10-1-zh-stable
#生成补丁包
git diff gitlab-10-1-stable gitlab-10-1-zh-stable > ../10-1-stable-zh.diff
#开始汉化
patch -d /opt/gitlab/embedded/service/gitlab-rails -pl < ../10-1-stable-zh.diff
#配置汉化并重启
gitlab-ctl reconfigure
gitlab-ctl restart
##############################################################################
#迁移gitlab
#复制其他服务器上的repositories目录下所有文件到/data/gitlab/repositories/
#修改权限
chown -R git:root /data/gitlab/repositories/*
#导入
cd /var/opt/gitlab
gitlab-rake gitlab:import:repos
#导入项目后,gitlab重启访问会出现502,需要执行gitlab-rake gitlab:import:repos
##############################################################################
#任务计划备份
#备份配置文件
sh -c 'umask 0077; tar -cf $(date "+etc-gitlab-%s.tar") -C /etc/gitlab'
#备份数据文件
sudo gitlab-rake gitlab:backup:create
#加入到任务计划CRON=1没有日志,改为>/tmp/gitlab_backup.log保存日志
0 2 * * 0 git /opt/gitlab/bin/gitlab-rake gitlab:backup:create > /data/gitlab/backups/rake.log
0 2 * * 0 git cd /data/gitlab/backups;tar -cf $(date "+etc-gitlab-%s.tar") -C /etc/gitlab
##############################################################################
#恢复
sudo mv /etc/gitlab /etc/gitlab.$(date +%s)
# 将下面配置备份文件的时间戳改为你所备份的文件的时间戳
sudo tar -xf etc-gitlab-1399948539.tar -C /
# 将数据备份文件拷贝至备份目录
sudo cp 1393513186_gitlab_backup.tar /data/gitlab/backups
# 停止连接数据库的进程
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
# 恢复1393513186这个备份文件,将覆盖GitLab数据库!
sudo gitlab-rake gitlab:backup:restore BACKUP=1393513186
# 启动 GitLab
sudo gitlab-ctl start
# 检查 GitLab
sudo gitlab-rake gitlab:check SANITIZE=true
##############################################################################
#故障排查
#502
#重启服务后502
#执行
gitlab-rake gitlab:import:repos
#访问页面过程中502,执行下面查看log
gitlab-ctl tail
#修复丢失文件
#https://www.ipreferjim.com/2012/02/git-push-fatal-unable-to-read-sha1/
#https://lists.nongnu.org/archive/html/dolibarr-dev/2012-10/txtyMlY1ONYxU.txt
#备份过程中出现error: Could not read,上传文件
#进入该git的目录执行
git fsck --full
git ls-tree cd5aa220b358f2839f083b0fea5684483875aff2
#所有版本
git rev-list HEAD
#查看日志历史
git log --raw --all --full-history
#查看文件内容
git cat-file -p 196035e8754a0c3d3966f0bc9619f66f5c1b94ba
#上传丢失的文件,sha-1码要一致
git hash-object -w 196035e8754a0c3d3966f0bc9619f66f5c1b94ba
#有些损坏的并且无法找回的可以删除掉