在CentOS上配置GitLab的數據庫,您可以選擇使用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
在psql命令行中,執行以下SQL命令:
CREATE DATABASE gitlab;
CREATE USER gitlab_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE gitlab TO gitlab_user;
\q
編輯GitLab配置文件 /etc/gitlab/gitlab.rb
,找到以下部分并進行修改:
gitlab_rails['db_adapter'] = "postgresql"
gitlab_rails['db_host'] = "localhost"
gitlab_rails['db_port'] = 5432
gitlab_rails['db_username'] = "gitlab_user"
gitlab_rails['db_password'] = "your_password"
gitlab_rails['db_database'] = "gitlab"
將your_password
替換為您在步驟4中設置的密碼。
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
使用MySQL作為數據庫
sudo yum install -y mysql-server mysql
sudo systemctl start mysqld
sudo systemctl enable mysqld
登錄到MySQL命令行:
mysql -u root -p
執行以下SQL命令:
CREATE DATABASE gitlab CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'gitlab_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON gitlab.* TO 'gitlab_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
將your_password
替換為您在步驟3中設置的密碼。
編輯GitLab配置文件 /etc/gitlab/gitlab.rb
,找到以下部分并進行修改:
gitlab_rails['db_adapter'] = "mysql2"
gitlab_rails['db_host'] = "localhost"
gitlab_rails['db_port'] = 3306
gitlab_rails['db_username'] = "gitlab_user"
gitlab_rails['db_password'] = "your_password"
gitlab_rails['db_database'] = "gitlab"
將your_password
替換為您在步驟3中設置的密碼。
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
現在,GitLab已經配置好了數據庫。您可以通過訪問GitLab的Web界面來驗證配置是否成功。