温馨提示×

GitLab在CentOS上的数据库选择与配置

小樊
54
2025-08-06 11:55:25
栏目: 智能运维

一、数据库选择

  • PostgreSQL:GitLab官方推荐,功能强大、支持复杂查询和事务处理,适合企业级应用。
  • MySQL/MariaDB:轻量级、易部署,适合中小型项目,但需注意GitLab 12.1+版本仅支持PostgreSQL。

二、配置步骤(以PostgreSQL为例)

  1. 安装数据库

    sudo yum install -y postgresql-server
    sudo postgresql-setup initdb
    sudo systemctl start postgresql
    sudo systemctl enable postgresql
    
  2. 创建数据库和用户

    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
    
  3. 配置GitLab连接
    编辑 /etc/gitlab/gitlab.rb

    gitlab_rails['db_adapter'] = 'postgresql'
    gitlab_rails['db_host'] = 'localhost'
    gitlab_rails['db_port'] = 5432
    gitlab_rails['db_user'] = 'gitlab'
    gitlab_rails['db_password'] = 'your_password'
    gitlab_rails['db_name'] = 'gitlabhq_production'
    
  4. 重启GitLab

    sudo gitlab-ctl reconfigure
    sudo gitlab-ctl restart
    

三、注意事项

  • 权限与安全:确保数据库用户仅拥有必要权限,限制数据库端口(5432)的访问。
  • 性能优化:根据服务器配置调整PostgreSQL参数(如shared_bufferswork_mem)。
  • 备份策略:定期备份数据库,建议使用GitLab内置备份功能或第三方工具。

0