在CentOS系统上安装所需的依赖:
ssh,
防火墙,
postfix(用于邮件通知) ,
wget,
以下命令也会打开系统防火墙中的HTTP和SSH端口访问
使用命令
yum install -y curl policycoreutils-python openssh-server

内网centos 搭建GitLab centos7 gitlab搭建_git


内网centos 搭建GitLab centos7 gitlab搭建_centos_02


安装完成之后,需要启用和启动sshd服务,执行命令:

systemctl enable sshd

systemctl start sshd

内网centos 搭建GitLab centos7 gitlab搭建_linux_03


内网centos 搭建GitLab centos7 gitlab搭建_centos_04


打开 /etc/sysctl.conf 文件,在文件最后添加新的一行

输入如下文本:

net.ipv4.ip_forward = 1

这样,就配置好了防火墙。

作用为,当linux主机有多个网卡时,一个网卡收到的信息时可以传递给其他网卡,即数据可以进行转发

内网centos 搭建GitLab centos7 gitlab搭建_centos_05

systemctl enable firewalld

systemctl start firewalld

systemctl enable firewalld

内网centos 搭建GitLab centos7 gitlab搭建_gitlab_06

由于gitlab是需要使用postfix来作为邮件发送服务的,还需安装下以下服务。

直接命令安装,确认安装环节,输入【y】即可:

yum install postfix

内网centos 搭建GitLab centos7 gitlab搭建_centos_07


安装完成之后,打开/etc/postfix/main.cf 文件,找到inet_protocols = all,将 all 改为 ipv4。

内网centos 搭建GitLab centos7 gitlab搭建_linux_08

内网centos 搭建GitLab centos7 gitlab搭建_linux_09


然后,启动postfix,输入命令:

systemctl enable postfix

systemctl start postfix

内网centos 搭建GitLab centos7 gitlab搭建_git_10

安装gitlab
到了开始安装gitlab的时刻了
首先,先更改下镜像源地址(该镜像源的地址设置成了清华大学的,下载提速)
在/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

然后保存文件

内网centos 搭建GitLab centos7 gitlab搭建_git_11


保存好之后,需要重新生成环境,执行如下命令:

yum makecache

![](

内网centos 搭建GitLab centos7 gitlab搭建_linux_12


然后,我们就可以正式安装gitlab了,执行如下命令:

yum install -y gitlab-ce

内网centos 搭建GitLab centos7 gitlab搭建_git_13


内网centos 搭建GitLab centos7 gitlab搭建_centos_14


运行gitlab首先,我们需要配置一下GitLab的域名,非必须的,但建议配置一下,便于访问gitlab的时,方面记忆。

打开/etc/gitlab/gitlab.rb文件,找到external_url 这个选项,改成机器ip或者域名,如图:

内网centos 搭建GitLab centos7 gitlab搭建_gitlab_15


内网centos 搭建GitLab centos7 gitlab搭建_centos_16

接下来,初始化gitlab,

输入命令:

gitlab-ctl reconfigure

当出现如图的画面时,即为初始化配置完成

内网centos 搭建GitLab centos7 gitlab搭建_gitlab_17


用root账号登录,密码在这里查看,只保留24小时

内网centos 搭建GitLab centos7 gitlab搭建_内网centos 搭建GitLab_18

内网centos 搭建GitLab centos7 gitlab搭建_centos_19


启动gitlab

sudo gitlab-ctl start

内网centos 搭建GitLab centos7 gitlab搭建_gitlab_20


启动后,发现页面无法访问

输入命令systemctl status firewalld发现防火墙在运行着

内网centos 搭建GitLab centos7 gitlab搭建_centos_21

输入命令service firewalld stop关闭防火墙即可成功访问,访问名称就是http://你设置的ip(不需要加端口)

内网centos 搭建GitLab centos7 gitlab搭建_linux_22


内网centos 搭建GitLab centos7 gitlab搭建_gitlab_23

先修改完密码(要不设置语言不生效)

内网centos 搭建GitLab centos7 gitlab搭建_内网centos 搭建GitLab_24


然后设置语言为中文

内网centos 搭建GitLab centos7 gitlab搭建_centos_25


退出登录后,重新登录语言即为中文

内网centos 搭建GitLab centos7 gitlab搭建_linux_26

常用命令总结:
初始化gitlab:sudo gitlab-ctl reconfigure
关闭gitlab:sudo gitlab-ctl stop
启动gitlab:
sudo gitlab-ctl start

#systemctl stop firewalld //关闭防火墙
#systemctl disable firewalld //禁用防火墙开机启动

//启动邮件服务,并开机加载
#systemctl start postfix
#systemctl enable postfix