安装并配置必要的依赖关系
安装Postfix
Postfix支持Gitlab发信功能
1 | yum -y install postfix |
设置Postfix开机自启,并启动
1 | systemctl enable postfix |
在Postfix安装期间,可能会出现配置屏幕。选择“Internet Site”并按Enter键。使用服务器的外部DNS作为“邮件名称”,然后按Enter键。如果出现其他屏幕,请继续按Enter键接受默认值。
添加 GitLab 镜像仓库并安装
gitlab-ce 是社区版,免费
gitlab-ee 是企业版,收费
使用官方镜像安装
1 | curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash |
更改 https://gitlab.example.com 为您要访问GitLab实例的URL
使用国内镜像安装(推荐)
如果提示连接超时,可以使用清华大学开源软件镜像站
进入该网站后,有详细的安装步骤,跟着安装即可。
这里介绍一下在CentOS中使用 清华大学开源软件镜像站安装
先还原yum源, 删掉Gitlab-ce源
1 | ls -l /etc/yum.repos.d/ # 查看源配置项 |
新建/etc/yum.repos.d/gitlab-ce.repo
,内容为
1 | cat > /etc/yum.repos.d/gitlab-ce.repo <<EOF |
再执行
1 | yum makecache |
配置并启动 GitLab
启动命令
1 | gitlab-ctl reconfigure # 首次启动也要用此命令。重新加载配置并启动 |
GitLab基本配置集中在/etc/gitlab/gitlab.rb
文件, 每个参数的作用和配置请参考官网的配置说明.
需要注意的几个参数
1 | external_url 'http://192.168.1.83' # clone时显示的地址,gitlab 的域名 |
1 | gitlab-ctl stop # 先停止 GitLab 服务 |
进行任何改动后, 保存退出, 在命令行逐个输入以下命令使配置生效
启动数据库, 不然 reconfigure 报错
1 | gitlab-ctl restart postgresql |
汉化
当前版本信息
1 | gitlab_version=$(cat /opt/gitlab/embedded/service/gitlab-rails/VERSION) |
假设当前版本为v12.0.4,并确认汉化版本库是否包含该版本的汉化标签(-zh结尾)。
如果具有相同版本的汉化标签,则在本地 clone 仓库。
安装git,patch
1 | yum -y install git patch |
克隆汉化版本库(可能下载很慢,拼运气的)
1 | git clone https://gitlab.com/xhang/gitlab.git |
查看该汉化补丁的版本
1 | cat gitlab/VERSION |
如果已经克隆过,则进行更新
1 | git fetch |
然后比较汉化标签和原标签,导出 patch 用的 diff 文件。
导出12.0.4版本的汉化补丁
1 | git diff v${gitlab_version} v${gitlab_version}-zh > ../${gitlab_version}-zh.diff |
执行完毕后将生成当前版本的补丁文件,如 12.0.4-zh.diff
导入汉化补丁
停止 gitlab
1 | gitlab-ctl stop |
1 | cd /root |
确定没有 .rej 文件,重启 GitLab 即可。
1 | gitlab-ctl start |
执行重新配置命令
1 | gitlab-ctl reconfigure |
卸载GitLab
1 | gitlab-ctl stop # 停止 |
邮件配置
主要修改两个地方
1 | vi /etc/gitlab/gitlab.rb |
1 | gitlab_rails['gitlab_email_enabled'] = true |
1 | gitlab_rails['smtp_enable'] = true |
修改完后重新加载配置
1 | gitlab-ctl reconfigure |
通过命令行测试邮件是否发送成功
1 | gitlab-rails console |
linux git pull/push时提示输入账号密码之免除设置
1、先cd到根目录,执行git config --global credential.helper store
命令
1 | # git config --global credential.helper store |
2、执行之后会在.gitconfig文件中多加红色字体项
1 | [user] |
3、之后cd到项目目录,执行git pull
命令,会提示输入账号密码。输完这一次以后就不再需要,并且会在根目录生成一个.git-credentials
文件
1 | # git pull |
4、之后pull/push
代码都不再需要输入账号密码了~
如果这个时候,还是提示需要输入账号,那就要进项目的根目录,.git 目录的 config里 找到
1 | [remote "origin"] |
修改这里的url