在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
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,607评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,047评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,496评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,405评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,400评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,479评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,883评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,535评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,743评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,544评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,612评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,309评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,881评论 3 306
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,891评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,136评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,783评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,316评论 2 342

推荐阅读更多精彩内容

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