CentOS 7 安装 GitLab 中文版

286 阅读2分钟

一、准备工作

▪ 前言

Gitlab接触了一段时间,觉得是一个很不错的开源产品(gitlab的社区版),值得我整理一篇部署教程作为记录。

安装全程选择的用户为 root

▪ 环境

操作系统:CentOS 7.6 GitLab版本:v12.3.5

▪ 更换阿里 YUM(个人习惯)

// 备份默认的 YUMmv /etc/yum.repos.d /etc/yum.repos.d.backup 
// 设置新的 YUM 目录mkdir /etc/yum.repos.d 
// 下载阿里 YUM 配置到该目录中wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
// 重建缓存yum clean allyum makecache 
// 升级所有包(改变软件设置和系统设置,系统版本内核都升级)

 

二、获取 GitLab 汉化包(要部署非汉化版,可以跳过这一块内容)

GitLab 中文社区版的项目:

v7 ~ v8.8 是由 Larry Li 发起的“GitLab 中文社区版项目”(gitlab.com/larryli/git…

v8.9 之后,@xhang 开始继续该汉化项目(gitlab.com/xhang/gitla…

获取 GitLab 汉化包:

// 安装 Gityum install -y git 
// 回到用户目录cd ~ 
// 下载最新的汉化包 git clone https://gitlab.com/xhang/gitlab.git 
// 查看该汉化补丁的版本(v12.3.5)cat gitlab/VERSION

三、部署社区版 GitLab

基础配置

// 安装 GitLab 的依赖项yum install -y curl openssh-server openssh-clients cronie policycoreutils-python 
// 安装 邮箱系统(可不装)yum install -y postfix 
// 启动 Postfixsystemctl start postfixsystemctl enable postfix 
// 设置防火墙 firewall-cmd --add-service=http --permanentfirewall-cmd --reload

获取 GitLab 的 RPM 包

查看清华开源镜像站,根据上面的 “cat gitlab/VERSION” 结果,我们需要下载 v12.3.5 的 RPM 包

// 下载包wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm 
// 安装 RPM 包rpm -i gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm

根据提示,继续执行指令配置 GitLab

gitlab-ctl reconfigure

修改配置文件 gitlab.rb

vim /etc/gitlab/gitlab.rb

// ...external_url="http://[IP]" 
// ...nginx['listen_port'] = 9091 
// ...
// unicorn 是 ruby 的HTTP SERVERunicorn['port'] = 9092

因为修改了配置文件,故需要重新加载配置内容

gitlab-ctl reconfiguregitlab-ctl restart

四、覆盖汉化包

停止 GitLab 服务

gitlab-ctl stop

切换到 GitLab 汉化包所在的目录(即步骤二获取的汉化版 GitLab )

cd ~/gitlab

比较汉化标签和原标签,导出 patch 用的 diff 文件到 /root 下

// 根据上面的 “cat gitlab/VERSION” 结果,版本为 12.3.5git diff v12.3.5 v12.3.5-zh > ../12.3.5-zh.diff

回到 /root 目录

cd ~

将 12.3.5-zh.diff 作为补丁更新到 GitLab 中

yum install patch -ypatch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < 12.3.5-zh.diff

启动 GitLab

gitlab-ctl start

重新配置 GitLab

gitlab-ctl reconfigure

五、设置管理员密码

网页方式:

地址:http://[IP]:9091

账号:root

命令方式:

gitlab-rails console production irb(main):001:0>user = User.where(id: 1).first      
// id为1的是超级管理员irb(main):002:0>user.password = '[PASSWORD]'        
// 密码必须至少8个字符irb(main):003:0>user.save!                          
// 如没有问题 返回true exit                                                
// 退出