赞
踩
清华镜像源官方使用文档:gitlab-ce | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
vi /etc/yum.repos.d/gitlab-ce.repo
- [gitlab-ce]
- name=Gitlab CE Repository
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
- gpgcheck=0
- enabled=1
本文为ContOS7.5系统。默认安装位置为:/var/opt/gitlab
- sudo yum makecache
- sudo yum install gitlab-ce
下载后出现如下图
vi /etc/gitlab/gitlab.rb
error:badgateway: failed to receive response: dial unix /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket
sudo gitlab-ctl reconfigure
sudo gitlab-ctl start
cd /opt/gitlab/bin/
sudo gitlab-rails console -e production
- user=User.where(username: 'root').first
- user=User.where(id:1).first
user.password='你的密码'
再次确认密码
user.password_confirmation="你的密码"
user.save!
1.为了能够备份和恢复,请确保你的系统上安装了Rsync
sudo yum install rsync
2.配置了与备份目标机器之间的免密认证,修改gitlab配置文件
vim /etc/gitlab/gitlab.rb
- #指定备份后数据存放的路径、权限、时间配置
- gitlab_rails['manage_backup_path'] = true #292行 开启备份功能
- gitlab_rails['backup_path'] = "/opt/gitlab_backups" #293行 指定备份的路径
- gitlab_rails['backup_archive_permissions'] = 0644 #296行 备份文件的权限
- gitlab_rails['backup_keep_time'] = 7776000 #301行 备份保留时间(保留90天 单位:秒
注意备份路径,备份主机要与本机一致,修改后记得执行gitlab-ctl reconfigure
3.创建备份目录并授权
mkdir /opt/gitlab_backups && chown -R git.git /opt/gitlab_backups/
4.刷新配置
gitlab-ctl reconfigure
5.手动配置
gitlab-backup create
ps:这里提示 gitlab.rb 和 gitlab-secrets.json 包涵敏感数据需要手动备份,在配置自动备份脚本中配置拷贝
6.编写备份脚本
vim backups.sh
- #!/usr/bin/bash
-
- #获取当前时间
- locale_date=`date +%Y-%m-%d.%H.%M.%S`
-
- #远端IP备份主机ip
- backup_host=127.0.0.1
-
- #本地备份路径
- backup_path=/mnt/data/gitlab/gitlab_backups
-
- #日志路径
- backup_log=/mnt/data/gitlab/gitlab_backups/gitlab_back.log
-
- #判断/mnt/data/gitlab/gitlab_backups目录是否存在,否则创建
- if [ ! -d ${backup_path} ]; then
- mkdir ${backup_path}
- fi
-
- #删除30天之前的备份数据
- find ${backup_path} -mtime +5 -name "*" -exec rm -rf {} \;
-
- #CRON=1 环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出
- #BACKUP=${locale_date}改变backup文件名称 例: 2022-06-15_11:22:52_gitlab_backup.tar
-
- /opt/gitlab/bin/gitlab-backup create BACKUP=${locale_date} CRON=1
- if [ $? -eq 0 ];then
- echo "${locale_date} ${backup_path}_gitlab_backup.tar 备份创建成功." >> ${backup_log}
- else
- echo "${locale_date} ${backup_path}_gitlab_backup.tar 备份创建失败." >> ${backup_log}
- exit 1
- fi
-
- #拷贝配置文件至本地备份目录/mnt/data/gitlab/gitlab_backups
- cp /etc/gitlab/gitlab-secrets.json ${backup_path}/${locale_date}_gitlab-secrets.json >> ${backup_log}
- cp /etc/gitlab/gitlab.rb ${backup_path}/${locale_date}_gitlab.rb >> ${backup_log}
-
- #同步本地 /opt/gitlab_backups目录到远端/opt/目录下
- rsync -avzPrt --delete ${backup_path} root@${backup_host}:/opt/ >> ${backup_log}
7.加入定时任务
crontab -e #添加定时任务
0 0,6,12,18 * * * /bin/bash //mnt/data/gitlab/backups.sh > /dev/null 2>&1
8.创建备份恢复脚本
vim restore.sh
- #!/bin/bash
-
- local_ip=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
- echo -e "本机IP:${local_ip} \n"
-
- echo -e "\033[36m发现以下下备份文件:\n \033[0m"
- ls -lt /mnt/data/gitlab/gitlab_backups/*.tar|awk -F '/' '{print $4}'
- echo -e "\n\033[36m请输入要恢复的文件或时间节点:\033[0m"
- read input
-
- gitlab_backup=${input%%_*}
- gitlab_rb=/mnt/data/gitlab/gitlab_backups/${gitlab_backup}_gitlab.rb
- secrets_json=/mnt/data/gitlab/gitlab_backups/${gitlab_backup}_gitlab-secrets.json
-
- echo -e "\n\033[36m即将恢复以下文件:\033[0m"
- echo "/opt/gitlab_backups/${gitlab_backup}_gitlab_backup.tar"
- echo ${gitlab_rb}
- echo ${secrets_json}
-
- sed -i "s#\(^external_url .*\)#external_url 'http://${local_ip}' #g" ${gitlab_rb}
-
- chown -Rf git:git /opt/gitlab_backups
-
- #/bin/cp -f /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb-`date +%Y-%m-%d_%H_%M_%S`-backup
- #/bin/cp -f /etc/gitlab/gitlab-secrets.json /etc/gitlab/gitlab-secrets.json-`date +%Y-%m-%d_%H_%M_%S`-backup
- #/bin/cp -f ${gitlab_rb} /etc/gitlab/gitlab.rb
- #/bin/cp -f ${secrets_json} /etc/gitlab/gitlab-secrets.json
- #/opt/gitlab/bin/gitlab-ctl reconfigure
- echo -e "\n\033[36m停止数据库服务\033[0m"
-
- /opt/gitlab/bin/gitlab-ctl stop unicorn
- /opt/gitlab/bin/gitlab-ctl stop puma
- /opt/gitlab/bin/gitlab-ctl stop sidekiq
-
- echo -e "\n\033[36m开始恢复${gitlab_backup}备份:\033[0m"
- /opt/gitlab/bin/gitlab-backup restore BACKUP=${gitlab_backup}
-
- echo -e "\n\033[36m备份本机配置文件\033[0m"
- /bin/cp -f /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb-`date +%Y-%m-%d_%H_%M_%S`-backup
- /bin/cp -f /etc/gitlab/gitlab-secrets.json /etc/gitlab/gitlab-secrets.json-`date +%Y-%m-%d_%H_%M_%S`-backup
- ls -lt /etc/gitlab/|grep `date +%Y-%m-%d_%H_%M_%S`
-
- echo -e "\n\033[36m覆盖本机配置文件\033[0m"
- /bin/cp -f ${gitlab_rb} /etc/gitlab/gitlab.rb
- /bin/cp -f ${secrets_json} /etc/gitlab/gitlab-secrets.json
- echo "/etc/gitlab/gitlab.rb"
- echo "/etc/gitlab/gitlab-secrets.json"
-
- echo -e "\n\033[36m重新加载配置文件并重启服务\033[0m"
- /opt/gitlab/bin/gitlab-ctl reconfigure
- /opt/gitlab/bin/gitlab-ctl restart
1、停止服务
sudo gitlab-ctl stop
2、启动服务
sudo gitlab-ctl start
3、重启gitlab服务
sudo gitlab-ctl restart
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。