三木社区

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 751|回复: 0
打印 上一主题 下一主题

快速安装 GitLab 并汉化

[复制链接]

1562

主题

1564

帖子

4904

积分

博士

Rank: 8Rank: 8

积分
4904
跳转到指定楼层
楼主
发表于 2017-9-2 10:22:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
源码安装 GitLab 步骤繁琐:需要安装依赖包,Mysql,Redis,Postfix,Ruby,Nginx……安装完毕还得一个个手动配置这些软件。源码安装容易出错,不顺利的话,一天都搞不定。源码最大的好处是私人定制,如果不做定制化,还是使用官方推荐的 omnibus packages 方式安装,网络好的话,一个小时内搞定。
参照官方安装文档,分别在 Ubuntu 14 和 CentOS 6 两个机器上安装,过程非常顺利,没有错误。
在 Ubuntu 14 安装使用国内安装源镜像,加快安装速度。修改/etc/apt/sources.list.d/gitlab-ce.list,添加以下行


  1. deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/debian jessie main
复制代码
开始安装:
  1. # 安装依赖包
  2. sudo apt-get install curl openssh-server ca-certificates postfix
  3. # 安装 GitLab 社区版
  4. apt-get install gitlab-ce
  5. # 初始化,初始化完自动启动 GitLab
  6. sudo gitlab-ctl reconfigure
复制代码
在 CentOS 6 安装
使用国内镜像安装,新建 /etc/yum.repos.d/gitlab-ce.repo,添加以下内容
  1. [gitlab-ce]
  2. name=gitlab-ce
  3. baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6
  4. repo_gpgcheck=0
  5. gpgcheck=0
  6. enabled=1
  7. gpgkey=https://packages.gitlab.com/gpg.key
复制代码
安装步骤:
  1. # 安装依赖包
  2. sudo yum install curl openssh-server openssh-clients postfix cronie
  3. # 启动 postfix 邮件服务
  4. sudo service postfix start
  5. # 检查 postfix
  6. sudo chkconfig postfix on
  7. # 安装 GitLab 社区版
  8. sudo yum install gitlab-ce
  9. # 初始化 GitLab
  10. sudo gitlab-ctl reconfigure
复制代码
修改 host
添加访问的 host,修改/etc/gitlab/gitlab.rb的external_url
  1. external_url 'http://git.home.com'
复制代码
  1. vi /etc/hosts,添加 host 映射
复制代码
  1. 127.0.0.1 git.home.com
复制代码
每次修改/etc/gitlab/gitlab.rb,都要运行以下命令,让配置生效
  1. sudo gitlab-ctl reconfigure
复制代码
配置本机的 host,如:192.168.113.59 git.home.com。最后,在浏览器打开网址http://git.home.com,登陆。默认管理员:
  1. 用户名: root
  2. 密码: 5iveL!fe
复制代码
安装中文语言包(汉化)
以下汉化步骤参考此篇文章,首先确认当前安装版本
  1. cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
复制代码
当前安装版本是8.5.7,因此中文补丁需要打8.5版本。
克隆 GitLab 源码仓库:
  1. # 克隆 GitLab.com 仓库
  2. git clone https://gitlab.com/larryli/gitlab.git
  3. #或 Gitcafe.com 镜像,速度更快
  4. git clone https://gitcafe.com/larryli/gitlab.git
复制代码
运行汉化补丁:
  1. # 8.5 版本的汉化补丁(8-5-stable是英文稳定版,8-5-zh是中文版,两个 diff 结果便是汉化补丁)
  2. sudo git diff origin/8-5-stable..8-5-zh > /tmp/8.5.diff
  3. # 停止 gitlab
  4. sudo gitlab-ctl stop
  5. # 应用汉化补丁
  6. cd /opt/gitlab/embedded/service/gitlab-rails
  7. git apply /tmp/8.5.diff  
  8. # 启动gitlab
  9. sudo gitlab-ctl start
复制代码
至此,汉化完毕。打开地址http://git.home.com,便会看到中文版的GitLab。如下
安装完成。
备份
如果是生产环境,备份是必须的。需要备份的文件:配置文件和数据文件。
备份配置文件
配置文件含密码等敏感信息,不要和数据备份文件放在一起。
  1. sh -c 'umask 0077; tar -cf $(date "+etc-gitlab-%s.tar") -C /etc/gitlab'
复制代码
备份数据文件
默认数据备份目录是/var/opt/gitlab/backups,手动创建备份文件:
  1. # Omnibus 方式安装使用以下命令备份
  2. sudo gitlab-rake gitlab:backup:create
复制代码
日常备份,添加 crontab,运行crontab -e
  1. # 每天2点执行备份
  2. 0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
复制代码
如要修改备份周期和目录,在/etc/gitlab/gitlab.rb中修改以下两个选项
  1. # 设置备份周期为7天 - 604800秒
  2. gitlab_rails['backup_keep_time'] = 604800
  3. # 备份目录
  4. gitlab_rails['backup_path'] = '/mnt/backups'
复制代码
恢复
恢复之前,确保备份文件所安装 GitLab 和当前要恢复的 GitLab 版本一致。首先,恢复配置文件:
  1. sudo mv /etc/gitlab /etc/gitlab.$(date +%s)
  2. # 将下面配置备份文件的时间戳改为你所备份的文件的时间戳
  3. sudo tar -xf etc-gitlab-1399948539.tar -C /
复制代码
恢复数据文件
  1. # 将数据备份文件拷贝至备份目录
  2. sudo cp 1393513186_gitlab_backup.tar /var/opt/gitlab/backups/

  3. # 停止连接数据库的进程
  4. sudo gitlab-ctl stop unicorn
  5. sudo gitlab-ctl stop sidekiq

  6. # 恢复1393513186这个备份文件,将覆盖GitLab数据库!
  7. sudo gitlab-rake gitlab:backup:restore BACKUP=1393513186

  8. # 启动 GitLab
  9. sudo gitlab-ctl start

  10. # 检查 GitLab
  11. sudo gitlab-rake gitlab:check SANITIZE=true

复制代码
持续集成(GitLab-CI)
GitLab 从 8.0 之后就集成了GitLab-CI,所以不需要再另外安装 CI。但需要安装Runner
1.添加 Runner 安装源
  1. # For Debian/Ubuntu
  2. curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash

  3. # For CentOS
  4. curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash

复制代码
安装gitlab-ci-multi-runner
  1. # For Debian/Ubuntu
  2. apt-get install gitlab-ci-multi-runner

  3. # For CentOS
  4. yum install gitlab-ci-multi-runner
复制代码
2.注册 Runner。获取Token:以管理员身份登录GitLab,进入管理区域,点击侧边栏的Runner,如下图,“注册授权码”后的字符串便是Token。
  1. sudo gitlab-ci-multi-runner register

  2. Running in system-mode.

  3. Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci):
  4. http://git.home.com/ci
  5. Please enter the gitlab-ci token for this runner:
  6. xxxx             # 输入Token
  7. Please enter the gitlab-ci description for this runner:
  8. [xxy-web-test-02]: test-runner  # 输入runner的名称
  9. Please enter the gitlab-ci tags for this runner (comma separated):
  10. test,php         # 输入runner的标签,以区分不同的runner,标签间逗号分隔
  11. Registering runner... succeeded                     runner=YDPz2or3
  12. Please enter the executor: ssh, shell, parallels, docker, docker-ssh, virtualbox:
  13. shell
  14. Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

复制代码
注册完成便可在上图中查看你所注册的Runner。至此,所有安装完毕,Runner的构建,后续补充。
  1. http://www.jianshu.com/p/7a0d6917e009?mType=Group
复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

Archiver|手机版|小黑屋|三木电子社区 ( 辽ICP备11000133号-4 )

辽公网安备 21021702000620号

GMT+8, 2024-4-21 00:10 , Processed in 0.032293 second(s), 23 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表