DevOps-版本控制系统-GitLab部署,


 使用RPM包部署

这里使用的系统是CentOS8, 清华源:mirrors.tuna.tsinghua.edu.cn/gitlab-ce/

  1. ## 下载软件包 
  2. wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el8/gitlab-ce-13.7.0-ce.0.el8.x86_64.rpm 
  3.  
  4. ## 安装 
  5. rpm -ivh gitlab-ce-13.7.0-ce.0.el8.x86_64.rpm 
  6.  
  7. ## 日志输出 
  8. warning: gitlab-ce-13.7.0-ce.0.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID f27eab47: NOKEY 
  9. Verifying...                          ################################# [100%] 
  10. Preparing...                          ################################# [100%] 
  11. Updating / installing... 
  12.    1:gitlab-ce-13.7.0-ce.0.el8        ################################# [100%] 
  13. It looks like GitLab has not been configured yet; skipping the upgrade script. 
  14.  
  15.        *.                  *. 
  16.       ***                 *** 
  17.      *****               ***** 
  18.     .******             ******* 
  19.     ********            ******** 
  20.    ,,,,,,,,,***********,,,,,,,,, 
  21.   ,,,,,,,,,,,*********,,,,,,,,,,, 
  22.   .,,,,,,,,,,,*******,,,,,,,,,,,, 
  23.       ,,,,,,,,,*****,,,,,,,,,. 
  24.          ,,,,,,,****,,,,,, 
  25.             .,,,***,,,, 
  26.                 ,*,. 
  27.  
  28.  
  29.  
  30.      _______ __  __          __ 
  31.     / ____(_) /_/ /   ____ _/ /_ 
  32.    / / __/ / __/ /   / __ `/ __ \ 
  33.   / /_/ / / /_/ /___/ /_/ / /_/ / 
  34.   \____/_/\__/_____/\__,_/_.___/ 
  35.  
  36.  
  37. Thank you for installing GitLab! 
  38. GitLab was unable to detect a valid hostname for your instance. 
  39. Please configure a URL for your GitLab instance by setting `external_url` 
  40. configuration in /etc/gitlab/gitlab.rb file. 
  41. Then, you can start your GitLab instance by running the following command: 
  42.   sudo gitlab-ctl reconfigure 
  43.  
  44. For a comprehensive list of configuration options please see the Omnibus GitLab readme 
  45. https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md 
  46.  
  47. Help us improve the installation experience, let us know how we did with a 1 minute survey: 
  48. https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=13-7 

配置

安装完成后可以发现以下信息,需要修改gitlab.rb配置文件。

  • GitLab was unable to detect a valid hostname for your instance. Please configure a URL for your GitLab instance by setting external_urlconfiguration in /etc/gitlab/gitlab.rb file. Then, you can start your GitLab instance by running the following command: sudo gitlab-ctl reconfigure

编辑 /etc/gitlab/gitlab.rb 可以看到默认的域名配置。如果是学习使用则可以继续使用该域名,不用再做其他配置。

  1. 32 external_url 'http://gitlab.example.com' 

如果是需要修改该域名,则需要这样做:

  1. ## 修改gitlab.rb 
  2. external_url 'http://gitlab.devops.com' 
  3. ## 重新配置 
  4. gitlab-ctl reconfigure 

服务运行控制

  1. ## 启动服务 
  2. gitlab-ctl start 
  3. ## 重启服务 
  4. gitlab-ctl restart  
  5. ## 查看状态 
  6. gitlab-ctl status  
  7. ## 停止 
  8. gitlab-ctl stop 

访问测试

由于使用的是gitlab.devops.com 这个域名,需要在dns或者本地hosts中添加该解析记录。

  1. vi /etc/hosts 
  2. 192.168.1.200 gitlab.devops.com 

浏览器访问http://gitlab.devops.com/, 设置用户密码。默认用户root。这里设置的密码是devops1234。


能够正常进入首页即可,安装完成。


扩展:使用外部PG数据库

使用docker快速启动PG

  • You are using PostgreSQL 9.6.16, but PostgreSQL >= 11 is required for this version of GitLab.
  1. mkdir /root/gitlab/pgdata 
  2.  
  3. docker run --name dockerPG11 \ 
  4. -e POSTGRES_PASSWORD=postgres \ 
  5. -v /root/gitlab/pgdata:/var/lib/postgresql/data \ 
  6. -p 54322:5432 \ 
  7. -d postgres:11.5 
  8.  
  9. ## 创建数据库 
  10. psql -U postgres -h localhost -p 54322 
  11. psql (11.5 (Debian 11.5-3.pgdg90+1)) 
  12. Type "help" for help. 
  13. postgres=# create role gitlab login encrypted password 'gitlab'; 
  14. CREATE ROLE 
  15. postgres=# create database gitlabhq_production owner=gitlab ENCODING = 'UTF8'; 
  16. CREATE DATABASE 
  17. postgres=# \c gitlabhq_production 
  18. You are now connected to database "gitlabhq_production" as user "postgres". 
  19. gitlabhq_production=# CREATE EXTENSION IF NOT EXISTS btree_gist; 
  20. CREATE EXTENSION 
  21. gitlabhq_production=# CREATE EXTENSION IF NOT EXISTS pg_trgm; 
  22. CREATE EXTENSION 
  23. postgres=# \q 

使用postgres用户创建 EXTENSION, btree_gist, pg_trgm。否则会遇到如下错误:

  • STDOUT: psql:/opt/gitlab/embedded/service/gitlab-rails/db/structure.sql:9: ERROR: permission denied to create extension "btree_gist" HINT: Must be superuser to create this extension.

修改gitlab.rb配置文件

编辑/etc/gitlab/gitlab.rb

  1. 654 gitlab_rails['db_adapter'] = "postgresql" 
  2. 655 gitlab_rails['db_encoding'] = "utf8" 
  3. 656 # gitlab_rails['db_collation'] = nil 
  4. 657 gitlab_rails['db_database'] = "gitlabhq_production" 
  5. 658 gitlab_rails['db_username'] = "gitlab" 
  6. 659 gitlab_rails['db_password'] = "gitlab" 
  7. 660 gitlab_rails['db_host'] = "192.168.1.200" 
  8. 661 gitlab_rails['db_port'] = 54322 
  9. 1025 postgresql['enable'] = false 
  10.  
  11. ## 配置更新 
  12. gitlab-ctl reconfigure 

验证配置生效

  1. cat /opt/gitlab/embedded/service/gitlab-rails/config/database.yml 
  2.  
  3. # This file is managed by gitlab-ctl. Manual changes will be 
  4. # erased! To change the contents below, edit /etc/gitlab/gitlab.rb 
  5. # and run `sudo gitlab-ctl reconfigure`. 
  6.  
  7. production: 
  8.   adapter: postgresql 
  9.   encoding: utf8 
  10.   collation: 
  11.   database: gitlabhq_production 
  12.   username: "gitlab" 
  13.   password: "gitlab" 
  14.   host: "192.168.1.200" 
  15.   port: 54322 

相关内容