在CentOS-7中安装Gitlab

安装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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 以下内容出自得到app,最近几年一直在说颠覆式创新,在说人工智能,在说阿法狗,所以有了以下内容,继续深度剖析颠覆式...
    芷荣说阅读 606评论 0 0
  • 内存区域划分(1)代码区:代码的二进制数据(2)数据区:全局变量、常量、静态static变量(3)堆区:动态申请的...
    大白_帕克阅读 884评论 0 0
  • 我现在在车上,向着熟悉的东方前进着,而我,此时此刻,心情却完全没有我臆想的那般轻松愉快,甚至有些恼火。 火车,我内...
    念旧的人阅读 296评论 0 0
  • 大家看过《笔仙》吗?我刚看完两部。说实话 虽然是鬼片,但我一点不害怕。 记得大学和室友一起看鬼片,她害怕的要死,把...
    怪咖小雪雪阅读 127评论 0 0