debian

Debian上GitLab的数据库如何配置

小樊
49
2025-07-18 11:14:17
栏目: 智能运维

在Debian上配置GitLab的数据库,你需要遵循以下步骤:

  1. 安装数据库服务器: GitLab支持多种数据库,如PostgreSQL、MySQL和SQLite。在这个例子中,我们将使用PostgreSQL。要安装PostgreSQL,请运行以下命令:

    sudo apt-get update
    sudo apt-get install postgresql postgresql-contrib
    
  2. 创建数据库和用户: 以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命令行。

  3. 配置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>"
    

    保存并关闭文件。

  4. 重新配置和重启GitLab: 运行以下命令以应用更改并重启GitLab:

    sudo gitlab-ctl reconfigure
    sudo gitlab-ctl restart
    

现在,GitLab应该已经使用你配置的数据库运行了。如果你遇到任何问题,请查看GitLab日志以获取更多信息:/var/log/gitlab/*.log

0
看了该问题的人还看了