0%

Gitlab安装与配置

Gitlab安装与配置

安装

安装配置依赖项

如想使用Postfix来发送邮件,在安装期间请选择’Internet Site’. 您也可以用sendmai或者 配置SMTP服务 并 使用SMTP发送邮件.

终端执行:

sudo apt-get install curl openssh-server ca-certificates postfix

添加Gitlab仓库并安装

1
2
curl -sS http://packages.gitlab.cc/install/gitlab-ce/script.deb.sh | sudo bash
sudo apt-get install gitlab-ce

另一种方式:可以下载deb包手动安装。

下载地址

选择合适的系统版本选择要安装的版本的包。

这里安装的是最新的版本8.15.4

找到对应的版本复制下载链接:

然后终端执行:下载包

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/trusty/main/g/gitlab-ce/gitlab-ce_8.15.4-ce.1_amd64.deb

然后执行:安装包

dkpg -i gitlab-ce_8.15.4-ce.1_amd64.deb

启动Gitlab

sudo gitlab-ctl reconfigure

浏览器访问

首次访问GitLab,系统会让你重新设置管理员的密码,设置成功后会返回登录界面.

默认的管理员账号是root,如果你想更改默认管理员账号,请输入上面设置的新密码登录系统后修改帐号名.

配置

配置文件地址:/etc/gitlab/gitlab.rb
修改external_url 'http://192.168.18.99'
这一项改为你的ip或者你的域名。改完后执行

sudo gitlab-ctl reconfigure
然后就可以访问。

这里使用的是gitlab中自带的nginx服务,如果使用已经安装的nginx服务器的话需要进行下面的配置。

nginx 增加虚拟主机配置

修改nginx的配置文件

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# gitlab socket 文件地址
upstream gitlab {
# 7.x 版本在此位置
# server unix:/var/opt/gitlab/gitlab-rails/tmp/sockets/gitlab.socket;
# 8.0 位置
server unix:/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket;
}

server {
listen *:80;
server_name gitlab.liaohuqiu.com; # 请修改为你的域名
server_tokens off; # don't show the version number, a security best practice
root /opt/gitlab/embedded/service/gitlab-rails/public;

# Increase this if you want to upload large attachments
# Or if you want to accept large git objects over http
client_max_body_size 250m;

# individual nginx logs for this gitlab vhost
access_log /var/log/gitlab/nginx/gitlab_access.log;
error_log /var/log/gitlab/nginx/gitlab_error.log;

location / {
# serve static files from defined root folder;.
# @gitlab is a named location for the upstream fallback, see below
try_files $uri $uri/index.html $uri.html @gitlab;
}

# if a file, which is not found in the root folder is requested,
# then the proxy pass the request to the upsteam (gitlab unicorn)
location @gitlab {
# If you use https make sure you disable gzip compression
# to be safe against BREACH attack
proxy_read_timeout 300; # Some requests take more than 30 seconds.
proxy_connect_timeout 300; # Some requests take more than 30 seconds.
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://gitlab;
}
# Enable gzip compression as per rails guide: http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
# WARNING: If you are using relative urls do remove the block below
# See config/application.rb under "Relative url support" for the list of
# other files that need to be changed for relative url support
location ~ ^/(assets)/ {
root /opt/gitlab/embedded/service/gitlab-rails/public;
# gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}

error_page 502 /502.html;
}

然后禁用gitlab自带的nginx

修改/etc/gitlab/gitlab.rb找到nginx['enable'] = false这一项设置为false。

然后重启nginx、重启gitlab。

server nginx restart

sudo gitlab-ctl reconfigure

然后就可以访问。

注意:在修改nginx的配置文件的时候可以选择监听其他端口。可以不是80端口。同样在gitlab的配置文件中也要做相应修改。访问的时候域名后面跟上监听的端口就可以。

参考文章:

gitlab中文网安装步骤

详细文档