环境
- 系统版本: CentOS Linux release 7.7.1908 (Core)
安装配置GitLab
安装编译环境和类库
yum -y install policycoreutils openssh-server openssh-clients postfix
设置postfix开机自启,并启动,postfix支持gitlab发信功能
systemctl enable postfix && systemctl start postfix
下载安装包,下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
下载完成后,上传安装包至服务器中,使用yum源直接安装即可
yum install -y gitlab-ce-12.6.2-ce.0.el7.x86_64.rpm
修改gitlab配置文件指定服务器ip和自定义端口
## 编辑gitlab的配置文件
vi /etc/gitlab/gitlab.rb
## 找到指定位置,将其参数修改为服务暴露IP地址或域名
## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
external_url 'http://192.168.0.72'
nginx['listen_port'] = 9091
unicorn['port'] = 9092
ps:注意这里设置的端口不能被占用,默认是8080端口,如果8080已经使用,请自定义其它端口,并在防火墙设置开放相对应得端口。
重置并启动GitLab
gitlab-ctl reconfigure
gitlab-ctl restart
分离仓库存储目录及数据库
挂载NFS磁盘,挂载方式可查看《NFS网络文件服务安装》客户端配置方式
Gitlab默然安装时,默认的仓库存储路径在 /var/opt/gitlab/git-data目录下,仓库存储在子目录repositories里面,可以通过修改/etc/gitlab/gitlab.rb文件中git_data_dirs参数来自定义父目录
## 编辑gitlab的配置文件
vi /etc/gitlab/gitlab.rb
## 找到指定位置,修改配置为挂载的磁盘地址
### For setting up different data storing directory
###! Docs: https://docs.gitlab.com/omnibus/settings/configuration.html#storing-git-data-in-an-alternative-directory
###! **If you want to use a single non-default directory to store git data use a
###! path that doesn't contain symlinks.**
git_data_dirs({
"default" => {
"path" => "/nfs-data/git-data"
}
})
## 重置并启动GitLab
gitlab-ctl reconfigure
gitlab-ctl restart
如果原有文件夹中有数据,则需要进行数据迁移;源文件夹数据无用可不做此操作
## 数据迁移前,停止服务,防止用户写入数据
gitlab-ctl stop
## 执行仓库数据迁移,正常情况应该有下面这个子目录
rsync -av /var/opt/gitlab/git-data/repositories /nfs-data/gitlab/
## 重置并启动GitLab
gitlab-ctl reconfigure
gitlab-ctl restart
分离数据库配置
首先需要在数据库中新建一个gitlab数据库,名称随意,使用gitlab专属用户名进行登录
在PostgreSQL新建gitlab数据库
## postgresql扩展pg_trgm
yum -y install postgresql-contrib
## 切换到postgreSQL数据库
su - postgres
psql
## 创建数据库用户
create user gitlab with password '*******';
## 创建数据库
create database gitlab owner gitlab;
## 将数据库的权限全部赋给新建的用户
grant all on database gitlab to gitlab;
## 使用新用户登录postgreSQL
psql gitlab
## 创建扩展pg_trgm
CREATE EXTENSION pg_trgm;
## 查看信息
select extname,extowner,extnamespace,extrelocatable,extversion from pg_extension;
编辑GitLab配置文件
## 编辑gitlab的配置文件
vi /etc/gitlab/gitlab.rb
## 找到指定位置,添加数据库配置信息
################################################################
## GitLab PostgreSQL
################################################################
###! Changing any of these settings requires a restart of postgresql.
###! By default, reconfigure reloads postgresql if it is running. If you
###! change any of these settings, be sure to run `gitlab-ctl restart postgresql`
###! after reconfigure in order for the changes to take effect.
postgresql['enable'] = false
gitlab_rails['db_adapter'] = "postgresql"
gitlab_rails['db_encoding'] = "utf8"
gitlab_rails['db_database'] = "gitlab"
gitlab_rails['db_pool'] = 30
gitlab_rails['db_username'] = "gitlab"
gitlab_rails['db_password'] = "*******"
gitlab_rails['db_host'] = "192.168.0.73"
gitlab_rails['db_port'] = "5432"
## 重置并启动GitLab
gitlab-ctl reconfigure
gitlab-ctl restart
GitLab配置备份文件夹
## 创建对应文件夹并修改权限
mkdir /home/git-data/backups
chown -R git.git /home/git-data/backups/
chmod 777 -R /home/git-data/backups/
## 编辑配置文件
vi /etc/gitlab/gitlab.rb
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/home/git-data/backups"
gitlab_rails['backup_archive_permissions'] = 0644
gitlab_rails['backup_keep_time'] = 7776000
## 重新加载配置
gitlab-ctl reconfigure
gitlab备份及备份恢复
## gitlab手动备份
gitlab-rake gitlab:backup:create
## gitlab手动恢复备份
## 停止相关服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
## 将备份的文件上传至gitlab的备份文件夹
## 执行gitlab手动备份恢复
gitlab-rake gitlab:backup:restore BACKUP=文件名
GitLab汉化
## 安装Git服务
yum install -y git
## 安装 patch 命令包
yum install -y patch
## 拉取最新版的汉化包
git clone https://gitlab.com/xhang/gitlab.git
## 停止gitlab服务
gitlab-ctl stop
## 切换到gitlab汉化包所在的目录,导出patch用的diff文件
git diff v11.1.4 v11.1.4-zh > ../v11.1.4-zh.diff
## 将文件作为补丁导入到gitlab中
patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < v11.1.4-zh.diff
## 处理完成后,重启服务即可
gitlab-ctl start