GitLab服务器搭建教程

安装前准备

  • VMWare虚拟机
  • 版本推荐CentOS7(我当前使用的版本是CentOS7)
  • 配置好Linux的IP地址
  • 保证Gitlab可用运行内存大于4G(否则虚拟机会变得非常消耗磁盘读写)
  • 安装依赖软件
1
yum -y install policycoreutils openssh-server openssh-clients postfix

设置postfix开机自启,并启动,postfix支持gitlab发信功能

1
systemctl enable postfix && systemctl start postfix

安装GitLab

下载GitLab安装包

国内GitLab安装包地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/

  • /el6/ CentOS 6系统目录
  • /el7/ CentOS 7系统目录
  • /el8/ CentOS 8系统目录

我下载的是 11.3.3 版本,大家可以根据自己需求选择下载。

进入/usr/local/src/目录下载GitLab安装包

1
[root@localhost src]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.3.3-ce.0.el7.x86_64.rpm

安装GitLab安装包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[root@localhost src]# rpm -i gitlab-ce-11.3.3-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-11.3.3-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配置文件

  1. 修改GitLab配置文件指定服务器ip和自定义端口
1
vim /etc/gitlab/gitlab.rb

修改成如下(IP地址+端口号):

1
external_url 'http://192.168.100.14:8801'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
## GitLab configuration settings
##! This file is generated during initial installation and **is not** modified
##! during upgrades.
##! Check out the latest version of this file to know about the different
##! settings that can be configured by this file, which may be found at:
##! https://gitlab.com/gitlab-org/omnibus-gitlab/raw/master/files/gitlab-config-template/gitlab.rb.template


## 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://192.168.100.14:8801'

## Roles for multi-instance GitLab
##! The default is to have no roles enabled, which results in GitLab running as an all-in-one instance.
##! Options:
##! redis_sentinel_role redis_master_role redis_slave_role geo_primary_role geo_secondary_role
##! For more deatils on each role, see:
##! https://docs.gitlab.com/omnibus/roles/README.html#roles
##!
# roles ['redis_sentinel_role', 'redis_master_role']
  1. 重置并重启GitLab

重置

注:第一次预计需要几分钟

1
# gitlab-ctl reconfigure

居然用了11分钟…

1
2
3
4
Running handlers:
Running handlers complete
Chef Client finished, 435/620 resources updated in 11 minutes 31 seconds
gitlab Reconfigured!

重启

1
# gitlab-ctl restart

访问GitLab页面

如果没有开启8801端口,是无法访问滴

1
/sbin/iptables -I INPUT -p tcp --dport 8801 -j ACCEPT

浏览器输入 http://192.168.100.14:8801

如果访问的时候报502错误,修改权限

1
chmod -R 755 /var/log/gitlab

修改root密码

第一次访问时,会自动跳转到修改root密码的界面,填写好密码确认即可。愉快地开始管理你的项目吧!

坚持原创技术分享,您的支持将鼓励我继续创作!
0%