Gitlab-CE私有化仓库部署


通过离线包安装

  • 资源地址

  • 下载安装

    wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.4.5-ce.0.el7.x86_64.rpm
    
    yum localinstall gitlab-ce-11.4.5-ce.0.el7.x86_64.rpm
  • 目录迁移

    • 因为gitlab安装完毕后,数据目录(仓库文件、数据库)是默认放在系统盘下的,以防仓库过大,可以先行将数据目录迁移至更大的磁盘中
      mkdir -p /data1/gitlab_data/logs
      mkdir /data1/git-backups
      
      mv /opt/gitlab /data1/gitlab_data/
      mv /var/log/gitlab /data1/gitlab_data/logs/
      
      ln -s /data1/gitlab_data/gitlab /opt/gitlab
      ln -s /data1/gitlab_data/logs/gitlab /var/log/gitlab
  • 修改配置文件

    • 根据需要配置
      vim  /etc/gitlab/gitlab.rb
    • 可参考配置
      external_url 'http://gitlab.nestealin.com'
      gitlab_rails['smtp_enable'] = true
      gitlab_rails['smtp_address'] = "smtp.qq.com"
      gitlab_rails['smtp_port'] = 465
      gitlab_rails['smtp_user_name'] = "123456@qq.com"
      gitlab_rails['smtp_password'] = "123456abc"
      gitlab_rails['smtp_domain'] = "qq.com"
      gitlab_rails['smtp_authentication'] = "login"
      gitlab_rails['smtp_enable_starttls_auto'] = true
      gitlab_rails['smtp_tls'] = false
      gitlab_rails['smtp_openssl_verify_mode'] = 'none'
      gitlab_rails['gitlab_email_enabled'] = true
      gitlab_rails['gitlab_email_from'] = '123456@qq.com'
      gitlab_rails['gitlab_email_display_name'] = 'NesGitLab'
      gitlab_rails['gitlab_email_reply_to'] = '123456@qq.com'
      gitlab_rails['incoming_email_email'] = "123456@qq.com"
      gitlab_rails['incoming_email_password'] = "123456abc"
      gitlab_rails['manage_backup_path'] = true
      gitlab_rails['backup_path'] = "/data1/git-backups"
      gitlab_rails['backup_keep_time'] = 17800
      gitlab_rails['git_max_size'] = 2097152000
      nginx['listen_port'] = 12345
  • 加载配置并启动Gitlab

    gitlab-ctl reconfigure
    • 加载成功则出现如下提示
      Running handlers:
      Running handlers complete
      Chef Infra Client finished, 571/1519 resources updated in 03 minutes 44 seconds
      
      Notes:
      Default admin account has been configured with following details:
      Username: root
      Password: You didn't opt-in to print initial root password to STDOUT.
      Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.
      
      NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
      
      gitlab Reconfigured!
    • 从提示可以看出,初始账号是 root ,默认密码保存在文件 /etc/gitlab/initial_root_password 中。
  • 检查 gitlab 启动状态

     gitlab-ctl status
     
     >>>
    run: alertmanager: (pid 7919) 309552s; run: log: (pid 7573) 309626s
     run: gitaly: (pid 7818) 309554s; run: log: (pid 6906) 309743s
     run: gitlab-exporter: (pid 7810) 309554s; run: log: (pid 7389) 309643s
     run: gitlab-workhorse: (pid 7782) 309556s; run: log: (pid 7290) 309662s
     run: grafana: (pid 7941) 309551s; run: log: (pid 7722) 309576s
     run: logrotate: (pid 7454) 152s; run: log: (pid 6778) 309755s
     run: nginx: (pid 9983) 308688s; run: log: (pid 7329) 309657s
     run: node-exporter: (pid 7796) 309555s; run: log: (pid 7371) 309649s
     run: postgres-exporter: (pid 7934) 309552s; run: log: (pid 7601) 309620s
     run: postgresql: (pid 7039) 309737s; run: log: (pid 7050) 309736s
     run: prometheus: (pid 7828) 309554s; run: log: (pid 7428) 309632s
     run: puma: (pid 7231) 309676s; run: log: (pid 7239) 309672s
     run: redis: (pid 6799) 309750s; run: log: (pid 6807) 309749s
     run: redis-exporter: (pid 7812) 309554s; run: log: (pid 7410) 309637s
     run: sidekiq: (pid 7248) 309670s; run: log: (pid 7259) 309668s
  • 证明启动成功,在浏览器输入 gitlab.rb 文件中指定的 external_url 地址,如有设置 nginx['listen_port'] 则需要带上端口即可访问 gitlab 服务了。

    • 例如
      http://gitlab.nestealin.com:12345
    • 首次登录会提示修改用户名及密码

至此,Gitlab安装就已经完成了。


Gitlab的一些重要信息

相关目录/文件

  • 主配置文件:/etc/gitlab/gitlab.rb
  • 程序、数据库安装目录:/opt/gitlab
  • 程序配置和运行目录:/var/opt/gitlab
  • 程序日志目录:/var/log/gitlab

相关命令

  • 升级数据库:gitlab-rake db:migrate
  • 显示配置环境:gitlab-rake gitlab:env:info
  • 检查gitlab运行环境:gitlab-rake gitlab:check
  • gitlab安装(慎用,会清数据库):gitlab-rake gitlab:setup
  • gitlab启动/停止/重启:gitlab-ctl start/stop/restart

文章作者: NesTeaLin
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 NesTeaLin !
  目录