Gitlab 搭建
为什么?
想要自己搭建一个代码仓库无非是以下几点原因:
- 公司内部项目
- 自己的项目,但不适合在公网
- 大部分的
git
仓库虽然有私有服务,但价格都不便宜,甚至不如一台云服务器来的便宜
配置及安装文档 Gitlab
- 由于
gitlab
会用到22
端口端口转发的化就走不了git clone
的默认配置,且占用内存较高,不推荐使用docker
进行部署; - 由于
gitlab
自带nginx
默认情况下会与属主机的nginx
冲突,因此推荐只使用gitlab
自带的nginx
进行端口转发;
最小化配置
# path /etc/gitlab/gitlab.rb
external_url 'http://git.demo.com'
# SMTP
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = 'smtp.163.com'
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = 'xxxx@163.com'
gitlab_rails['smtp_password'] = 'xxxx'
gitlab_rails['smtp_authentication'] = 'login'
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxx@163.com'
gitlab_rails['smtp_domain'] = 'smtp.163.com'
gitlab_rails['gitlab_email_from'] = 'xxxx@163.com'
gitlab_rails['gitlab_email_display_name'] = 'xxxx'
gitlab_rails['gitlab_email_reply_to'] = 'xxxx@163.com'
# NGINX
nginx['client_max_body_size'] = '250m'
# 添加自己的 NGINX 代理
nginx['custom_nginx_config'] = 'include /etc/nginx/conf.d/*.conf;'
# PGSQL
postgresql['shared_buffers'] = '128MB'
# Terraform
gitlab_rails['terraform_state_enabled'] = false
# Usage Statistics
gitlab_rails['usage_ping_enabled'] = false
gitlab_rails['sentry_enabled'] = false
grafana['reporting_enabled'] = false
# 关闭容器仓库功能
gitlab_rails['gitlab_default_projects_features_container_registry'] = false
gitlab_rails['registry_enabled'] = false
registry['enable'] = false
registry_nginx['enable'] = false
# 包仓库
gitlab_rails['packages_enabled'] = false
gitlab_rails['dependency_proxy_enabled'] = false
# GitLab KAS
gitlab_kas['enable'] = false
gitlab_rails['gitlab_kas_enabled'] = false
# Mattermost
mattermost['enable'] = false
mattermost_nginx['enable'] = false
# Kerberos
gitlab_rails['kerberos_enabled'] = false
sentinel['enable'] = false
# GitLab Pages
gitlab_pages['enable'] = false
pages_nginx['enable'] = false
# 禁用 PUMA 集群模式
puma['worker_processes'] = 1
puma['min_threads'] = 1
puma['max_threads'] = 2
puma['per_worker_max_memory_mb'] = 256
# 降低后台守护进程并发数
sidekiq['concurrency'] = 8
# 关闭监控
prometheus_monitoring['enable'] = false
alertmanager['enable'] = false
node_exporter['enable'] = false
redis_exporter['enable'] = false
postgres_exporter['enable'] = false
pgbouncer_exporter['enable'] = false
gitlab_exporter['enable'] = false
grafana['enable'] = false
sidekiq['metrics_enabled'] = false
gitlab_rails['env'] = {
'MALLOC_CONF' => 'dirty_decay_ms:1000,muzzy_decay_ms:1000'
}
gitaly['env'] = {
'MALLOC_CONF' => 'dirty_decay_ms:1000,muzzy_decay_ms:1000',
'GITALY_COMMAND_SPAWN_MAX_PARALLEL' => '2'
}
gitlab.rb
安装 gitlab
后,启动完成后,修改 admin
页面上的设置可能 500
,其原因是有些密钥需要重置,原因可能是首次启动未启动完全导致(博主的机子性能不够,导致安装后用默认配置启动出现卡死的情况),使用以下代码尝试修复
# 检查密钥
gitlab-rake gitlab:doctor:secrets
# 根据检查结果 可能需要执行以下内容
# 1 进入 dbconsole 更新密钥,可能要执行很久,耐心等待
gitlab-rails dbconsole
UPDATE application_settings SET runners_registration_token_encrypted = null;
UPDATE application_settings SET runners_registration_token_encrypted = null;
UPDATE application_settings SET encrypted_ci_jwt_signing_key = null;