一、软件包下载
gitlab安装包下载链接
ubuntu:
ubuntu/focal 适用于 ubuntu20系列
ubuntu/bionic 适用于 ubuntu18 系列
Debian:
debian/buster 适用于 Debian10系列
debian/bullseye 适用于 Debian11、12系列
二、安装gitlab
ubuntu需要安装一些环境库
bash
sudo apt-get install -y curl openssh-server ca-certificates policycoreutils-python-utils
如果实现邮箱功能需要安装postfix
bash
sudo apt-get install -y postfix
bash
sudo apt install gitlab-ce_xxx.deb
三、环境配置
sudo vim /etc/gitlab/gitlab.rb
bash
##! Note: During installation/upgrades, the value of the environment variable
##! EXTERNAL_URL will be used to populate/replace this value.
##! On AWS EC2 instances, we also attempt to fetch the public hostname/IP
##! address from AWS. For more details, see:
##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
external_url 'http://ip:port' # 本机ip和访问端口号
### GitLab email server settings
###! Docs: https://docs.gitlab.com/omnibus/settings/smtp.html
###! **Use smtp instead of sendmail/postfix.**
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.server"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "smtp user"
gitlab_rails['smtp_password'] = "smtp password"
gitlab_rails['smtp_domain'] = "example.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_pool'] = true
配置并启动服务
bash
cd /opt/gitlab/bin
sudo gitlab-ctl reconfigure
相关命令
bash
sudo gitlab-ctl stop //--停止服务
sudo gitlab-ctl reconfigure //--启动服务
sudo gitlab-ctl restart //--重启所有gitlab组件
sudo gitlab-ctl start //--启动所有gitlab组件
bash
sudo systemctl enable gitlab-runsvdir.service
四、修改仓库保存路径
在path路径下创建git-data文件夹
bash
sudo gitlab-ctl stop
sudo vim /etc/gitlab/gitlab.rb
bash
git_data_dirs({
"default" => {
"path" => "/path/git-data"
}
})
bash
sudo chmod +x /path
sudo chmod +x /path/git-data
sudo gitlab-ctl reconfigure
sudo gitlab-ctl start
五、获取首次登录密码
bash
sudo vim /etc/gitlab/initial_root_password
其中Password: 后为登录密码
六、网页进入gitlab页面:
输入:http://ip:port
用户名:root
密码:为刚查找的密码
登录后,及时修改登录密码。
七、gitlab轻量化优化:
bash
# 关闭容器仓库功能
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 Pages
gitlab_pages['enable'] = false
pages_nginx['enable'] = false
# 关闭监控和性能基准相关功能
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
# Usage Statistics
gitlab_rails['usage_ping_enabled'] = false
gitlab_rails['sentry_enabled'] = false
grafana['reporting_enabled'] = false
# GitLab KAS
gitlab_kas['enable'] = false
gitlab_rails['gitlab_kas_enabled'] = false
# Terraform
gitlab_rails['terraform_state_enabled'] = false
# Kerberos 文档说EE only,但是默认值为 true
gitlab_rails['kerberos_enabled'] = false
# Sentinel
sentinel['enable'] = false
# Mattermost
mattermost['enable'] = false
mattermost_nginx['enable'] = false
# 关闭电子邮件相关功能
gitlab_rails['smtp_enable'] = false
gitlab_rails['gitlab_email_enabled'] = false
gitlab_rails['incoming_email_enabled'] = false
gitlab_ci['gitlab_ci_all_broken_builds'] = false
gitlab_ci['gitlab_ci_add_pusher'] = false
# 禁用 PUMA 集群模式(可选)
puma['worker_processes'] = 0
puma['min_threads'] = 1
puma['max_threads'] = 2
# 降低后台守护进程并发数
sidekiq['max_concurrency'] = 5