Centos6.8安装Gitlab7.6

本文涉及的产品
RDS Agent(兼容OpenClaw),2核4GB
RDS DuckDB + QuickBI 企业套餐,8核32GB + QuickBI 专业版
RDS MySQL DuckDB 分析主实例,基础系列 4核8GB
简介:

概述

本帖针对Centos6/REHL6系统
Gitlab的安装过程主要包括以下组件的配置:

  • 关闭selinux

 # 修改/etc/selinux/config 文件
 将SELINUX=enforcing改为SELINUX=disabled ,然后重启电脑
 # sestatus -v 
 查看selinux状态
 Current mode:                   permissive #说明已关闭selinux
  • 安装软件包及版本要求

  • Ubuntu/Debian/CentOS/RHEL**

  • ruby 2.0+

  • git 1.7.10+

  • redis 2.0+

  • MySQL or PostgreSQL


1.安装软件包及解决依赖项

添加EPEL源:

1
2
3
4
5
6
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-6
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
# 安装`epel-release-latest-6.noarch.rpm`包,启用EPEL
rpm -Uvh http://mirrors.ustc.edu.cn/epel/epel-release-latest-6.noarch.rpm
yum groupinstall "Development tools"
yum install autoconf automake bison build-essential byacc checkinstall cmake cpio crontabs curl curl-devel db4-devel expat-devel gcc-c++ gdbm-devel gettext gettext-devel glibc-devel libcurl4-openssl-dev libexpat1-dev libffi libffi-dev libffi-devel libgdbm-dev libicu libicu-dev libicu-devel libkrb5-dev libncurses5-dev libreadline-dev libssl-dev libtool libxml2 libxml2-dev libxml2-devel libxslt libxslt-dev libxslt-devel libyaml libyaml-dev libyaml-devel libz-dev logrotate logwatch make ncurses-devel openssh-server openssl-devel patch pcre-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-Time-HiRes pkg-config postfix python-devel python-docutils readline readline-devel sqlite-devel sudo system-config-firewall-tui tcl-devel vim wget zlib1g-dev zlib-devel

安装git
如果已经用yum安装过git,要先卸载掉旧的版本

1
yum remove git

使用源码编译安装git

1
2
3
4
5
6
7
8
9
10
11
12
mkdir /tmp/git && cd /tmp/git
curl -O --progress https://www.kernel.org/pub/software/scm/git/git-2.8.5.tar.gz
tar zxvf git-2.8.5.tar.gz
cd git-2.8.5
./configure
make prefix=/usr/local all
# 安装到/usr/local/bin
sudo make prefix=/usr/local install
# 验证git版本号
git --version
#创建软连接
ln -s /usr/local/bin/git /usr/bin/git

2.添加系统用户

我们添加一个用来管理运行Gitlab的用户git

1
2
3
4
5
6
7
adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
# 修改git用户的环境变量PATH,以root用户运行
visudo
# 找到下面一行
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin
#修改为
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

3.安装ruby环境

在Gitlab生产环境使用Ruby版本管理工具RVM,rbenv或者chruby常常会带来很多疑难杂症.比如Gitlab-shell版本管理器调用OpenSSH的功能以防止越过ssh对仓库进行pull和push操作.而前面提到的三个版本管理器不支持这样的功能,所以我们强烈建议大家按照下面的方式来安装Ruby.

Note: The current supported Ruby (MRI) version is 2.3.x. GitLab 9.0 dropped

support for Ruby 2.1.x.

  1. 如果系统上存在旧的Ruby1.8,先删除掉:

1
yum remove ruby
  1. 下载Ruby源码,编译安装:

1
2
3
4
5
6
7
8
9
10
11
mkdir /tmp/ruby && cd /tmp/ruby
# 这里替换官方文档的下载地址为mirrors.ustc.edu.cn提供的镜像地址
curl -O --progress https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz
tar zxvf ruby-2.1.5.tar.gz
cd ruby-2.1.5
./configure --disable-install-rdoc
make
sudo make install
安装完成后,重新登录终端确保$PATH生效,检测ruby的安装成功与否:
ruby -v
ln -s /usr/local/bin/ruby /usr/bin/ruby


  1. 国内使用Ruby的Gem和Bundler必须要做的事情:

1
2
3
4
5
6
7
# 修改git用户gem安装源为淘宝
gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/  
# 确保git用户当前gems源为淘宝
gem sources -l
*** CURRENT SOURCES ***
  
备:gems源中科大: https://gems.ruby-china.org/
  1. 安装bundle包(root用户)

1
sudo gem install bundler --no-ri --no-rdoc


4-1.安装数据库-mysql

安装mysql数据库,设置数据库管理员密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#下载yum仓库文件:
wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
#下载完成后将Yum库导入到你的本地:
sudo yum localinstall mysql-community-release-el6-*.noarch.rpm   
#安装MySQLServer:
yum install mysql-server mysql-devel mysql-client libmysqlclient-dev
#启动mysql服务
/etc/init.d/mysqld start
#MySQL安全配置向导
mysql_secure_installation    
---------------------------------------------------------------------------------
   Enter current password for root (enter for none):  <–初次运行直接回车
   Set root password? [Y/n]   <– 是否设置root用户密码,输入y并回车或直接回车
   Remove anonymous users? [Y/n]   <– 是否删除匿名用户,生产环境建议删除,所以直接回车
   Disallow root login remotely? [Y/n]  <–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
   Remove test database and access to it? [Y/n]   <– 是否删除test数据库,直接回车
   Reload privilege tables now? [Y/n]   <– 是否重新加载权限表,直接回车

创建新用户和数据库给gitlab使用

1
2
3
4
5
6
7
8
9
10
11
12
13
# 登录数据库
$ mysql -u root -p
# 输入root密码
# 为gitlab创建使用用户
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab账号的密码';
# 创建gitlaba使用的数据库
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# 给予gitlab用户权限
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost' IDENTIFIED BY 'gitpasswd';
# 刷新权限
mysql> flush privileges;
# 查看创建的用户
mysql> select user,host,password from mysql.user;
1
2
3
4
5
6
7
8
9
10
#测试新建的用户能否登陆mysql
mysql -u git -p -h localhost
mysql> show databases;
+---------------------+
| Database            |
+---------------------+
| information_schema  |
| gitlabhq_production |
+---------------------+
2 rows in set (0.00 sec)

4-2.安装数据库-PostgreSQL

配置postgresql安装源:
https://wiki.postgresql.org/wiki/YUM_Installation#Configure_your_YUM_repository

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 修改/etc/yum.repos.d/CentOS-Base.repo,在[base]和[update]段落添加下面的配置
exclude=postgresql*
# 安装postgresql源
yum localinstall http://mirrors.ustc.edu.cn/postgresql/repos/yum/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-3.noarch.rpm
#yum localinstall http://mirrors.ustc.edu.cn/postgresql/repos/yum/9.2/redhat/rhel-6-x86_64/pgdg-redhat92-9.2-8.noarch.rpm
# 安装postgresql
yum install postgresql95-server postgresql95-devel postgresql95-contrib
# 默认情况下,postgresql的数据库文件存放在
/var/lib/pgsql/9.5/data
  
# 初始化
mv /etc/init.d/{postgresql-9.5,postgresql}
service postgresql initdb
# 启动postgresql
service postgresql start
# 配置postgresql自启动
chkconfig postgresql on
  
# 为Gitlab创建一个用户,用户名为git
cd /home
sudo -u postgres psql -d template1 -c "CREATE USER git CREATEDB;"
#创建pg_trgm扩展 (required for GitLab 8.6+):
sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
# 创建Gitlab生产环境数据库并赋予git用户属主权限
sudo -u postgres psql -d template1 -c "CREATE DATABASE gitlabhq_production OWNER git;"
# 用git用户测试下是否能登录刚才创建的数据库
sudo -u git -H psql -d gitlabhq_production
#检查是否启用 pg_trgm 扩展:
SELECT true AS enabled
FROM pg_available_extensions
WHERE name = 'pg_trgm'
AND installed_version IS NOT NULL;
如果启用了扩展,这将产生以下输出:
  enabled
---------
  t
(1 row)
# 退出数据库会话
gitlabhq_production> \q
  
# 创建pg_config的软连接
ln -s /usr/pgsql-9.5/bin/pg_config /usr/bin/pg_config

5.配置Redis

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#此处redis是yum安装,为了省事。
yum install -y redis
  
# Disable Redis listening on TCP by setting 'port' to 0
sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf
 
#添加redis.sock文件信息
echo 'unixsocket /var/run/redis/redis.sock' |tee -a /etc/redis.conf
echo -e 'unixsocketperm 0770' |tee -a /etc/redis.conf
  
#创建文件并赋予权限
mkdir  -p /var/run/redis
sudo chown redis:redis /var/run/redis
sudo chmod 755 /var/run/redis
 
# Persist the directory which contains the socket, if applicable
if [ -d /etc/tmpfiles.d ]; then
    echo 'd  /var/run/redis  0755  redis  redis  10d  -' | sudo tee -a /etc/tmpfiles.d/redis.conf
fi
  
#将redis用户添加到git组
sudo usermod -aG redis git
 
#配置redis使其在开机时启动:
sudo chkconfig redis on
sudo service redis start

6.安装GitLab

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#将GitLab安装在git的家目录下:
cd /home/git/
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-6-stable gitlab
cd /home/git/gitlab
 
# 复制gitlab.yml(Gitlab的主配置文件)
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
  
# 修改gitlab.yml
sudo -u git -H vim config/gitlab.yml
     host: localhost为 ####修改第32行 你的域名或者ip
     port: 80
     https: false
  
# 修改 log/ 和 tmp/ 文件夹权限
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX,go-w log/
sudo chmod -R u+rwX tmp/
 
#创建文件夹gitlab-satellites
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
 
# 修改 tmp/pids/ 和 tmp/sockets/ 文件夹权限
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/
  
# 创建 public/uploads/ 文件夹
sudo -u git -H mkdir public/uploads/
  
# 修改 public/uploads/ 文件夹权限,只有git用户有访问权限
sudo chmod -R u+rwX  public/uploads
  
# 复制 Unicorn 配置文件
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
  
# 查询CPU核心数
nproc
  
# 如果你想搭建一个高负载的Gitlab实例,可启用集群模式.
# 修改'worker_processes'参数,至少要跟cpu核心数一样.
# 修改监听地址和端口,要和下文 gitlab-shell/config.yml 中配置一致
sudo -u git -H vim config/unicorn.rb
     worker_processes 3
     listen "your_IP:8080", :tcp_nopush => true
  
# 复制Rack attack 配置文件
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
  
# 为 git 用户配置用户和邮件
 
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "example@example.com"    
   
# 'autocrlf' 需要Web编辑器
sudo -u git -H git config --global core.autocrlf input
  
# 复制 Redis 连接配置文件
sudo -u git -H cp config/resque.yml.example config/resque.yml
  
# 如修改过redis socket的路径,在这个配置文件里面修改,确认redis端口和ip.
sudo -u git -H vim config/resque.yml
-------------------------------------
development: redis://127.0.0.1:6379
test: redis://127.0.0.1:6379
production: unix:/var/run/redis/redis.sock

7.GitLab数据库配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 仅限于Mysql:
sudo -u git cp config/database.yml.mysql config/database.yml
 
# 仅限于PostgreSQl:
sudo -u git cp config/database.yml.postgresql config/database.yml
 
# 以下修改针对MySQL,修改username/password.
 
sudo -u git -H vim config/database.yml
production:
   adapter: mysql2
   encoding: utf8
   collation: utf8_general_ci
   reconnect: false
   database: gitlabhq_production
   pool: 10
   username: git
   password: "gitpasswd"
   # host: localhost
   # socket: /tmp/mysql.sock
   socket: /var/lib/mysql/mysql.sock
  
  
# 以下修改针对PostgreSQL,修改username/password.
# 修改'secure password' 为你设置的密码,没单独设置则不改 
production:
   adapter: postgresql
   encoding: unicode
   database: gitlabhq_production
   pool: 10
   # username: git
   # password:        #未设置不用修改
   # host: localhost
   # port: 5432
 
# 修改database.yml的权限,确保git用户可以读取该文件.
sudo -u git -H chmod o-rwx config/database.yml

8.Gems安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 进入gitlab目录
cd /home/git/gitlab
--------------------------------------------------------------
gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
--------------------------------------------------------------
# 修改 Gemfile 和 Gemfile.lock
vim Gemfile(Gemfile.lock)
更改
source https://rubygems.org/ 
为:  
source 'https://ruby.taobao.org/'
-------------------------------------------------------------- 
# 确保只有 https://ruby.taobao.org/
gem sources -l
     https://ruby.taobao.org/
  
ln -s /usr/local/bin/bundle /usr/bin/ 
 
####一定要注意选择自己用的数据库的命令
###PostgreSQL (note, the option says "without ... mysql")
sudo -u git -H bundle install --deployment --without development test mysql aws
  
# 如果使用 MySQL,执行下面的命令 (note, the option says "without ... postgres")
sudo -u git -H bundle install --deployment --without development test postgres aws 
 
笔记: 如果你想去用 Kerberos 做用户认证, 然后在--without选项中省略Kerbero

9.Gitlab-shell安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):
sudo -u git -H bundle exec rake gitlab:shell:install[v2.4.0] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
 
# 默认情况下,gitlab-shell的配置是根据Gitlab的配置生产的.
# 你可以运行下面的命令查看和修改gitlab-shell的配置,
# 监听端口要和/home/git/gitlab/config/unicorn.rb中配置一致
sudo -u git -H vim /home/git/gitlab-shell/config.yml
---
user: git
gitlab_url:  https://localhost:8080/   #使用https 
http_settings:
   self_signed_cert: false       #如果gitlab_url为https,修改成true
repos_path: "/home/git/repositories/"
auth_file: "/home/git/.ssh/authorized_keys"
redis:
   bin: "/usr/bin/redis-cli"
   namespace: resque:gitlab
   socket: "/var/run/redis/redis.sock"
log_level: INFO
audit_usernames: false

10.初始化数据库,激活高级特性

1
2
3
4
5
6
7
8
9
10
11
cd /home/git/gitlab
  
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
  
# 输入 'yes' 以创建数据库表
  
# 当看到以下内容,表示已经安装完成
Administrator account created:
login:    root
password: your_passwd
== Seed from /home/git/gitlab/db/fixtures/production/010_settings.rb

Note: 你能通过提供环境变量设置 Administrator/root 密码和邮箱, 分别为GITLAB_ROOT_PASSWORD 和 GITLAB_ROOT_EMAIL , 如下所示。如果你不能设置密码(它被设置为默认的) 请等待曝光gitlab到公共互联网直到安装完成和你已经登录到服务器的第一时间。 在第一次登录时,您将被迫更改默认密码。.

1
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=youremail

11.下载服务脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
wget -O /etc/init.d/gitlab  https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn
# 配置gitlab的启动级别 
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab
chkconfig gitlab on 
 
设置Logrotate
cd /home/git/gitlab
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab    
 
检查GitLab环境配置
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
-----
production
 
System information
System:     CentOS 6.8
Current User:  git
Using RVM: no
Ruby Version:  2.1.5p273
Gem Version:   2.2.2
Bundler Version:1.15.1
Rake Version:  10.3.2
Sidekiq Version:2.17.8
 
GitLab information
Version:    7.6.2
Revision:   fatal: Not a git repository (or any parent up to mount point /home)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
Directory:  /home/git/gitlab
DB Adapter:    mysql2
URL:        http://your_ip
HTTP Clone URL:   http://your_ip/some-project.git
SSH Clone URL:    git@your_ip:some-project.git
Using LDAP:    no
Using Omniauth:    no
 
GitLab Shell
Version:    2.1.0
Repositories:   /home/git/repositories/
Hooks:      /home/git/gitlab-shell/hooks/
Git:        /usr/bin/git
 
 
# 生成GitLab前端资源
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
# 启动gitlab服务
service gitlab start


12.安装nginx服务,并下载gitlab的站点配置文件

1
2
3
4
5
6
7
8
9
10
# 使用yum进行安装
yum install -y nginx
chkconfig nginx on
wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab-ssl
# 将nginx用户添加到git组
mkdir -p /etc/nginx/ssl
cd /etc/nginx/ssl/
openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
# 启动nginx服务
service nginx restart

13.Gitlab配置SMTP邮件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 使用SMTP邮件服务器,可以不安装postfix
 
cd /home/git/gitlab
sudo -u git -H cp config/initializers/smtp_settings.rb.sample config/initializers/smtp_settings.rb
 
#修改如下
sudo -u git -H vim config/initializers/smtp_settings.rb
 
 
这里提供163和腾讯企业邮箱两种配置方式,注意将下面的123456替换成自己的密码
163邮箱:
if Rails.env.production?
   Gitlab::Application.config.action_mailer.delivery_method = :smtp
   ActionMailer::Base.delivery_method = :smtp        #使用smtp方法
   ActionMailer::Base.smtp_settings = {
     address: "smtp.163.com",
     port: 25,
     user_name: "wpgitlab",
     password: "123456",
     domain: "163.com",
     authentication: :plain,
     enable_starttls_auto: true
   }
end
 
QQ邮箱:
if Rails.env.production?
   Gitlab::Application.config.action_mailer.delivery_method = :smtp
   ActionMailer::Base.delivery_method = :smtp        #使用smtp方法
   ActionMailer::Base.smtp_settings = {
     address: "smtp.exmail.qq.com",
     port: 25,
     user_name: "wangpeng@scnee.com",
     password: "123456",
     domain: "smtp.qq.com",
     authentication: :plain,
     enable_starttls_auto: true,
   }
end
 
3. 修改gitlab.yml
cd /home/git/gitlab
sudo -u git -H vim config/gitlab.yml
 
一键安装路径:
cd
   /opt/gitlab-8.5.7-0
vim
  apps/gitlab/htdocs/config/gitlab.yml
 
将默认邮箱修改为自己的邮箱
163:
## Email settings
     # Email address used in the "From" field in mails sent by GitLab
     email_from: wpgit@163.com
 
腾讯企业邮箱:
## Email settings
     # Email address used in the "From" field in mails sent by GitLab
     email_from: wangpeng@scnee.com
 
 
#编辑文件
[root@git gitlab]#sudo -u git -H vim config/environments/production.rb
config.action_mailer.delivery_method = :smtp            #将方法修改成smtp方式
 
4. 修改后。重启gitlab
 
#监控日志文件
tail -f /home/git/gitlab/log/*.log
tail -f /var/log/maillog


安装完成后gitlab运行异常使用如下命令检测,并解决

1
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production


验证结果,访问地址如下:

wKiom1l1cguCzu5wAASuN-fkXt0395.png-wh_50

用户名和密码如下

login.........root

password......5iveL!fe


备份恢复

Gitlab 创建备份

使用Gitlab一键安装包安装Gitlab非常单, 同样的备份恢复与迁移也非常简单,用一条命令即可创建完整的Gitlab备份:

1
2
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production STRATEGY=copy

注:跳过某些内容sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production SKIP=db,uploads 

skip为:

db (database)
uploads (attachments)
repositories (Git repositories data)
builds (CI job output logs)
artifacts (CI job artifacts)
lfs (LFS objects)
registry (Container Registry images)
pages (Pages content)


Gitlab 修改备份文件默认目录

修改/home/git/gitlab/config/gitlab.yml来修改默认存放备份文件的目录:

1
2
3
4
sudo -u git -H vim /home/git/gitlab/config/gitlab.yml
---------------------- 
  backup:
     path: "/home/git/backups/"   # Relative paths are relative to Rails.root (default: tmp/backups/)

自动备份

1
2
3
# Create a full backup of the GitLab repositories and SQL database every day at 4am
0 4 * * * cd /home/git/gitlab && PATH=/usr/local/bin:/usr/bin:/bin bundle exec rake gitlab:backup:creat
# 0 4 * * * cd /home/git/gitlab && sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production

恢复

首先进入备份 gitlab 的目录,这个目录是配置文件中的path,本文设置为 /home/git/backups/ 。

然后停止 unicorn 和 sidekiq ,保证数据库没有新的连接,不会有写数据情况。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 停止相关数据连接服务
service gitlab stop
 
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=productione RAILS_ENV=production CRON=1
  
# 如果备份目录下面有多个备份文件,则需加参数并指明时间戳
BACKUP=timestamp_of_backup (required if more than one backup exists)
force=yes (do not ask if the authorized_keys file should get regenerated)
 
sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=productione RAILS_ENV=production CRON=1 force=yes BACKUP=timestamp_of_backup
#恢复时候BACKUP=timestamp_of_backup timestamp_of_backup表示是时间前缀 默认恢复最新一次的备份
 
# 启动Gitlab
sudo gitlab-ctl start
1
2
3
4
# 恢复过程中没有权限
mkdir /home/git/backups/
chown git /home/git/backups/
chmod 700 /home/git/backups/

迁移

把备份文件拷贝到gitlab的备份目录下,根据上面gitlab恢复步骤即可。

备份注意事项:

还需要备份文件:/home/git/gitlab/config/secrets.yml(两步验证时用到:用户名密码登录及短信验证)

本文转自奔跑在路上博客51CTO博客,原文链接http://blog.51cto.com/qiangsh/1949450如需转载请自行联系原作者


qianghong000

相关文章
|
10月前
|
存储 Ubuntu Linux
VMware-安装CentOS系统教程及安装包
虚拟机相当于是一个独立于你电脑的环境,在这个环境上面,你可以安装Linux、Windows、Ubuntu等各个类型各个版本的系统,在这个系统里面你不用担心有病读等,不用担心文件误删导致系统崩溃。 虚拟机也和正常的电脑系统是一样的,也可以开关机,不用的时候,你关机就可以了,也不会占用你的系统资源,使用起来还是比较方便 这里也有已经做好的CentOS 7系统,下载下来解压后直接用VMware打开就可以使用
1616 69
|
9月前
|
存储 分布式计算 Linux
安装篇--CentOS 7 虚拟机安装
VMware 装 CentOS 7 不知道从哪下手?这篇超详细图文教程手把手教你在 VMware Workstation 中完成 CentOS 7 桌面系统的完整安装流程。从 ISO 镜像下载、虚拟机配置,到安装图形界面、设置用户密码,每一步都有截图讲解,适合零基础新手快速上手。装好之后无论你是要搭 Hadoop 集群,还是练 Linux ,这个环境都够你折腾一整天!
4108 3
|
10月前
|
Ubuntu Linux 索引
Centos 7、Debian及Ubuntu系统中安装和验证tree命令的指南。
通过上述步骤,我们可以在CentOS 7、Debian和Ubuntu系统中安装并验证 `tree`命令。在命令行界面中执行安装命令,然后通过版本检查确认安装成功。这保证了在多个平台上 `tree`命令的一致性和可用性,使得用户无论在哪种Linux发行版上都能使用此工具浏览目录结构。
912 78
|
11月前
|
Linux 网络安全 Apache
针对在Centos/Linux安装Apache过程中出现的常见问题集锦
以上每个问题的解决方案应深入分析错误日志、系统消息和各种配置文件,以找到根本原因并加以解决。务必保持系统和Apache软件包更新到最新版本,以修复已知的bugs和安全漏洞。安装和管理Web服务器是一项需要细致关注和不断学习的任务。随着技术的发展,推荐定期查看官方文档和社区论坛,以保持知识的更新。
420 80
|
9月前
|
安全 关系型数据库 MySQL
CentOS 7 yum 安装 MySQL教程
在CentOS 7上安装MySQL 8,其实流程很清晰。首先通过官方Yum仓库来安装服务,然后启动并设为开机自启。最重要的环节是首次安全设置:需要先从日志里找到临时密码来登录,再修改成你自己的密码,并为远程连接创建用户和授权。最后,也别忘了在服务器防火墙上放行3306端口,这样远程才能连上。
2290 16
|
10月前
|
存储 关系型数据库 MySQL
在CentOS 8.x上安装Percona Xtrabackup工具备份MySQL数据步骤。
以上就是在CentOS8.x上通过Perconaxtabbackup工具对Mysql进行高效率、高可靠性、无锁定影响地实现在线快速全量及增加式数据库资料保存与恢复流程。通过以上流程可以有效地将Mysql相关资料按需求完成定期或不定期地保存与灾难恢复需求。
759 10
|
12月前
|
机器人 Linux
CentOS 7系统中安装特定版本CMake 3.21.2的方法。
到这里,过程已经全部完成。如果你跟随上面的步骤来,那么你现在已经拥有了一个全新的CMake版本在你的CentOS 7系统上了。这个过程就像是你通过一系列仪式,唤醒了一个沉睡已久的古老机器人,它现在完全按照你的意愿来帮你构建和编译软件了。
799 18
|
11月前
|
人工智能 数据挖掘 Linux
Centos安装Python3.7(亲测可用)
本指南详细介绍了在基于Linux(以CentOS系统为例,使用yum包管理器)的系统上安装Python 3.7版本的完整流程。Python是一种广泛使用的高级编程语言,在各种领域如软件开发、数据分析、人工智能和区块链开发等都有着重要的应用。
897 2
|
10月前
|
运维 网络协议 Linux
CentOS下Bind服务的安装与故障排查
通过以上的步骤,您应该能够在CentOS系统上安装并配置BIND DNS服务,并进行基本的故障排查。
783 0
|
10月前
|
存储 Ubuntu Linux
安卓手机免root安装各种Linux系统:Ubuntu, Centos,Kali等
此外还可以安装Slackware、Archstrike等系统,还可以通过github查找方法安装更多有趣的东西。 昨日小编就是通过Termux安装的Kali Linux工具包。