0%

Debian 安装 Gitlab CE

搭建 Gitlab CE,利用其issue、任务指派、@群组成员等功能,尝试替代 Tower 。
搭建环境:Debian

具体操作:

安装依赖以及 gitlab-ce

1
2
3
sudo apt -y install curl vim openssh-server ca-certificates perl
sudo apt-get install -y postfix
apt-get install gitlab-ce

运行 runsvdir-start

screen -R gitlab_runsvdir
/opt/gitlab/embedded/bin/runsvdir-start

修改配置文件

vim /etc/gitlab/gitlab.rb

假设域名是 test.a.com,修改以下配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
nginx['enable'] = false
external_url 'https://test.a.com'
gitlab_workhorse['enable'] = true
gitlab_workhorse['listen_network'] = "tcp"
gitlab_workhorse['listen_addr'] = "0.0.0.0:10080"
gitlab_workhorse['auth_backend'] = "http://localhost:8089"
gitlab_rails['gitlab_ssh_host'] = 'test.a.com'
puma['port'] = 8089 设置为8089,默认8080会与其他软件有冲突

# 优化内存占用
puma['worker_timeout'] = 30
puma['worker_processes'] = 2
postgresql['shared_buffers'] = "256MB"
sidekiq['max_concurrency'] = 8
postgresql['max_worker_processes'] = 4
puma['per_worker_max_memory_mb'] = 600
prometheus_monitoring['enable'] = false
sidekiq['min_concurrency'] = 8

vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

1
2
3
4
5
gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: test.a.com
port: 443
https: true

重载配置文件

1
2
gitlab-ctl restart
gitlab-ctl reconfigure

curl localhost:10080 得到响应:

1
<html><body>You are being <a href="http://localhost:10080/users/sign_in">redirected</a>.</body></html>

配置反向代理

在域名 test.a.com 的 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
#PROXY-START/

location /
{
proxy_pass http://localhost:10080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Ssl on;
proxy_http_version 1.1;
# proxy_hide_header Upgrade;

add_header X-Cache $upstream_cache_status;
#Set Nginx Cache

set $static_file5qKTKBxE 0;
if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
{
set $static_file5qKTKBxE 1;
expires 1m;
}
if ( $static_file5qKTKBxE = 0 )
{
add_header Cache-Control no-cache;
}
}
#PROXY-END/

如果用的BT管理面板:

1
2
注意,要手动点配置文件,增加:
proxy_set_header X-Forwarded-Ssl on;

浏览器访问 test.a.com ,得到gitlab登录界面。

设置密码

1
2
3
4
5
6
7
8
gitlab-rails console

进入 gitlab-rails 的 console 后,分别执行:

user=User.where(id:1).first
user.password='Test123456'
user.password_confirmation='Test123456'
user.save

打开 test.a.com ,账号输入 root 密码输入 Test123456 ,登录成功。

设置SMTP

vim /etc/gitlab/gitlab.rb

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
# 启用 smtp 服务
gitlab_rails['smtp_enable'] = true

# 配置 smtp 服务地址,这里需要填写邮件服务里面的“SMTP服务器地址”(如下是网易163邮箱的smtp服务器地址)
gitlab_rails['smtp_address'] = "smtp.163.com"

# 配置 smtp 服务的端口号(默认)
gitlab_rails['smtp_port'] = 465

# 配置发送邮件的电子邮箱名称(即刚才注册的邮箱名称)
gitlab_rails['smtp_user_name'] = "[email protected]"

# 配置发送邮件的电子邮箱授权密码,刚才在邮箱里面开启 SMTP 服务的时候弹框提示的那一串【授权密码】(切记:这里不是邮箱的登录密码,是SMTP的授权密码)
gitlab_rails['smtp_password'] = "xxAxxSxxDx"

# 配置 SMTP 服务的域名,和上面的smtp服务器地址一致(如下是网易163邮箱的smtp域名)
gitlab_rails['smtp_domain'] = "smtp.163.com"

# 配置 SMTP 鉴定类别(默认 login 即可)
gitlab_rails['smtp_authentication'] = "login"

# 开启纯文本通信协议扩展
gitlab_rails['smtp_enable_starttls_auto'] = true

# 开启 smtp_tls (传输安全)
gitlab_rails['smtp_tls'] = true

# gitlab 服务邮件发送来源邮箱(即发出邮件的发送方邮箱),填写刚才注册的邮箱即可
gitlab_rails['gitlab_email_from'] = '[email protected]'

gitlab-ctl reconfigure
gitlab-ctl restart

测试发邮件

1
2
3
4
5
6
7
8
9
gitlab-rails console


Notify.test_email('[email protected]', 'test title', 'test body').deliver_now

若返回:
/opt/gitlab/embedded/lib/ruby/gems/3.0.0/gems/net-protocol-0.1.3/lib/net/protocol.rb:46:in `connect_nonblock': SSL_connect returned=1 errno=0 state=error: wrong version number (OpenSSL::SSL::SSLError)

则将 /etc/gitlab/gitlab.rb 的 gitlab_rails['smtp_tls'] 值设置为 false

设置自定义Logo和名称

1
https://your domain.com/admin/application_settings/appearance

参考

https://www.cnblogs.com/devilyouwei/p/13157556.html

欢迎关注我的其它发布渠道