美文网首页工作生活
在CentOS-7中安装Gitlab

在CentOS-7中安装Gitlab

作者: _王大宝 | 来源:发表于2019-06-30 14:01 被阅读0次

    安装Gitlab社区版,即Gitlab-ce

    1首先第一步安装和配置必要的依赖,参考官网 https://about.gitlab.com/install/#centos-7

    On CentOS 7 (and RedHat/Oracle/Scientific Linux 7), the commands below will also open HTTP and SSH access in the system firewall.

    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 systemctl reload firewalld
    

    效果如下

    [root@double double]# sudo yum install -y curl policycoreutils-python openssh-server
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base: mirrors.163.com
     * extras: mirrors.163.com
     * updates: mirrors.163.com
    base                                                     | 3.6 kB     00:00     
    extras                                                   | 3.4 kB     00:00     
    updates                                                  | 3.4 kB     00:00     
    Package curl-7.29.0-51.el7.x86_64 already installed and latest version
    Package openssh-server-7.4p1-16.el7.x86_64 already installed and latest version
    Resolving Dependencies
    --> Running transaction check
    ---> Package policycoreutils-python.x86_64 0:2.5-29.el7 will be updated
    ---> Package policycoreutils-python.x86_64 0:2.5-29.el7_6.1 will be an update
    --> Processing Dependency: policycoreutils = 2.5-29.el7_6.1 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
    --> Running transaction check
    ---> Package policycoreutils.x86_64 0:2.5-29.el7 will be updated
    ---> Package policycoreutils.x86_64 0:2.5-29.el7_6.1 will be an update
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package                     Arch        Version             Repository    Size
    ================================================================================
    Updating:
     policycoreutils-python      x86_64      2.5-29.el7_6.1      updates      456 k
    Updating for dependencies:
     policycoreutils             x86_64      2.5-29.el7_6.1      updates      916 k
    
    Transaction Summary
    ================================================================================
    Upgrade  1 Package (+1 Dependent package)
    
    Total size: 1.3 M
    Downloading packages:
    warning: /var/cache/yum/x86_64/7/updates/packages/policycoreutils-2.5-29.el7_6.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
    Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    Importing GPG key 0xF4A80EB5:
     Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
     Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
     Package    : centos-release-7-6.1810.2.el7.centos.x86_64 (@anaconda)
     From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Updating   : policycoreutils-2.5-29.el7_6.1.x86_64                        1/4 
      Updating   : policycoreutils-python-2.5-29.el7_6.1.x86_64                 2/4 
      Cleanup    : policycoreutils-python-2.5-29.el7.x86_64                     3/4 
      Cleanup    : policycoreutils-2.5-29.el7.x86_64                            4/4 
      Verifying  : policycoreutils-2.5-29.el7_6.1.x86_64                        1/4 
      Verifying  : policycoreutils-python-2.5-29.el7_6.1.x86_64                 2/4 
      Verifying  : policycoreutils-2.5-29.el7.x86_64                            3/4 
      Verifying  : policycoreutils-python-2.5-29.el7.x86_64                     4/4 
    
    Updated:
      policycoreutils-python.x86_64 0:2.5-29.el7_6.1                                
    
    Dependency Updated:
      policycoreutils.x86_64 0:2.5-29.el7_6.1                                       
    
    Complete!
    [root@double double]# sudo systemctl enable sshd
    [root@double double]# sudo systemctl start sshd
    [root@double double]# sudo firewall-cmd --permanent --add-service=http
    success
    [root@double double]# sudo systemctl reload firewalld
    
    

    然后安装Postfix去发送邮件。如果需要通过其他途径发送邮件的话,可以跳过这个步骤,等Gitlab安装完成之后再配置外部的SMTP服务器,参考
    https://docs.gitlab.com/omnibus/settings/smtp.html

    sudo yum install postfix
    sudo systemctl enable postfix
    sudo systemctl start postfix
    

    During Postfix installation a configuration screen may appear. Select 'Internet Site' and press enter. Use your server's external DNS for 'mail name' and press enter. If additional screens appear, continue to press enter to accept the defaults.

    2配置GitLab的仓库地址并下载安装包

    2.1添加仓库地址

    curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
    

    这里配置yum时引用的是官方的库可能速度有影响,可以切换到国内镜像源

    配置yum源

    vim /etc/yum.repos.d/gitlab-ce.repo
    

    复制以下内容

    [gitlab-ce]
    name=gitlab-ce
    baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
    Repo_gpgcheck=0
    Enabled=1
    Gpgkey=https://packages.gitlab.com/gpg.key
    

    2.2更新本地yum缓存

    sudo yum makecache
    
    [root@double double]# sudo yum makecache
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base: mirrors.163.com
     * extras: mirrors.163.com
     * updates: mirrors.163.com
    base                                                     | 3.6 kB     00:00     
    extras                                                   | 3.4 kB     00:00     
    gitlab-ce                                                | 2.9 kB     00:00     
    updates                                                  | 3.4 kB     00:00     
    (1/8): extras/7/x86_64/other_db                            | 127 kB   00:00     
    (2/8): extras/7/x86_64/prestodelta                         |  65 kB   00:00     
    (3/8): extras/7/x86_64/filelists_db                        | 246 kB   00:00     
    (4/8): gitlab-ce/other_db                                  |  28 kB   00:00     
    (5/8): base/7/x86_64/other_db                              | 2.6 MB   00:00     
    (6/8): base/7/x86_64/filelists_db                          | 7.1 MB   00:01     
    (7/8): updates/7/x86_64/filelists_db                       | 4.4 MB   00:01     
    (8/8): gitlab-ce/filelists_db                              | 243 MB   00:23     
    Metadata Cache Created
    
    

    2.3安装GitLab社区版

    sudo EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-ce
    
    

    这里EXTERNAL_URL="http://gitlab.example.com"
    如果不需要https方式的话可以只用http
    服务器地址可以设置成本机IP
    端口默认是80,可以设置任意未占用的其他端口
    例如 EXTERNAL_URL="http://192.168.1.10:8899"。

    [root@double double]# sudo EXTERNAL_URL="http://192.168.1.10:10086" yum install -y gitlab-ce
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base: mirrors.163.com
     * extras: mirrors.163.com
     * updates: mirrors.163.com
    Resolving Dependencies
    --> Running transaction check
    ---> Package gitlab-ce.x86_64 0:12.0.2-ce.0.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package          Arch          Version                  Repository        Size
    ================================================================================
    Installing:
     gitlab-ce        x86_64        12.0.2-ce.0.el7          gitlab-ce        611 M
    
    Transaction Summary
    ================================================================================
    Install  1 Package
    
    Total download size: 611 M
    Installed size: 611 M
    Downloading packages:
    warning: /var/cache/yum/x86_64/7/gitlab-ce/packages/gitlab-ce-12.0.2-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
    Public key for gitlab-ce-12.0.2-ce.0.el7.x86_64.rpm is not installed
    gitlab-ce-12.0.2-ce.0.el7.x86_64.rpm                                      | 611 MB  00:00:58     
    Retrieving key from https://packages.gitlab.com/gpg.key
    Importing GPG key 0xE15E78F4:
     Userid     : "GitLab B.V. (package repository signing key) <packages@gitlab.com>"
     Fingerprint: 1a4c 919d b987 d435 9396 38b9 1421 9a96 e15e 78f4
     From       : https://packages.gitlab.com/gpg.key
    
    
    Public key for gitlab-ce-12.0.2-ce.0.el7.x86_64.rpm is not installed
    
    
     Failing package is: gitlab-ce-12.0.2-ce.0.el7.x86_64
     GPG Keys are configured as: https://packages.gitlab.com/gpg.key
    

    这里可以看见有一段错误

    Public key for gitlab-ce-12.0.2-ce.0.el7.x86_64.rpm is not installed
    

    可能是由于该镜像不是从官方下载导致的,可以在安装命令后面加--nogpgcheck

    sudo EXTERNAL_URL="http://192.168.1.10:8899" yum install -y gitlab-ce --nogpgcheck
    

    效果如下

    *
    *
    *
    以上一大段省略.........
    Running handlers:
    Running handlers complete
    Chef Client finished, 513/1343 resources updated in 04 minutes 09 seconds
    gitlab Reconfigured!
    
           *.                  *.
          ***                 ***
         *****               *****
        .******             *******
        ********            ********
       ,,,,,,,,,***********,,,,,,,,,
      ,,,,,,,,,,,*********,,,,,,,,,,,
      .,,,,,,,,,,,*******,,,,,,,,,,,,
          ,,,,,,,,,*****,,,,,,,,,.
             ,,,,,,,****,,,,,,
                .,,,***,,,,
                    ,*,.
      
    
    
         _______ __  __          __
        / ____(_) /_/ /   ____ _/ /_
       / / __/ / __/ /   / __ `/ __ \
      / /_/ / / /_/ /___/ /_/ / /_/ /
      \____/_/\__/_____/\__,_/_.___/
      
    
    Thank you for installing GitLab!
    GitLab should be available at http://192.168.1.10:10086
    
    For a comprehensive list of configuration options please see the Omnibus GitLab readme
    https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
    
      Verifying  : gitlab-ce-12.0.2-ce.0.el7.x86_64                                                                                                                                                                1/1 
    
    Installed:
      gitlab-ce.x86_64 0:12.0.2-ce.0.el7                                                                                                                                                                               
    
    Complete!
    
    

    3配置邮件

    前面提到等Gitlab安装完成之后再配置外部的SMTP服务器,参考
    https://docs.gitlab.com/omnibus/settings/smtp.html

    编辑gitlab.rb文件

    vi /etc/gitlab/gitlab.rb
    

    找到邮件配置区域,这里配置的是126邮箱,如下

    ### Email Settings
    # gitlab_rails['gitlab_email_enabled'] = true
    # gitlab_rails['gitlab_email_from'] = 'example@example.com'
    # gitlab_rails['gitlab_email_display_name'] = 'Example'
    # gitlab_rails['gitlab_email_reply_to'] = 'noreply@example.com'
    # gitlab_rails['gitlab_email_subject_suffix'] = ''
    gitlab_rails['smtp_enable'] = true
    gitlab_rails['smtp_address'] = "smtp.126.com"
    gitlab_rails['smtp_port'] = 25
    gitlab_rails['smtp_user_name'] = "用户名@126.com"
    gitlab_rails['smtp_password'] = "网易提供的客户端授权码,非邮箱密码"
    gitlab_rails['smtp_domain'] = "126.com"
    gitlab_rails['smtp_authentication'] = "login"
    gitlab_rails['smtp_enable_starttls_auto'] = true
    gitlab_rails['smtp_tls'] = false
    gitlab_rails['gitlab_email_from'] = "用户名@126.com"
    gitlab_rails['gitlab_email_reply_to'] = "用户名@126.com"
    user["git_user_email"] = "用户名@126.com"
    

    然后更新配置

    gitlab-ctl reconfigure
    
    如果更新后还是不行,可以重启一下试试
    
    gitlab-ctl restart
    

    4故障点

    4.1主机访问虚拟机出现502

    我这里面是在VM14里面的CentOS-7安装的gitlab-ce,便于测试需要,直接关闭了防火墙

    [root@double double]# systemctl disable firewalld
    Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
    Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
    [root@double double]# systemctl stop firewalld
    

    相关文章

      网友评论

        本文标题:在CentOS-7中安装Gitlab

        本文链接:https://www.haomeiwen.com/subject/jkcvcctx.html