热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Centos7搭建gitlab环境

前言在学习Gitlab的环境搭建之前,首先需要了解Git,Gitlab,GitHub他们三者之间的关系Git它是一个源代码版本控制系统,可让您在本地跟踪更改并从远程资源推送

前言

在学习Gitlab的环境搭建之前,首先需要了解Git,Gitlab,GitHub他们三者之间的关系

Git 它是一个源代码版本控制系统,可让您在本地跟踪更改并从远程资源推送或提取更改。
GitHub 是一项公开可用的免费服务,它要求所有代码(除非您有付费帐户)公开。 任何人都可以看到您推送给GitHub的代码并提供改进建议。
GitLab是一种类似github的服务,组织可以使用它来提供git存储库的内部管理。 它是一个自我托管的Git-repository管理系统,可以保持用户代码的私密性,并且可以轻松地部署代码的更改。

简单来说,github是全世界最大的开源的gay友平台,适合免费公开的代码。gitlab是搭建本公司的代码管理平台,适合私有的平台代码管理。
因为本公司的代码不想被其它人看到,这就需要搭建一个本公司的gitlab平台,供公司内部人员使用。

环境准备:

centos 7
gitlab 10

安装依赖包

GitLab 10.x之后添加多了一些依赖,并且要启动sshd服务,所以我们先添加依赖,启动sshd,为防火墙添加服务

sudo yum install -y curl policycoreutils-python openssh-server openssh-clients sudo systemctl enable sshd sudo systemctl start sshd # 防火墙这2步可以不用管 # sudo firewall-cmd –permanent –add-service=http # sudo systemctl reload firewalld

postfix的产生是为了替代传统的sendmail.相较于sendmail,postfix在速度。性能和稳定性上都更胜一筹。
如今眼下许多的主流邮件服务事实上都在採用postfix. 当我们须要一个轻量级的的邮件server是,postfix不失为一种选择。

  • postfix想要作用的范围是广大的Internet用户。试图影响大多数的Internet上的电子邮件系统,因此它是免费的。
  • postfix在性能上大约比sendmail快三倍。一部执行postfix的台式PC每天能够收发上百万封邮件。
  • postfix是sendmail兼容的,从而使sendmail用户能够非常方便地迁移到postfix。Postfix支持/var[/spool]/mail、/etc/aliases、 NIS、和 ~/.forward 文件。
  • postfix被设计成在重负荷之下仍然能够正常工作。当处理的邮件数目增长时,postfix执行的进程不会跟着添加。
  • postfix是由超过一打的小程序组成的,每一个程序完毕特定的功能。

gitlab配置需要用到邮件发送,所以先安装postfix

yum -y install postfix

安装完之后,启动postfix

systemctl start postfix

启动过程中如果报错:Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.

解决办法,vim打开/etc/postfix/main.cf,修改如下两项,修改之前可以先备份下

# 修改 /etc/postfix/main.cf的设置 inet_protocols = ipv4 inet_interfaces = all  

修改完成后,再次启动,就不会报错了,设置postfix为开机自启动

systemctl enable postfix

查看启动状态,看到 Active: active (running) 就是已经正常启动了

systemctl status postfix

完整的操作如下

[root ~]# yum -y install policycoreutils-python openssh-server openssh-clients [root ~]# systemctl enable sshd [root ~]# systemctl start sshd [root ~]# yum -y install postfix [root ~]# systemctl start postfix Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details. [root~]# cp /etc/postfix/main.cf /etc/postfix/main.cf.bak [root~]# vim /etc/postfix/main.cf # 修改inet_protocols = ipv4 和inet_interfaces = all [root ~]# systemctl start postfix [root ~]# systemctl enable postfix [root~]# systemctl status postfix ● postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2019-01-15 15:37:28 CST; 5min ago Process: 3171 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS) Process: 3167 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS) Process: 3164 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS) Main PID: 3244 (master) CGroup: /system.slice/postfix.service ├─3244 /usr/libexec/postfix/master -w ├─3245 pickup -l -t unix -u └─3246 qmgr -l -t unix -u Jan 15 15:37:27 systemd[1]: Starting Postfix Mail Transport Agent... Jan 15 15:37:28 postfix/postfix-script[3242]: starting the Postfix mail system Jan 15 15:37:28 postfix/master[3244]: daemon started -- version 2.10.1, configuration /etc/postfix Jan 15 15:37:28 systemd[1]: Started Postfix Mail Transport Agent. [root~]# 

gitlab安装

centos 7系统的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7

找个最新版去下载gitlab-ce-11.6.3-ce.0.el7.x86_64.rpm

下载rpm包并安装

# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm # mkdir /usr/local/gitlab # mv gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm /usr/local/gitlab/ # cd /usr/local/gitlab/ # rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm warning: gitlab-ce-11.6.3-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY error: Failed dependencies:  policycoreutils-python is needed by gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm # 如果出现上面这个报错就执行yum install policycoreutils-python # yum -y install policycoreutils-python # rpm -i gitlab-ce-11.6.3-ce.0.el7.x86_64.rpm warning: gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY It looks like GitLab has not been configured yet; skipping the upgrade script. *. *. *** *** ***** ***** .****** ******* ******** ******** ,,,,,,,,,***********,,,,,,,,, ,,,,,,,,,,,*********,,,,,,,,,,, .,,,,,,,,,,,*******,,,,,,,,,,,, ,,,,,,,,,*****,,,,,,,,,. ,,,,,,,****,,,,,, .,,,***,,,, ,*,. _______ __ __ __ / ____(_) /_/ / ____ _/ /_ / / __/ / __/ / / __ `/ __ \ / /_/ / / /_/ /___/ /_/ / /_/ / \____/_/\__/_____/\__,_/_.___/ 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

安装完成之后,会出现gitlab官方文档地址https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

配置并启动gitlab-ce

gitlab安装完成后,需要设置一个访问地址(或域名),打开/etc/gitlab/gitlab.rb将默认的external_url = 'http://git.example.com'修改为自己的IP地址:http://xxx.xx.xxx.xx

# vim /etc/gitlab/gitlab.rb

原来默认的external_url

## 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://git.example.com'

修改成自己定义的url地址,端口自己设置一个,别和已有的冲突了

## 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://47.104.x.x:8100'

修改完成后:wq保存退出,执行以下命令,让配置生效

# gitlab-ctl reconfigure

启动Gitlab

# gitlab-ctl start

# gitlab-ctl start ok: run: gitaly: (pid 6638) 186s ok: run: gitlab-monitor: (pid 6656) 186s ok: run: gitlab-workhorse: (pid 6659) 186s ok: run: logrotate: (pid 6703) 185s ok: run: nginx: (pid 6709) 185s ok: run: node-exporter: (pid 6715) 184s ok: run: postgres-exporter: (pid 6720) 184s ok: run: postgresql: (pid 7324) 44s ok: run: prometheus: (pid 6752) 171s ok: run: redis: (pid 6761) 171s ok: run: redis-exporter: (pid 6765) 170s ok: run: sidekiq: (pid 7299) 45s ok: run: unicorn: (pid 7476) 18s

启动完成后,在浏览器输入http://47.104.x.x:8100,就是gitlab的登录首页了,如果出现502页面,需修改默认的8080端口

502问题

打开gitlab首页出现502问题

出现这个问题,主要是因为8080端口被占用,之前安装tomcat默认的是8080端口,netstat -ntpl查看端口情况

# netstat -ntpl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:9100 0.0.0.0:* LISTEN 6715/node_exporter tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 801/java tcp 0 0 0.0.0.0:8060 0.0.0.0:* LISTEN 6709/nginx: master tcp 0 0 127.0.0.1:9121 0.0.0.0:* LISTEN 6765/redis_exporter tcp 0 0 127.0.0.1:9090 0.0.0.0:* LISTEN 6752/prometheus tcp 0 0 127.0.0.1:9187 0.0.0.0:* LISTEN 6720/postgres_expor tcp 0 0 0.0.0.0:8100 0.0.0.0:* LISTEN 6709/nginx: master tcp 0 0 127.0.0.1:8101 0.0.0.0:* LISTEN 7495/unicorn master tcp6 0 0 :::3306 :::* LISTEN 1370/mysqld 

杀掉8080端口即可,8080端口对应的pip是801

# kill -9 801

重启下服务,刷新页面就可以访问了

# gitlab-ctl restart

为了避免8080端口冲突问题,可以修改下unicorn的默认端口,vim打开/etc/gitlab/gitlab.rb配置文件

新增一项unicorn['port'] = 8101,修改后内容如下

## 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://47.104.x.x:8100' unicorn['port'] = 8101

修改完成后:wq保存退出,执行gitlab-ctl reconfigure命令,让配置生效,再重新启动服务

# gitlab-ctl reconfigure # gitlab-ctl stop # gitlab-ctl start

接着在浏览器访问就能看的gitlab登录首页了

gitlab配置查看

gitlab的配置主要是etc/gitlab/gitlab.rb下的两个地方

external_url 'http://47.104.x.x:8100' unicorn['port'] = 8101

查看更多配置信息可以,在/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml查看具体的详情

 gitlab: ## Web server settings (note: host is the FQDN, do not include http://)  host: 47.104.x.x  port: 8100  https: false

相关操作

启动服务:gitlab-ctl start
查看状态:gitlab-ctl status
停掉服务:gitlab-ctl stop
重启服务:gitlab-ctl restart
让配置生效:gitlab-ctl reconfigure


推荐阅读
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • HyperledgerComposer环境安装1.安装基本软件包**如果使用Linux安装HyperledgerComposer,请注意以下建议:以 ... [详细]
  • Centos7安装MySql5.6
    如何在CentO ... [详细]
  • 基于CentOS7的服务器环境搭建(LAMP环境)一、安装MySQL组件  1.由于在CentOS7中,默认yum安装库中不含有mysql,我们可以下载mysql的分支Mari ... [详细]
  • Docker从安装到入门到项目部署
    容器化的时代你怎么可 ... [详细]
  • Lunix历史及如何学习
    1.Lunix是什么1.1Lunix是操作系统还是应用程序Lunix是一套操作系统,它提供了一个完整的操作系统当中最底层的硬件控制与资源管理的完整架构, ... [详细]
  • 如何运行vue项目(github项目),Go语言社区,Golang程序员人脉社 ... [详细]
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • Linux如何安装Mongodb的详细步骤和注意事项
    本文介绍了Linux如何安装Mongodb的详细步骤和注意事项,同时介绍了Mongodb的特点和优势。Mongodb是一个开源的数据库,适用于各种规模的企业和各类应用程序。它具有灵活的数据模式和高性能的数据读写操作,能够提高企业的敏捷性和可扩展性。文章还提供了Mongodb的下载安装包地址。 ... [详细]
  • 解决github访问慢的问题的方法集锦
    本文总结了国内用户在访问github网站时可能遇到的加载慢的问题,并提供了解决方法,其中包括修改hosts文件来加速访问。 ... [详细]
  • 这里我们采用两台Nginx服务器作为前端,一主一从,Keepalived实现状态监测,保证Nginx正常对外提供服务,即主Nginx服务进程死掉之后,keepalived能够通过其自身的检测机制 ... [详细]
  • centos7+cdh5.10.0搭建
    一、选择环境:1.说明本次部署使用台机器,3台用于搭建CDH集群,1台为内部源。内部源机器是可以连接公网的,可以提前部署好内部源,本次部署涉及到的服务器的hosts配置如下:192.168 ... [详细]
  • 之前有一篇文章介绍过在ubuntu下安装selenium和firefox现在介绍下centos7注意以下都是下载的linux64位的软件,32位的请自己找下链接,现在使用的python的版 ... [详细]
  • 达梦8图形化安装部署安装准备远程工具:xshell环境准备:vmware14\centos7操作系统镜像安装软件:Linux版本的DM8安装包系统准备检查系统信息#获取系统位数ge ... [详细]
  • 1.在CentOSRHEL7中,有个叫hostnamectl的命令行工具,它允许你查看或修改与主机名相关的配置。$hostnamectlstatus[root@simon- ... [详细]
author-avatar
殇子休
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有