GitLab默認推薦PostgreSQL,其性能更優且兼容性更好。
注:CentOS 7/8中需手動安裝PostgreSQL,MySQL支持已逐步淘汰。
安裝PostgreSQL
sudo yum install -y postgresql-server postgresql-contrib
sudo postgresql-setup initdb # 初始化數據庫
sudo systemctl start postgresql
sudo systemctl enable postgresql
創建數據庫和用戶
sudo -u postgres psql
CREATE DATABASE gitlabhq_production; # 創建數據庫
CREATE USER gitlab WITH PASSWORD 'your_password'; # 創建用戶
GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production TO gitlab; # 授權
\q
修改GitLab配置文件
編輯/etc/gitlab/gitlab.rb
,添加以下內容:
gitlab_rails['db_adapter'] = 'postgresql'
gitlab_rails['db_encoding'] = 'utf8'
gitlab_rails['db_host'] = 'localhost'
gitlab_rails['db_database'] = 'gitlabhq_production'
gitlab_rails['db_username'] = 'gitlab'
gitlab_rails['db_password'] = 'your_password'
重啟GitLab生效
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
備份與恢復
gitlab-rake gitlab:backup:create # 備份至默認目錄/var/opt/gitlab/backups
gitlab-rake gitlab:backup:restore BACKUP_FILE # 指定備份文件
數據庫升級
gitlab-ctl pg-upgrade # 升級PostgreSQL版本
服務狀態檢查
gitlab-ctl status # 查看所有組件狀態
gitlab-ctl tail postgresql # 查看PostgreSQL日志
5432
端口。postgresql.conf
中的shared_buffers
等參數。以上步驟參考自。