极客教程:云服务器搭建一个GitLab仓库
发布时间:2019-05-10 10:53:00 来源: 互盟云
新购了一台服务器,顺便带大家了解一下如何在自己服务器上搭建一个GitLab仓库,来实现代码的托管和管理,服务器配置CPU:2核,内存:8GB,操作系统:CentOS7.464位,带宽:1Mbps为例。
1.GitLab是什么
GitLab是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的Web服务,可通过Web界面进行访问公开的或者私人项目。它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。
2.GitLab服务器搭建步骤
2.1远程登录服务器
我这里用的是mac,所以这里我用的终端iTerm登录远程服务器,关于iTerm可以看文章-mac如何使用iTerm2+sshpass便捷登录远程服务器
Welcome
to
Alibaba
Cloud
Elastic
Compute
Service
!
-
bash
:
warning
:
setlocale
:
LC_CTYPE
:
cannotchangelocale
(
UTF
-
8
):
No
suchfile
or
directory
manpath
:
can
'tsetthelocale;makesure$LC_*and$LANGarecorrect
[root@izwz9g9rz7v30c7l7z7ft2z~]#
2.2postfix服务设置
安装postfix以发送通知邮件,安装命令:sudoyuminstallpostfix。
[
root@izwz9g9rz7v30c7l7z7ft2z
~]#
sudoyuminstallpostfix
Failed
to
set
locale
,
defaultingtoC
Loaded
plugins
:
fastestmirror
Loading
mirrorspeeds
from
cachedhostfile
base
|
3.6
kB
00
:
00
epel
|
4.7
kB
00
:
00
extras
|
3.4
kB
00
:
00
mysql
-
connectors
-
community
|
2.5
kB
00
:
00
mysql
-
tools
-
community
|
2.5
kB
00
:
00
mysql80
-
community
|
2.5
kB
00
:
00
updates
|
3.4
kB
00
:
00
(
1
/
3
):
epel
/
x86_64
/
updateinfo
|
988
kB
00
:
00
(
2
/
3
):
updates
/
7
/
x86_64
/
primary_db
|
3.4
MB
00
:
00
(
3
/
3
):
epel
/
x86_64
/
primary_db
|
6.7
MB
00
:
00
Package
2
:
postfix
-
2.10
.
1
-
7.el7.x86
_64alreadyinstalled
and
latestversion
Nothing
to
do
2.3设置postfix开机自启
a.将postfix服务设置成开机自启动。
安装命令:sudosystemctlenablepostfix。
b.启动postfix。
安装命令:sudosystemctlstartpostfix。
Job
for
postfix
.
servicefailedbecausethecontrolprocessexited
with
errorcode
.
See
"systemctlstatuspostfix.service"
and
"journalctl-xe"
for
details
.
如上出现了错误:
Jobforpostfix.servicefailed.See'systemctlstatuspostfix.service'and'journalctl-xn'fordeta。
然后执行vi/etc/hosts,注释掉下面这一行。
::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6
127.0
.
0.1
localhostlocalhost
.
localdomainlocalhost4localhost4
.
localdomain4
#::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6
再次执行命令:sudosystemctlstartpostfix,成功!
2.4添加GitLab镜像
添加GitLab镜像源并安装gitlab服务器。
执行命令:
wgethttps://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
[
root@izwz9g9rz7v30c7l7z7ft2z
~]#
wgethttps
:
//mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
--
2019
-
04
-
19
10
:
58
:
04
--
https
:
//mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
Resolving
mirrors
.
tuna
.
tsinghua
.
edu
.
cn
(
mirrors
.
tuna
.
tsinghua
.
edu
.
cn
)...
101.6
.
8.193
,
2402
:
f000
:
1
:
408
:
8100
::
1
Connecting
tomirrors
.
tuna
.
tsinghua
.
edu
.
cn
(
mirrors
.
tuna
.
tsinghua
.
edu
.
cn
)|
101.6
.
8.193
|:
443.
..
connected
.
HTTPrequestsent
,
awaitingresponse
...
200
OK
Length
:
359519811
(
343M
)
[
application
/
x
-
redhat
-
package
-
manager
]
Saving
to
:
'gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm'
100
%[======================================>]
359
,
519
,
811
12.5MB
/
s
in
29s
2019
-
04
-
19
10
:
58
:
33
(
11.9
MB
/
s
)
-
'gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm'
saved
[
359519811
/
359519811
]
2.5安装GitLab命令
安装命令:rpm-igitlab-ce-10.0.0-ce.0.el7.x86_64.rpm,出现错误:依赖检测失败。
[
root@izwz9g9rz7v30c7l7z7ft2z
~]#
rpm
-
igitlab
-
ce
-
10.0
.
0
-
ce
.
0.el7.x86
_64
.
rpm
warning
:
gitlab
-
ce
-
10.0
.
0
-
ce
.
0.el7.x86
_64
.
rpm
:
Header
V4RSA
/
SHA1
Signature
,
keyIDf27eab47
:
NOKEY
error
:
Failed
dependencies
:
policycoreutils
-
python
is
needed
by
gitlab
-
ce
-
10.0
.
0
-
ce
.
0.el7.x86
_64
然后执行命令:
yuminstallpolicycoreutils-python执行成功后,若出现以下图中的信息则表示安装成功!
Installed
:
policycoreutils
-
python
.
x86_64
0
:
2.5
-
29.el7_6.1
Dependency
Installed
:
audit
-
libs
-
python
.
x86_64
0
:
2.8
.
4
-
4.el7
checkpolicy
.
x86_64
0
:
2.5
-
8.el7
libcgroup
.
x86_64
0
:
0.41
-
20.el7
libsemanage
-
python
.
x86_64
0
:
2.5
-
14.el7
python
-
IPy
.
noarch
0
:
0.75
-
6.el7
setools
-
libs
.
x86_64
0
:
3.3
.
8
-
4.el7
Complete
!
最后再次执行命令:rpm-igitlab-ce-10.0.0-ce.0.el7.x86_64.rpm,如果出现下图,则说明安装成功!
[
root@izwz9g9rz7v30c7l7z7ft2z
~]#
rpm
-
igitlab
-
ce
-
10.0
.
0
-
ce
.
0.el7.x86
_64
.
rpm
warning
:
gitlab
-
ce
-
10.0
.
0
-
ce
.
0.el7.x86
_64
.
rpm
:
Header
V4RSA
/
SHA1
Signature
,
keyIDf27eab47
:
NOKEY
It
lookslike
GitLab
has
not
beenconfiguredyet
;
skippingtheupgradescript
.
*.
*.
***
***
*****
*****
.******
*******
********
********
,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
,,,,,,,,,*****,,,,,,,,,.
,,,,,,,****,,,,,,
.,,,***,,,,
,*,.
_____________
/
____
(
_
)
/
_
//
_____
/
/
_
//
__
/
/
__
//
/
__\`
/
__\
//
_
/
//
/
_
//
___
/
/
_
//
/
_
/
/
\____
/
_
/
\__
/
_____
/
\__
,
_
/
_
.
___
/
Thank
you
for
installing
GitLab
!
GitLab
wasunabletodetectavalidhostname
for
yourinstance
.
Please
configureaURL
for
your
GitLab
instance
by
setting
`external_url`
configuration
in
/
etc
/
gitlab
/
gitlab
.
rbfile
.
Then
,
youcanstartyour
GitLab
instance
by
runningthefollowingcommand
:
sudogitlab
-
ctlreconfigure
For
acomprehensivelistofconfigurationoptionspleaseseethe
Omnibus
GitLab
readme
https
:
//gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
2.6修改gitlab配置
修改gitlab配置文件指定服务器ip:vim/etc/gitlab/gitlab.rb。
修改external_url'http://xxxx'(xxx:代表公网IP地址)
##GitLabconfigurationsettings
##!Thisfileisgeneratedduringinitialinstallationand**isnot**modified
##!duringupgrades.
##!Checkoutthelatestversionofthisfiletoknowaboutthedifferent
##!settingsthatcanbeconfiguredbythisfile,whichmaybefoundat:
##!https://gitlab.com/gitlab-org/omnibus-gitlab/raw/master/files/gitlab-config-template/gitlab.rb.template
##GitLabURL
##!URLonwhichGitLabwillbereachable.
##!Formoredetailsonconfiguringexternal_urlsee:
##!https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
external_url
'http://gitlab.example.com'
2.7执行配置启动GitLab
执行配置命令:gitlab-ctlreconfigure
Running
handlers
:
Running
handlerscomplete
Chef
Client
finished
,
360
/
515
resourcesupdated
in
01
minutes
36
seconds
gitlab
Reconfigured
!
重置并启动GitLab命令:gitlab-ctlrestart
[
root@izwz9g9rz7v30c7l7z7ft2z
~]#
gitlab
-
ctlrestart
ok
:
run
:
gitaly
:
(
pid
9410
)
1s
ok
:
run
:
gitlab
-
monitor
:
(
pid
9426
)
0s
ok
:
run
:
gitlab
-
workhorse
:
(
pid
9429
)
1s
ok
:
run
:
logrotate
:
(
pid
9474
)
0s
ok
:
run
:
nginx
:
(
pid
9479
)
0s
ok
:
run
:
node
-
exporter
:
(
pid
9486
)
1s
ok
:
run
:
postgres
-
exporter
:
(
pid
9495
)
0s
ok
:
run
:
postgresql
:
(
pid
9503
)
0s
ok
:
run
:
prometheus
:
(
pid
9513
)
1s
ok
:
run
:
redis
:
(
pid
9522
)
0s
ok
:
run
:
redis
-
exporter
:
(
pid
9527
)
1s
ok
:
run
:
sidekiq
:
(
pid
9535
)
0s
ok
:
run
:
unicorn
:
(
pid
9545
)
1s
2.8访问GitLab页面
浏览器地址栏直接输入公网ip地址,即可访问。
Repository是托管代码的入口,使用Wiki可以进行接口相关的一些说明,可以节省一些前后端的沟通成本。
3.nginx反向代理
如果你服务器上还有其他服务供用户访问,可采用nginx反向代理访问gitlab,具体可看文章:nginx反向代理gitlab
还有怎么上传代码配置,可以看文章GitLab使用总结(配置上传代码)
本文来源:
https://www.humengyun.com/news-view-748.html