CentOS7 部署 GitLab

CentOS7 部署 GitLab


参考

安装

  • 安装必要的依赖和配置防火墙

    sudo yum install -y curl policycoreutils-python openssh-server
    sudo systemctl enable sshd
    sudo systemctl start sshd
    sudo firewall-cmd --permanent --add-service=http
    sudo firewall-cmd --permanent --add-service=https
    sudo systemctl reload firewalld
    
  • 安装 Postfix 发送邮件通知

    sudo yum install postfix
    sudo systemctl enable postfix
    sudo systemctl start postfix
    
  • 添加 GitLab 包仓库并安装包

    curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
    yum install -y gitlab-ce
    
    安装完成后:
        Thank you for installing GitLab!
        GitLab was unable to detect a valid hostname for your instance.
        Please configure a URL for your GitLab instance by setting `external_url`
        configuration in /etc/gitlab/gitlab.rb file.
        Then, you can start your GitLab instance by running the following command:
        sudo gitlab-ctl reconfigure
        For a comprehensive list of configuration options please see the Omnibus GitLab readme
        https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
    

配置

  • vim /etc/gitlab/gitlab.rb

    external_url 'http://127.0.0.1:81'
    
    git_data_dirs({
       "default" => {
         "path" => "/home/git/MyGitLabRepository"
        }
     })
    
  • gitlab-ctl reconfigure

  • gitlab-ctl restart

  • 开机启动

    systemctl enable gitlab-runsvdir.service
    
  • 若出现502报错,查看端口占用:netstat -tnlp | grep “被占用端口”

    注意:不用去 nginx 的配置文件中配置监听端口,只需要在 external_url 'http://127.0.0.1:81' 该处配置  
    
  • http://10.8.0.1:81 访问

    第一次会要求修改 root 密码
    然后可以用:
        账户:root
        密码:刚刚修改的密码
    

GitLab 常用指令

  • 常用命令
    sudo gitlab-ctl start                             # 启动所有 gitlab 组件;
    sudo gitlab-ctl stop                              # 停止所有 gitlab 组件;
    sudo gitlab-ctl restart                           # 重启所有 gitlab 组件;
    sudo gitlab-ctl status                            # 查看服务状态;
    sudo gitlab-ctl reconfigure                       # 启动服务;
    sudo vim /etc/gitlab/gitlab.rb                    # 修改默认的配置文件;
    gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab;
    sudo gitlab-ctl tail                              # 查看日志;
    

远程仓库

  • 局域网中成功推送的配置

    remote.origin.url=git@192.168.2.189:baethan/link_probe.git
    说明需要访问的是 ssh 的端口
    而 gitlab 默认给出下面的 url,显然是不可能访问的
    git remote add origin git@127.0.0.1:private/codingexercisewithvs.git
    
  • 方案一:本地配置

    先配置内网穿透:
    baethan.vicp.io:43854  ---> 192.168.2.189:22
    在配置 ~/.ssh/config 文件:  
    Host baethan.vicp.io
        HostName baethan.vicp.io
    	Port 43854
    	user git
    	PreferredAuthentications publickey,password
    	IdentityFile C:\\Users\\Administrator\\.ssh\\id_rsa
    
  • 方案二:/etc/gitlab/gitlab.rb 配置页面显示的 SSH url 和端口,实际的 ssh 工作端口还是 sshd_config 中配置的端口

    gitlab_rails['gitlab_ssh_host'] = 'baethan.vicp.io'
    gitlab_rails['gitlab_shell_ssh_port'] = 43854
    
  • 注意事项

    • 使用 git clone 命令 clone 项目时,如果 repositorySSH 端口不是标准 22 端口时(例如,SSH tunnel模式,等等),可以使用如下命令:
    git clone ssh://git@hostname:port/.../xxx.git
    git clone ssh://git@10.137.20.113:2222/root/test.git
    

卸载

  • 停止 gitlab

    gitlab-ctl stop
    
  • 卸载 gitlab(注意这里写的是 gitlab-ee

    rpm -e gitlab-ee
    
  • 查看 gitlab 相关进程

    ps aux | grep gitlab  
    root      2109  0.0  0.0   4384   484 ?        Ss   09:30   0:00 runsvdir 
    kill 2109
    
  • 删除所有包含 gitlab 相关文件

    find / -name gitlab | xargs rm -rf
    

配置备份

  • 参考

    • https://www.cnblogs.com/kevingrace/p/7821529.html
    • https://www.cnblogs.com/ssgeek/p/9392104.html
  • 查看 gitlab version

    cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
    
  • Gitlab 的备份目录路径设置

    gitlab_rails['manage_backup_path'] = true
    gitlab_rails['backup_path'] = "/data/gitlab/backups"    //gitlab备份目录
    gitlab_rails['backup_archive_permissions'] = 0644       //生成的备份文件权限
    gitlab_rails['backup_keep_time'] = 7776000              //备份保留天数为3个月(即90天,这里是7776000秒)
    
  • 创建配置的备份目录

    mkdir -p /data/gitlab/backups  
    
  • 更改用户,配置权限

    chown -R git.git /data/gitlab/backups    很重要,否则出错
    chmod -R 777 /data/gitlab/backups        很重要,否则无法写入备份文件
    
  • 重新加载配置,重启

    gitlab-ctl reconfigure
    gitlab-ctl restart
    
  • 方案一:手动备份

    gitlab-rake gitlab:backup:create
    
  • 备份的问题:

    Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data 
    and are not included in this backup. You will need these files to restore a backup.
    Please back them up manually.
    说明:
    /etc/gitlab/gitlab.rb
    /etc/gitlab/gitlab-secrets.json
    这两个文件不在备份中,需要手动备份
    
  • 方案二:定时自动备份

    • vim /data/gitlab/backups/gitlab_backup.sh

      #!/bin/bash
      /usr/bin/gitlab-rake gitlab:backup:create CRON=1
      # 注意:环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出
      
    • 配置 crontab
      crontab -e

      使用 VIM 的操作逻辑,加入下面一行
      30 17 * * * /usr/bin/bash +x /home/vftp/GitLabBackUp/gitlab_backup.sh > /dev/null 2>&1
      

FAQ

  • gitlab-ctl reconfigure 失败

    gitlab_sysctl[kernel.sem] (postgresql::enable line 76) had an error: Mixlib::ShellOut::ShellCommandFailed: 
    execute[load sysctl conf kernel.sem] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/resources/gitlab_sysctl.rb line 46)
    had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '255'
    
  • 解决

    cat /etc/sysctl.conf /etc/sysctl.d/*.conf | sysctl -e -p -
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值