溫馨提示×

CentOS上GitLab的數據庫如何配置

小樊
50
2025-06-26 11:24:20
欄目: 智能運維

在CentOS上配置GitLab的數據庫,您可以選擇使用PostgreSQL或MySQL作為數據庫服務器。以下是配置這兩種數據庫的步驟:

使用PostgreSQL作為數據庫

  1. 安裝PostgreSQL:
sudo yum install -y postgresql-server postgresql-contrib
  1. 初始化數據庫:
sudo postgresql-setup initdb
  1. 啟動并啟用PostgreSQL服務:
sudo systemctl start postgresql
sudo systemctl enable postgresql
  1. 創建一個新的數據庫和用戶:
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
  1. 配置GitLab使用PostgreSQL:

編輯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中設置的密碼。

  1. 重新配置并重啟GitLab:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

使用MySQL作為數據庫

  1. 安裝MySQL:
sudo yum install -y mysql-server mysql
  1. 啟動并啟用MySQL服務:
sudo systemctl start mysqld
sudo systemctl enable mysqld
  1. 創建一個新的數據庫和用戶:

登錄到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中設置的密碼。

  1. 配置GitLab使用MySQL:

編輯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中設置的密碼。

  1. 重新配置并重啟GitLab:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

現在,GitLab已經配置好了數據庫。您可以通過訪問GitLab的Web界面來驗證配置是否成功。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女