Technology Sharing

Use of Jihu Gitlab (2)

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Table of contents

1. Modify the administrator password via Gitlab command line

2. Gitlab service management

3. The company's development code submission process

4. Gitlab backup and recovery

data backup

Test data recovery

5. Email Configuration


 

1. Modify the administrator password via Gitlab command line

  1. [root@tty01 ~]# gitlab-rails console -e production # 启动GitLab的Rails控制台
  2. --------------------------------------------------------------------------------
  3. Ruby: ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x86_64-linux]
  4. GitLab: 16.11.5-jh (3a067aedcc3) EE
  5. GitLab Shell: 14.35.0
  6. PostgreSQL: 14.11
  7. ------------------------------------------------------------[ booted in 50.69s ]
  8. Loading production environment (Rails 7.0.8.1)
  9. irb(main):001:0> user = User.where(id: 1).first # id为1的是超级管理员
  10. => #<User id:1 @root>
  11. irb(main):002:0> user.password = 'Qq111111' # 密码必须至少8个字符
  12. => "Qq111111"
  13. irb(main):003:0> user.save! # 如没有问题 返回true
  14. => true
  15. irb(main):004:0> exit # 退出

2. Gitlab service management

  1. gitlab-ctl start # 启动所有 gitlab 组件;
  2. gitlab-ctl stop # 停止所有 gitlab 组件;
  3. gitlab-ctl restart # 重启所有 gitlab 组件;
  4. gitlab-ctl status # 查看服务状态;
  5. gitlab-ctl reconfigure # 启动服务;
  6. vim /etc/gitlab/gitlab.rb # 修改默认的配置文件;
  7. gitlab-ctl tail # 查看日志;

3. The company's development code submission process

  • Project managers (PMs) create tasks in GitLab and assign them to developers

    • PM uses GitLab's Issue feature to create tasks and specify detailed descriptions and requirements of the tasks.
    • Assign tasks to specific developers, set priorities and deadlines.
  • After the developer receives the task, he uses git clone to pull the code base locally

    • The developer executes the command in the local terminal:
      git clone <仓库地址>
    • Clone the code repository to your local development environment.
  • Developers create development branches and carry out development

    • Create a new development branch locally, such asdev
      git checkout -b dev
    • existdevCode development and modification are performed on branches.
  • After the developer completes the development, submit it to the local warehouse

    • Submit code changes locally:
      git add . git commit -m "完成任务描述"
  • Developers apply for a branch merge request on the GitLab interface

    • Push the local branch to the remote repository:
      git push origin dev
    • Log in to GitLab, create a new Merge Request in the Merge Requests page of the project, select the source branch and target branch to merge (usuallymasterormain)。
  • PM checks the submission and code modification status on GitLab, and after confirming that everything is correct, confirms to merge the developer's branch into the main branch

    • PM reviews the Merge Request on GitLab, including code changes and submission records.
    • If everything is OK, PM will approve the Merge Request.devMerge branch intomasterBranch.
  • The developer confirms the development is complete by clicking Mark done on GitLab and closes the Issue.

    • When submitting a Merge Request, developers can addclose #1(in#1is the Issue number), so that when the Merge Request is merged, the related Issue will be automatically closed.
    • If there is no instruction to close the issue in the description, developers can manually close the issue on the Issue page.

 

4. Gitlab backup and recovery

Check the system version and software version

  1. [root@tty01 ~]# cat /etc/redhat-release
  2. Rocky Linux release 9.4 (Blue Onyx)
  3. [root@tty01 ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
  4. 16.11.5-jh
data backup

Open the /etc/gitlab/gitlab.rb configuration file and view a configuration item related to backup:

 

  1. [root@tty01 ~]# vim /etc/gitlab/gitlab.rb #启用下述两个配置项
  2. gitlab_rails['manage_backup_path'] = true #指定GitLab是否应该自动管理备份路径
  3. gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" #指定GitLab备份文件的存储路径

This item defines the default backup file path. You can modify this configuration and execute gitlab-ctl reconfigure or gitlab-ctl restart Restart the service to take effect.

  1. [root@tty01 ~]# gitlab-ctl reconfigure
  2. [root@tty01 ~]# gitlab-ctl restart

Execute the backup command to back up

[root@tty01 ~]# gitlab-rake gitlab:backup:create

After executing the command, there will be a warning prompt:gitlab.rbandgitlab-secrets.jsonThe files contain sensitive data and are not included in this backup. When restoring the backup, you will need to back up these files manually.

Of course, these can also be combined with planned tasks.

Check whether the files in the backup directory exist normally.

  1. [root@tty01 ~]# ls /var/opt/gitlab/backups/
  2. 1720624341_2024_07_10_16.11.5-jh_gitlab_backup.tar

Set the backup retention period to prevent daily backups. There is definitely a risk of the directory being full. Open the /etc/gitlab/gitlab.rb configuration file and find the following configuration:

  1. [root@tty01 ~]# vim /etc/gitlab/gitlab.rb # 启用下述两个配置项
  2. gitlab_rails['backup_keep_time'] = 604800 # 设置备份文件过期时间,604800秒等于7天

The configuration time is in seconds. If you want to increase or decrease it, you can configure it directly here and restart the service through gitlab-ctl restart to take effect.

After the backup is completed, a tarball with today's date will be generated in the backup directory.

Test data recovery

Log in as an administrative user and delete the library project

 

You need to stop the data connection service before restoring:

  1. [root@tty01 ~]# gitlab-ctl stop unicorn
  2. [root@tty01 ~]# gitlab-ctl stop sidekiq

If it is a newly built host, there is generally no need to stop the data connection operation. In theory, it is also OK to not stop these two services. Stopping these two services is to ensure data consistency. Generally, the backup files in the old server's /data/gitlab/backups directory are copied to the new server's /data/gitlab/backups for restoration. Here, the experimental environment is restored on this machine.

Note: 600 permissions cannot be restored. The experimental environment can be changed to 777, and the production environment is recommended to change the owner and group

After executing the command, wait for a while..., then enter yes twice to complete the recovery.

  1. [root@tty01 ~]# cd /var/opt/gitlab/backups/ #进入数据备份目录
  2. [root@tty01 backups]# gitlab-rake gitlab:backup:restore BACKUP=1720624341_2024_07_10_16.11.5-jh

Note the file name after BACKUP=. In newer versions, you cannot use the full name. _gitlab_backup.tarh will be added automatically, so you cannot write the dot after the file name.

After the recovery is complete, restart all services, or just start the two data connection services that were shut down earlier.

  1. [root@tty01 backups]# gitlab-ctl restart
  2. [root@tty01 backups]# gitlab-ctl start unicorn
  3. [root@tty01 backups]# gitlab-ctl start sidekiq

Note: When restoring gitlab through backup files, the gitlab versions of the two hosts must be consistent, otherwise a version mismatch will be prompted  

 

At this time, refresh or log in again to see the deleted data

 

 

5. Email Configuration

Please change it to your email address, mail service provider, authorization code, port and other information

  1. [root@tty01 ~]# vim /etc/gitlab/gitlab.rb #找到并替换邮箱配置,更改你的邮箱进行测试
  2. gitlab_rails['smtp_enable'] = true
  3. gitlab_rails['smtp_address'] = "smtp.163.com"
  4. gitlab_rails['smtp_port'] = 465
  5. gitlab_rails['smtp_user_name'] = "[email protected]"
  6. gitlab_rails['smtp_password'] = "UWYNCPQOBQFCDLIW"
  7. gitlab_rails['smtp_domain'] = "smtp.163.com"
  8. gitlab_rails['smtp_authentication'] = "login"
  9. gitlab_rails['smtp_enable_starttls_auto'] = false
  10. gitlab_rails['smtp_tls'] = true
  11. gitlab_rails['smtp_pool'] = false
  12. gitlab_rails['gitlab_email_from'] = '[email protected]'

 

After setting, save and exit, then reload the configuration.

[root@tty01 ~]# gitlab-ctl reconfigure  #重新配置 GitLab 服务

Log in to the web page and log in as a random user. Previously, we used a random email format. Now we change it to our real email to test our email configuration.

 

After you click Save, a pop-up window will pop up asking you to go to your mailbox and click Confirm to verify.

When I come to the mailbox, I can see that the sender is a QQ mailbox I filled in the configuration, and a verification is sent to the mailbox changed by the user.

Clicking Verify will redirect to a new page where you can see that the user has successfully changed their email address.