缺省安装后的一些重要信息

  • 程序目录在:/opt/gitlab
  • 文件数据在:/var/opt/gitlab
  • git repo目录在:/var/opt/gitlab/git-data
  • 上传图片目录在:/var/opt/gitlab/uploads
  • 大文件、二进制文件目录在: /var/opt/gitlab/gitlab-rails/shared/lfs-objects
  • 备份文件目录在: /var/opt/gitlab/backups
  • 使用的本地模式运行的postgresql数据,会随gitlab启动时候自动运行,socket模式没有监听端口
  • 默认生成的配置文件位置: /var/opt/gitlab/gitlab-rails/etc
  • 使用本地运行的redis服务,会随gitlab启动时候自动运行socket
  • 缺省利用本地邮件,自动投递给其他服务器,如果是非互联网ip,可以修改为本地smtp方式
  • 修改ssh服务的git账号入口,git账号的登录shell处理为gitlab-shell
  • 自带nginx,缺省会在所有ip地址的80端口监听请求,请求会转发给ruby进程

管理

# 所有组件状态
sudo gitlab-ctl status

# 启动所有 gitlab 组件:

sudo gitlab-ctl start

# 停止所有 gitlab 组件:

sudo gitlab-ctl stop

# 重启所有 gitlab 组件:

sudo gitlab-ctl restart

# 更新配置并重启

sudo gitlab-ctl reconfigure

# 看日志

sudo gitlab-ctl tail

查看版本信息

gitlab-rake gitlab:env:info RAILS_ENV=production

System information
System: CentOS 6.5
Current User: git
Using RVM: no
Ruby Version: 2.3.3p222
Gem Version: 2.6.6
Bundler Version:1.13.7
Rake Version: 10.5.0
Redis Version: 3.2.5
Git Version: 2.13.4
Sidekiq Version:5.0.0
Go Version: unknown

GitLab information
Version: 9.4.5
Revision: 140292e
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: postgresql
URL: http://gitlab.sh.45.com
HTTP Clone URL: http://gitlab.sh.45.com/some-group/some-project.git
SSH Clone URL: git@gitlab.sh.45.com:some-group/some-project.git
Using LDAP: no
Using Omniauth: no

GitLab Shell
Version: 5.3.1
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks
Git: /opt/gitlab/embedded/bin/git

数据库同步所有历史信息

gitlab-rake db:migrate:status RAILS_ENV=production

database: gitlabhq_production

Status Migration ID Migration Name
--------------------------------------------------
up 20121220064453 Init schema
... ... ...
up 20170724214302 Add lower path index to redirect routes
up 20170725145659 Add binary to merge request diff files

汉化

确认GitLab版本

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

克隆代码

mkdir -p /opt/gitlab-zh 
cd /opt/gitlab-zh
yum -y install git

# 整个仓库300多M
# git clone https://gitlab.com/xhang/gitlab.git
cd /opt/gitlab-zh
scp zhourudong@192.168.1.51:/tmp/gitpkg/gitlab_hanhua.tar.gz .
tar xf gitlab_hanhua.tar.gz && rm -f gitlab_hanhua.tar.gz && cd gitlab
git pull

比较汉化分支和原分支导出文件

git diff origin/9-4-stable 9-4-stable-zh  > /opt/gitlab-zh/9.4.diff

补丁

cd /opt/gitlab-zh
yum -y install patch

#停止gitlab
gitlab-ctl stop

patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < /opt/gitlab-zh/9.4.diff

#启动gitlab
gitlab-ctl restart

备份恢复

https://docs.gitlab.com/ce/raketasks/backup_restore.html

备份

# 定时备份
0 1 * * * /usr/bin/gitlab-rake gitlab:backup:create

/etc/gitlab/gitlab.rb

gitlab_rails['backup_keep_time'] = 604800   # 一周, 默认为0

恢复

首先进入备份 gitlab 的目录,这个目录是配置文件中的gitlab_rails[‘backup_path’],默认为/var/opt/gitlab/backups.
然后停止 unicorn 和 sidekiq ,保证数据库没有新的连接,不会有写数据情况。

sudo gitlab-ctl stop unicorn
# ok: down: unicorn: 0s, normally up

sudo gitlab-ctl stop sidekiq
# ok: down: sidekiq: 0s, normally up

查看备份文件时间戳, 1502957534_2017_08_17_9.4.5为备份文件的时间戳

# 恢复
ls /var/opt/gitlab/backups
# 1503395474_2017_08_22_9.4.5_gitlab_backup.tar

gitlab-rake gitlab:backup:restore BACKUP=1502957534_2017_08_17_9.4.5

数据迁移

首先需要暂停服务,避免用户在迁移期间读写数据:

gitlab-ctl stop

rsync -av /var/opt/gitlab/git-data/repositories /path/to/git-data/

sudo gitlab-ctl start

sudo gitlab-ctl reconfigure

pgsql修改

# 极少情况下需要修改(修改最大权限示例)
vim /var/opt/gitlab/postgresql/data/postgresql.conf
listen_addresses = '*' # 默认只开放本地socket方式连接

# 极少情况下需要修改(修改最大权限示例)

vim /var/opt/gitlab/postgresql/data/pg_hba.conf
host all all 192.168.1.203/32 trust

清缓存

# 清空redis缓存
gitlab-rake cache:clear RAILS_ENV=production
gitlab-rake cache:clear

大型文件、二进制文件对象相关

https://docs.gitlab.com/ce/workflow/lfs/manage_large_binaries_with_git_lfs.html

https://docs.gitlab.com/ce/workflow/lfs/lfs_administration.html

Gitaly RPC调用配置

存储服务等配置

默认情况下开启
https://docs.gitlab.com/ce/administration/gitaly/index.html
/etc/default/gitlab 添加 gitaly_enabled=false,重载配置生效

监控

白名单

/etc/gitlab/gitlab.rb谁能访问

gitlab_rails['monitoring_whitelist'] = ['127.0.0.0/8', '192.168.0.1']

Admin area ➔ Monitoring ➔ Health check (admin/health_check)

https://gitlab.example.com/-/readiness?token=ACCESS_TOKEN

Prometheus 监控

默认开启监听地址为localhost

/etc/gitlab/gitlab.rb 修改配置文件禁用此服务

prometheus_monitoring['enable'] = false
prometheus['listen_address'] = 'localhost:9090'
# gitlab-ctl reconfigure

https://docs.gitlab.com/ce/administration/monitoring/prometheus/index.html

设置redis session过期

rcli() {
# This example works for Omnibus installations of GitLab 7.3 or newer. For an
# installation from source you will have to change the socket path and the
# path to redis-cli.
sudo /opt/gitlab/embedded/bin/redis-cli -s /var/opt/gitlab/redis/redis.socket "$@"
}

# test the new shell function; the response should be PONG
rcli ping
# Tell Redis to expire each matched key after 600 seconds.
rcli keys '*' | grep '^[a-f0-9]\{32\}$' | awk '{ print "expire", $0, 600 }' | rcli
# This will print '(integer) 1' for each key that gets expired.

CHECK

当前配置是否有问题

sudo gitlab-rake gitlab:check

检查git仓库

# dangling commit 检查是否有悬空的提交
gitlab-rake gitlab:repo:check
# 检查用户是否有问题,相对于某个仓库,默认所有
gitlab-rake gitlab:user:check_repos[root]

https://docs.gitlab.com/ce/administration/raketasks/ldap.html#check

https://docs.gitlab.com/ce/administration/repository_checks.html、

Performance

存储路径配置

https://docs.gitlab.com/ce/administration/repository_storage_paths.html

升级参考地址

http://interprism.hatenablog.com/entry/gitlab6to8

http://theterminallife.com/migrating-gitlab-to-gitlab-omnibus/

http://docs.gitlab.com/omnibus/update/README.html

https://gitlab.com/gitlab-org/omnibus-gitlab/issues/2109