分享 安装 GitLab 需要注意的地方

ruby_sky · June 28, 2014 · Last by yfractal replied at July 25, 2014 · 18261 hits

系统与文档说明

主要的安装 Gitlab 的流程安装请参考原官方教程: https://github.com/gitlabhq/gitlabhq/blob/7-0-stable/doc/install/installation.md 。描述的已经很清楚了。

  • 本教程是基于干净的 512M(最低标配)阿里云服务器搭建。
  • 使用的是 7-0-stable 版本,即发贴前最新版本,绝对不推荐使用 6.4.3 版本,bug 太多。

添加 swap 以满足 Gitlab 在运行中需要的“内存使用”(穷人家的孩子必读)

  • 如果你的内存超强大,请直接忽略此段介绍

  • 通常情况下,Swap 空间应大于或等于物理内存的大小,最小不应小于 64M,通常 Swap 空间的大小应是物理内存的 2-2.5 倍。

  • 参考添加 swap 的文章链接在此:https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-12-04

  • 直接阅读链接原文章比自己再重复一遍可能更好,本人服务器上设置的 swap 为 2G。:)

注意事项

  • 注意在 git 用户 (/home/git) 下使用的 git 版本必须是大于 1.7.10,在 gitlab 的配置中:

    git:
    bin_path: /usr/local/bin/git
    

    如果是编译安装 git,一般是/usr/local/bin,偶尔一般是/usr/bin目录下, 默认是/usr/bin ,特别需要小心。

  • 内存小(比如 512M),在 第一次访问 gitlab 时,往往会报 500 的错误,可以从/var/log/nginx/gitlab_error.log,查找到具体的错误,这时需要把 /home/git/gitlab/config/unicorn.rb中的第一个 timeout 配置为 300(默认为 30),因为第一次访问,会初始化很多任务,占用大量内存。

  • 不能正常的 push 或者合并 MR(Merge Request)

浏览过很多有关于 Gitlab 的安装,很多人对 gitlab 在 push 代码时,都遇到类似说 lanrion test_me (master) $ git push -u origin master fatal: 'root/test_me.git' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 特别是你在 Web 界面上操作合并 MR 时不成功,但就是没有错误信息或者其他提示。

Gitlab 是通过发送 API 的形式通知 gitlab-shell(https://github.com/gitlabhq/gitlab-shell )来执行 git 命令,所以在操作 git 相关的 操作时,除了本能的排除 gitlab/log//var/log/nginx/ 的错误,一定要仔细检查 /home/git/gitlab-shell 下的 gitlab-shell.log

像上述举例的 fatal: 'root/test_me.git' does not appear to be a git repository 错误例子,需要理解,当你使用 test 账号 在 gitlab web 界面时创建一个名为 test_gitlab 的 repository 时,gitlab 的后台其实是在/home/git/repositories/test创建了两个文件:test_gitlab.wiki.git和test_gitlab.git,原因就是没有创建test_gitlab.git.

解决方案:升级 gitlab-shell 是最佳解决方案。

如果创建正常,相对应的在 gitlab-shell.log下会有如下正常的 log:

I, [2014-06-28T01:32:18.984690 #31310]  INFO -- : Adding project test/test_gitlab.wiki.git at </home/git/repositories/test/test_gitlabwiki.git>.
I, [2014-06-28T01:32:18.986640 #31311]  INFO -- : Adding project test/test_gitlab.git at </home/git/repositories/test/test_gitlabgit>.

当然,有些部分可能是因为 API 传过来的参数 有问题,具体需要查看 gitlab-shell.log 的报错信息。

关注 gitlab-shell.log 能够帮你解决大部分的怪异问题。

  • ssh key 的问题:如果你为了方便,直接把 gitlab 的数据库 drop 掉了,然后重来,你可能会因此没有关联清空/home/git/.ssh/authorized_keys,如果你再重新运行 gitlab 并添加与之前相同的 ssh key,可能会引用 Access denied ,很大原因在你所保存的最新的 ssh key 对就的数据库表记录与你之前在 cat /home/git/.ssh/authorized_keys的历史数据不一致引起,解决方案:直接清空/home/git/.ssh/authorized_keys,重新添加一次 ssh key 即可。

  • 创建数据库时,请务必支持中文 😄

    # for mysql 
    CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
    

实用 Gitlab 自身携带的检测错误命令

  • 检查 Gitlab 环境是正确:

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

  • 检查 Gitlab 每个组件是运行情况

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

好文章,赞!

吐两个槽:

  1. authorized_keys 经常出问题,添加新用户总是需要命令重置
  2. wiki 标题不支持中文,输入直接挂

#4 楼 @siyang1982 第一点没遇到过,第二点没有测试过。

何必这么折腾 早就有安装包可以用了 https://about.gitlab.com/downloads/ 6.8 用了半年了,毫无压力

#6 楼 @suupic 这是一个问题分析帖,而不是如何教你安装。

8 Floor has deleted

@ruby_sky 我现在从其他电脑通过 SSH push 项目到 服务器上总提示输入密码 git remote add origin [email protected]:gmaildangdang/project_01.git git push -u origin master 但所有密码都试过了,还不行

#9 楼 @dangdang 查一下:gitlab-shell.log

#6 楼 @suupic 用 bitnami 一键安装更简单吧?

中文 commit 问题,还有 gbk 文件乱码问题能解决吗

#13 楼 @owiga 查查数据库编码问题。

Unknow user #15 July 25, 2014

周末,可否一约楼主?我在 珠江新城 这边 😄

#16 楼 @ruby_sky 哈哈!!加油哦!!

You need to Sign in before reply, if you don't have an account, please Sign up first.