git学习------>在CenterOS系统上安装GitLab并自定义域名访问GitLab管理页面

目前就职的公司一直使用SVN作为版本管理,现在打算尝试从SVN迁移到Git。安排我来预言并搭建好相关的环境以及自己尝试使用Git。今天我就尝试在Center OS系统上安装GitLab,现在在此记录一下整个安装过程。

第一步 查看GitLab的官方网站

GitLab的官方网站关于安装gitlab的介绍页面如下:
https://about.gitlab.com/installation/

选择 CenterOS,切换到如下的页面

按照如上图的步骤,一步一步的来即可安装成功。

第二步 安装GitLab

1. 安装和配置必要的依赖

如果你安装postfix发送邮件,请选择“网站设置”中。而不是使用后缀也可以使用sendmail配置自定义SMTP服务器配置为SMTP服务器。

在CentOS的,下面的命令将在系统防火墙打开HTTP和SSH访问。

之前没有参考官方文档,去百度搜索其他人的安装gitlab教程后,在CenterOS本机上可以正常访问gitlab的管理页面,但是其他的电脑因为防火墙的原因都不能访问gitlab的管理页面。所以这边一定要先配置好以下命令。

sudo yum install curl policycoreutils openssh-server openssh-clients
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld

2. 添加GitLab包服务器安装包

2.1 Gitlab官方下载安装

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

sudo yum install gitlab-ce

如果您不喜欢这种安装方式,你可以通过管道脚本来安装库,您可以在这里找到整个脚本,网站地址:https://packages.gitlab.com/gitlab/gitlab-ee/install

选择和下载相应的安装包 网站地址:https://packages.gitlab.com/gitlab/gitlab-ee

然后使用下面的命令手动安装和使用

curl -LJO https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-XXX.rpm/download
rpm -i gitlab-ce-XXX.rpm

2.2 Gitlab国内镜像下载安装

参考地址:
https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/

有时候,天朝访问国外网站的速度是龟速,受不了的话,可以使用清华大学的国内镜像,如上图所示,可以有Ubuntu、CenerOS等系统的不同添加国内镜像的方式。

2.2.1 Debian/Ubuntu 用户

1、首先信任 GitLab 的 GPG 公钥:

curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null

2、再选择你的 Debian/Ubuntu 版本,文本框中内容写进 /etc/apt/sources.list.d/gitlab-ce.list
比如我选择系统版本为Ubuntu 14.04,则生成的文本如下

deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu trusty main

然后使用vi命令操作/etc/apt/sources.list.d/gitlab-ce.list文件,将上面的文本添加到/etc/apt/sources.list.d/gitlab-ce.list文件中。

3、安装 gitlab-ce:

sudo apt-get update
sudo apt-get install gitlab-ce

实战截图:

使用原始的gitlab镜像,下载失败

使用国内清华大学镜像,下载成功,只需要17分钟

下载完毕,安装成功截图

2.2.2 RHEL/CentOS 用户

新建 /etc/yum.repos.d/gitlab-ce.repo,内容为

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

再执行下面命令即可。

sudo yum makecache
sudo yum install gitlab-ce

3.配置GitLab主机名

这一步在官方的文档里面没有,但是如果没有配置的话,直接启动GitLab,会出现不正确的FQDN错误,导致无法正常启动。因此必须做配置。

1. 修改/etc/gitlab/gitlab.rb文件

执行如下命令,使用gedit打开/etc/gitlab/gitlab.rb文件

sudo mkdir -p /etc/gitlab
sudo touch /etc/gitlab/gitlab.rb
sudo chmod 600 /etc/gitlab/gitlab.rb
sudo gedit /etc/gitlab/gitlab.rb

找到如下这段代码,把external_url改成部署机器的域名或者IP地址,如我的电脑ip地址就是 172.28.255.100

## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
external_url 'http://172.28.255.100'

## Legend
##! The following notations at the beginning of each line may be used to
##! differentiate between components of this file and to easily select them using
##! a regex.
##! ## Titles, subtitles etc
##! ##! More information - Description, Docs, Links, Issues etc.
##! Configuration settings have a single # followed by a single space at the
##! beginning; Remove them to enable the setting.

##! **Configuration settings below are optional.**
##! **The values currently assigned are only examples and ARE NOT the default
##!   values.**

2. 修改/var/opt/gitlab/gitlab-rails/etc/gitlab.yml文件

执行如下命令,使用gedit打开/var/opt/gitlab/gitlab-rails/etc/gitlab.yml文件

 sudo gedit /var/opt/gitlab/gitlab-rails/etc/gitlab.yml

找到关键字 * ## Web server settings *
将host的值改成本机的ip地址: 172.28.255.100 ,如下图:

# This file is managed by gitlab-ctl. Manual changes will be
# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
# and run `sudo gitlab-ctl reconfigure`.

production: &base
  #
  # 1. GitLab app settings
  # ==========================

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 172.28.255.100
    port: 80
    https: false

    # Uncommment this line below if your ssh host is different from HTTP/HTTPS one
    # (you'd obviously need to replace ssh.host_example.com with your own host).
    # Otherwise, ssh host will be set to the `host:` value above
    ssh_host: 

    # WARNING: See config/application.rb under "Relative url support" for the list of
    # other files that need to be changed for relative url support
    relative_url_root: 

    # Trusted Proxies
    # Customize if you have GitLab behind a reverse proxy which is running on a different machine.
    # Add the IP address for your reverse proxy to the list, otherwise users will appear signed in from that address.
    trusted_proxies:

    # Uncomment and customize if you can't use the default user to run GitLab (default: 'git')
    user: git

    ## Date & Time settings
    time_zone: 

    ## Email settings
    # Uncomment and set to false if you need to disable email sending from GitLab (default: true)
    email_enabled:
    # Email address used in the "From" field in mails sent by GitLab
    email_from: gitlab@172.28.255.100
    email_display_name:
    email_reply_to:
    email_subject_suffix:

到此为止,gitlab的web管理页面就可以正常访问,并通过自定义域名访问了。

如果还是不能正常访问的话,查看80端口是否被占用?
有时候80端口可能被apache给暂用了,针对此问题,直接停用apache服务,或者修改apache的默认端口。

断口被占用

在后来我进行gitlab迁移的时候,需要在新的Ubuntu服务器上搭建Gitlab的时候,端口80以及端口8080分别被Ubuntu服务器上的Apache服务和Tomcat服务所占用。

我的做法是修改 /etc/gitlab/gitlab.rb 文件

vim /etc/gitlab/gitlab.rb 

将external_url 直接输入 ip加上端口号 ,比如因为80端口被占用,我直接输入9999端口

external_url 'http://172.28.100.26:9999

修改NGINX监听的端口为9999

#edited by ouyang 2017-8-10 16:15:05
nginx['listen_addresses'] = ['*']
nginx['listen_port'] = 9999

8080端口被Tomcat占用,会出现502的页面。

因此需要修改unicorn的配置,如下:

### Advanced settings
# unicorn['listen'] = '127.0.0.1'
# unicorn['port'] = 8080

# 本机有Tomcat占用了8080,因此改为8082试一试
 unicorn['listen'] = '127.0.0.1'
 unicorn['port'] = 8082

修改Gitlab数据存储路径

默认的Gitlab数据存储路径,在目录/var/opt/gitlab/git-data下,但是新的Ubuntu服务器根目录分配的空间比较小,为了防止以后数据过大,所以可以修改路径存储为/data/gitlabData, /data是挂载的2T的硬盘够用。

### For setting up different data storing directory
###! Docs: https://docs.gitlab.com/omnibus/settings/configuration.html#storing-git-data-in-an-alternative-directory
###! **If you want to use a single non-default directory to store git data use a
###!   path that doesn't contain symlinks.**
# git_data_dirs({ "default" => { "path" => "/var/opt/gitlab/git-data", 'gitaly_address' => 'unix:/var/opt/gitlab/gitaly/gitaly.socket' } })

#edited by ouyangpeng 2017-8-10  配置gitlab的数据存储位置为/data目录下,保证硬盘安全
git_data_dirs({ "default" => { "path" => "/data/gitlabData" } })

设置完后,过一段使用时间,可以看到该目录下的resposities,如下所示:

4.配置并启动GitLab

执行如下命令

sudo gitlab-ctl reconfigure

有时候,像上面步骤修改了GitLab的ip地址一样,临时修改了GitLab的配置之后,得执行如下的命令,应用重新配好的配置并重启GitLab,然后查看GitLab的状态

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
sudo gitlab-ctl status

如下所示,就是运行命令的截图。

[root@xtgl207940 test]# sudo gitlab-ctl restart
ok: run: gitaly: (pid 27639) 1s
ok: run: gitlab-monitor: (pid 27646) 0s
ok: run: gitlab-workhorse: (pid 27649) 0s
ok: run: logrotate: (pid 27660) 1s
ok: run: nginx: (pid 27667) 0s
ok: run: node-exporter: (pid 27684) 1s
ok: run: postgres-exporter: (pid 27691) 0s
ok: run: postgresql: (pid 27700) 1s
ok: run: prometheus: (pid 27710) 0s
ok: run: redis: (pid 27720) 0s
ok: run: redis-exporter: (pid 27724) 1s
ok: run: sidekiq: (pid 27730) 1s
ok: run: unicorn: (pid 27736) 0s
[root@xtgl207940 test]#  sudo gitlab-ctl status
run: gitaly: (pid 27639) 14s; run: log: (pid 26617) 438613s
run: gitlab-monitor: (pid 27646) 13s; run: log: (pid 27069) 438589s
run: gitlab-workhorse: (pid 27649) 13s; run: log: (pid 26666) 438612s
run: logrotate: (pid 27660) 13s; run: log: (pid 26819) 438605s
run: nginx: (pid 27667) 12s; run: log: (pid 26779) 438606s
run: node-exporter: (pid 27684) 12s; run: log: (pid 26932) 438598s
run: postgres-exporter: (pid 27691) 11s; run: log: (pid 27027) 438590s
run: postgresql: (pid 27700) 11s; run: log: (pid 26269) 438678s
run: prometheus: (pid 27710) 10s; run: log: (pid 26890) 438599s
run: redis: (pid 27720) 10s; run: log: (pid 26127) 438684s
run: redis-exporter: (pid 27724) 10s; run: log: (pid 26969) 438596s
run: sidekiq: (pid 27730) 9s; run: log: (pid 26567) 438619s
run: unicorn: (pid 27750) 7s; run: log: (pid 26512) 438621s
[root@xtgl207940 test]#

5.打开浏览器,输入本机的ip地址并登陆

在您的第一次访问时,您将被重定向到密码重置屏幕,以提供初始管理员帐户的密码。输入您想要的密码,您将被重定向回登录屏幕。
默认帐户的用户名是root。提供您先前创建的密码并登录。登录后,您可以更改用户名。

我这边因为以及不是第一次访问了,所以进入的是如下的页面:

输入帐号名和密码,如果没有请先注册。

这个是新注册的帐号登陆之后的页面

然后你可以在该管理网站上进行相应的操作,如下图所示:

常用的几个Gitlab命令

# 重新应用gitlab的配置
sudo gitlab-ctl reconfigure

# 重启gitlab服务
sudo gitlab-ctl restart

# 查看gitlab运行状态
sudo gitlab-ctl status

#停止gitlab服务
sudo gitlab-ctl stop

# 查看gitlab运行日志
sudo gitlab-ctl tail

# 停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

参考链接



作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/72903221

如果本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行打赏。

时间: 2024-08-02 14:10:41

git学习------>在CenterOS系统上安装GitLab并自定义域名访问GitLab管理页面的相关文章

《易学Python》——1.3 在Windows系统上安装Python

1.3 在Windows系统上安装Python 在接下来的三小节中,我将引导您循序渐进地安装Python,创建一个简单程序以核实Python在系统上运行正常,并介绍运行程序的基本步骤.现在核实Python运行正常可避免您以后气馁. 1.3.1 安装Python 我们将使用Python 2版本,这是因为本书使用的大多数库都不支持Python 3.在本书编写期间,标准版是Python 2.7.要安装Python,需要从Python网站下载一个程序并运行它.这个程序包含Python.Python库以及

在Windows系统上安装PHP应用程序服务器

安装 PHP 应用程序服务器 (Windows) 若要处理动态 Web 页,您需要应用程序服务器.应用程序服务器是一种软件,它帮助 Web 服务器处理包含服务器端脚本或标签的 Web 页.当浏览器请求这样一个页时,Web 服务器先将该页传递给应用程序服务器进行处理,然后再发送到浏览器.有关更多信息,请参见了解 Web 应用程序. 确保运行 IIS 的系统上安装了 PHP 应用程序服务器并且正在运行.(IIS 可能位于您的硬盘或远程 Windows 计算机上.)您可以从 PHP Web 站点(网址

如何在 AIX 系统上安装和配置 IBM OpenPages GRC

了解在 AIX 系统上安装和配置 IBM OpenPages GRC IBM OpenPages GRC 简介 IBM OpenPages GRC(Governance.Risk and Compliance)平台是一个帮助企业管理整个企业风险和合规性的综合性平台.它提供一组涵盖风险和合规性领域(包括操作风险.策略和合规性.财务控制管理.IT 治理和内部审计)的核心服务和功能组件.从而帮助管理者全面和深入了解企业管理.风险和合规性.本文旨在介绍如何在 AIX 系统上安装和配置 IBM OpenP

如何在Linux系统上安装Domino Server

前言 在Linux系统上安装Domino Server是一个小小的挑战,其实并没有大家想想的复杂,既然是商业性的软件,OEM早就为我们解决了安装的难度,还有就是选择自己熟悉的Linux发行版,各个发行版操作上还是有一定的区别的,这里选择最新的Ubuntu Server 13.04,尽量在Server版本的Ubuntu上安装,虽然说Desktop版本也可以. 安装 Unbuntu server 13.4 下载Ubuntu server镜像 http://releases.ubuntu.mirror

在Linux系统上安装Wine的教程

  Wine,一个在Linux平台上非常受欢迎并且强大的开源应用,有了它,我们可以在Linux平台上完美运行Windows应用与游戏. WineHQ团队,近期宣布了一个新的开发版本Wine1.7.29.这个版本带来了诸多重要的特性,并且修复了44个bug. Wine团队几乎每周都会发布新的开发版本,并且加入许多新特性以及修复漏洞.每个新版本都会支持新的应用与游戏(Windows),这使得Wine在那些想要在Linux下运行Windows应用的用户群体中很流行并且是不可缺少的. 根据变更日志,这个

Docker CentOS7的系统上安装部署以及基础教程_docker

说明: 本文介绍如何在CentOS7的系统上安装部署Docker环境,本文参考Docker官方文档如下链接: https://docs.docker.com/engine/installation/centos/ CentOS7的系统上安装部署Docker环境 1 CentOS7安装(略) 2 升级系统 yum update 升级完成后需要重启下系统. 3 添加docker yum源 执行如下命令: cat >/etc/yum.repos.d/docker.repo name=Docker Re

Maven实战. 2.2在基于UNIX的系统上安装Maven

2.2在基于UNIX的系统上安装Maven Maven是跨平台的,它可以在任何一种主流的操作系统上运行.本节将介绍如何在基于UNIX的系统(包括Linux.Mac OS以及FreeBSD等)上安装Maven. 2.2.1下载和安装 首先,与在Windows上安装Maven一样,需要检查JAVA_HOME环境变量以及Java命令,这里对细节不再赘述.命令如下:juven@juvenubuntu:~$ echo $JAVA_HOME juven@juvenubuntu:~$ javaversi

如何在 Linux 系统上安装 Suricata 入侵检测系统

如何在 Linux 系统上安装 Suricata 入侵检测系统 随着安全威胁的不断发生,入侵检测系统(IDS)在如今的数据中心环境中显得尤为必要.然而,随着越来越多的服务器将他们的网卡升级到10GB/40GB以太网,对如此线路上的硬件进行计算密集型的入侵检测越来越困难.其中一种提升入侵检测系统性能的途径是多线程入侵检测系统,它将 CPU 密集型的深度包检测工作并行的分配给多个并发任务来完成.这样的并行检测可以充分利用多核硬件的优势来轻松提升入侵检测系统的吞吐量.在这方面有两个知名的开源项目,分别

32位-Java 8在win10系统上安装出现问题

问题描述 Java 8在win10系统上安装出现问题 我的电脑系统是win10 32位,JDK是在官网上下载的最新的版本jdk-8u65-windows-i586,但是我安装过程过总是出现下面的对话框,在最后一步被中断,请各位高手帮忙看下,不胜感激!!!!!! 解决方案 你电脑是不是有安装过JAVA的运行环境 JRE? 这里说的是ID为8024的进程在使用JDK要更新的文件,导致更新失败.而对应的进程就是JAVA的运行环境.