在Debian上配置GitLab的數據庫,你需要遵循以下步驟:
安裝數據庫服務器: GitLab支持多種數據庫,如PostgreSQL、MySQL和SQLite。在這個例子中,我們將使用PostgreSQL。要安裝PostgreSQL,請運行以下命令:
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
創建數據庫和用戶: 以postgres用戶身份登錄到PostgreSQL:
sudo -u postgres psql
在psql命令行中,創建一個新的數據庫和用戶,并為他們分配密碼。請將<your_database>
、<your_user>
和<your_password>
替換為你選擇的數據庫名、用戶名和密碼:
CREATE DATABASE <your_database> WITH OWNER = <your_user>;
CREATE USER <your_user> WITH PASSWORD '<your_password>';
ALTER ROLE <your_user> SET client_encoding TO 'utf8';
ALTER ROLE <your_user> SET default_transaction_isolation TO 'read committed';
ALTER ROLE <your_user> SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE <your_database> TO <your_user>;
完成后,輸入\q
退出psql命令行。
配置GitLab:
打開GitLab配置文件/etc/gitlab/gitlab.rb
:
sudo nano /etc/gitlab/gitlab.rb
在文件中找到以下部分:
# PostgreSQL configuration:
gitlab_rails['db_adapter'] = "postgresql"
gitlab_rails['db_encoding'] = "unicode"
gitlab_rails['db_collation'] = "PostgreSQL"
gitlab_rails['db_host'] = "localhost"
gitlab_rails['db_port'] = ""
gitlab_rails['db_username'] = "gitlab"
gitlab_rails['db_password'] = ""
gitlab_rails['db_database'] = "gitlabhq_production"
根據你的數據庫設置修改這些值。例如,如果你使用的是PostgreSQL,你的配置應該如下所示:
# PostgreSQL configuration:
gitlab_rails['db_adapter'] = "postgresql"
gitlab_rails['db_encoding'] = "unicode"
gitlab_rails['db_collation'] = "PostgreSQL"
gitlab_rails['db_host'] = "localhost"
gitlab_rails['db_port'] = "5432"
gitlab_rails['db_username'] = "<your_user>"
gitlab_rails['db_password'] = "<your_password>"
gitlab_rails['db_database'] = "<your_database>"
保存并關閉文件。
重新配置和重啟GitLab: 運行以下命令以應用更改并重啟GitLab:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
現在,GitLab應該已經使用你配置的數據庫運行了。如果你遇到任何問題,請查看GitLab日志以獲取更多信息:/var/log/gitlab/*.log
。