Gitlab Settings Database-yellowcong

Posted by praveenhotha on Sun, 19 May 2019 10:09:28 +0200

To be honest, Gitlab's database configuration is quite complex, and there are many configuration files that need to be modified. The main steps are as follows: 1. Creating a database. 2. Add database configuration in / etc/gitlab/gitlab.rb file. 3. Install mysql dependency on gitlab. 4. Execute gitlab-rake gitlab:check to check the configuration file. There are many errors in this place. 5. After no errors, restart the server and set the administrator password.

1. Creating a database

#Create a database
create database gitlab DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

#add permission
GRANT ALL PRIVILEGES ON gitlab.*TO 'gitlab'@'%' IDENTIFIED BY 'gitlab' WITH GRANT OPTION;

#Refresh authority
flush privileges;

2. Configure gitlab.rb and add mysql

vim /etc/gitlab/gitlab.rb

#Modify database configuration
gitlab_rails['db_adapter'] = "mysql2"
gitlab_rails['db_encoding'] = "utf8"
gitlab_rails['db_database'] = "gitlab"
gitlab_rails['db_username'] = "gitlab"
gitlab_rails['db_password'] = "gitlab"
gitlab_rails['db_host'] = "127.0.0.1"
gitlab_rails['db_port'] = 3306
postgresql['enable'] = false

3. Dependence on configuring gitlab

3.1 Remove postgres dependencies

#Without mysql2, download one with ruby's gem tool. Before downloading, configure ruby's gem and bundle
#Edit config
vim /opt/gitlab/embedded/service/gitlab-rails/.bundle/config

Replace the original mysql with postgres, and we don't need the postgers package.

3.2 Installing mysql dependencies

Installation dependencies, you need to specify the version, you can first install, then execute gitlab-rake gitlab:check to see the installed version.

## Almost all commands in gitlab are in this directory
 cd /opt/gitlab/embedded/bin/

##Install mysql
./gem install mysql2

#Delete mysql
./gem uninstall mysql2

#Install the specified version
./gem install mysql2 -v "0.3.20"

#View version
./gem list | grep mysql

4. Check configuration

This check is to ensure that our configuration is absolutely correct. Otherwise, if we do it directly, we will die miserably. There will be a lot of mistakes in this place. You can see my common problems concretely, maybe the same.

#See if the configuration isok,If the databaseokIt can be executed directly.gitlab-rake gitlab:setup,To create tables in the database.
gitlab-rake gitlab:check 

Check configuration information

5. Initialization of gitlab

Execute the gitlab-rake gitlab:setup command to initialize gitlab.

#Initialize gitlab
gitlab-rake gitlab:setup

After we execute gitlab-rake gitlab:setup, we are prompted that the previous data information will be lost. Of course, we don't set it as yes. What's the fun behind it?

After success, a root user is created

6. Restart Services

#####The next few commands commonly used in gitlab-ctl are not needed for this configuration
#Configuration service
gitlab-ctl reconfigure;

#Restart service
gitlab-ctl restart;

#View startup status
gitlab-ctl tail 

7. Viewing database information

You can see that there are many more tables in the database, and then the service starts normally.

#You can see that many tables have been created automatically.
 show tables;

Service Start Normally

Common problem

1. Warehouse Storage Directory Permissions

The solution is to set the right of gt user sudo chown-R git: git/var/opt/gitlab/git-data/repositories to the warehouse.

default... no
  User id for git: 995. Groupd id for git: 993
  Try fixing it:
  sudo chown -R git:git /var/opt/gitlab/git-data/repositories
  For more information see:
  doc/install/installation.md in section "GitLab Shell"
  Please fix the error above and rerun the checks.

2. gitlab does not depend on MySQL 2

Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). excluded from capture due to environment or should_capture callback

Solution, Installation Dependence

#To the bin directory, execute the gem command
cd /opt/gitlab/embedded/bin

#Install the specified version of mysql driver
gem install mysql2 -v "0.3.20"

3. The problem of gitlab not finding tables

If the driver installation is successful, execute gitlab-rake gitlab:check, and if the table does not exist, execute the following code to create the table.

gitlab-rake gitlab:setup

4,gitlab-shell self-check failed

Auto-check fails. The reason for this problem is that you can't find your own server. The solution is to point to your own server in the local hosts.

Solution, / etc/hosts add 127.0.0.1 localhost, I will test the function first.

vim /etc/hosts 

#Add to
127.0.0.1 localhost

Reference articles

https://docs.gitlab.com/omnibus/settings/database.html
http://www.mamicode.com/info-detail-1688017.html
https://blog.csdn.net/shilei_zhang/article/details/77568505

Topics: GitLab Database MySQL git