ubuntu18搭建Gitlab服务

本文详述了在Ubuntu18上搭建Gitlab服务的全过程,包括安装、配置镜像路径、添加SSH密钥、解决各种错误、gitlab命令、开机启动、卸载、备份恢复、升级等关键步骤,以及遇到问题的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装

参考:https://docs.gitlab.com/omnibus/settings/configuration.html
官方:https://about.gitlab.com/install/#ubuntu

sudo apt-get install -y curl openssh-server ca-certificates
sudo apt-get install -y postfix  #选择 Internet Site
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

sudo systemctl enable postfix
sudo systemctl start postfix

sudo apt-get install gitlab-ce #安装可用最新版本
#sudo apt-get install gitlab-ce=11.7.5-ce.0  #指定版本号
#由于版本太低,需要指定源进行下载
#sudo apt-get install gitlab-ce=12.9.2-ce.0 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/bionic/main/g/gitlab-ce/

#指定清华源 apt install gitlab-ce方法
sudo vim /etc/apt/sources.list.d/gitlab-ce.list #写入如下内容
deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu bionic main
#首先信任 GitLab 的 GPG 公钥:
curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null
sudo apt update
sudo apt list gitlab-ce -a #查看所有的gilab-ce版本
sudo apt-get install gitlab-ce=12.9.2-ce.0 #指定版本安装


sudo vim /etc/gitlab/gitlab.rb
#配置external_url 通常是本机局域网ip的形式,例如:external_url 'http://192.168.1.106:80'
#设置git-data存储位置
#git_data_dirs({ "default" => { "path" => "/mnt/gitlab/git-data" } })   #添加指定存储位置

sudo gitlab-ctl reconfigure

sudo gitlab-ctl stop
#If you already have existing Git repositories in /var/opt/gitlab/git-data you can move them to the new location as follows:
sudo rsync -av /var/opt/gitlab/git-data/repositories /mnt/nas/git-data/   #同步文件内容

sudo gitlab-ctl upgrade
sudo gitlab-ctl start
#设置下次开机自启动gitlab服务
sudo systemctl enable gitlab-runsvdir.service
sudo systemctl start gitlab-runsvdir.service

错误STDERR: sysctl: cannot open “/etc/sysctl.d/90-omnibus-gitlab-kernel.sem.conf”:
参考:https://www.jianshu.com/p/134c1107114a

错误1:
resql/.s.PGSQL.5432"? [execute] psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/opt/gitlab/postgresql

一般是文件权限问题,只要修改/var/opt/gitlab/postgresql权限

sudo chmod 755 /var/opt/gitlab/postgresql
sudo gitlab-ctl reconfigure

错误2:
storage_directory[/var/opt/gitlab/.ssh](gitlab::gitlab-shell line 38)had an error:Mixlib::shellout::shellcommandfailed:
ruby_block[directory resource: xxx_path]

一般是文件权限问题,只要修改xxx_path权限使git用户有读写权限即可

sudo chown git:root xxx_path

错误4
Gitlab更新后gitlab-ctl reconfigure报错rails_migration[gitlab-rails] (gitlab::database_migrations line 51) had an error
方法: https://yangyq.net/2022/05/gitlab-update-error.html

解决方法:

#重起系统
sudo gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,push_event_payloads,event_id,'[["event_id"]\, ["event_id_convert_to_bigint"]]']
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
<think>好的,我需要帮用户解决在Ubuntu安装和配置GitLab服务器的问题。首先,我要回忆一下相关的步骤和注意事项,确保信息的准确性。用户可能对Linux系统管理有一定的了解,但作为指导,步骤需要详细且清晰。 首先,安装前的准备。用户需要Ubuntu系统,可能不知道需要先更新系统和安装依赖包。常见的依赖如curl、openssh-server、ca-certificates等是必须的,可能需要提到用apt命令安装这些。另外,防火墙设置也是重要的,特别是开放HTTP/HTTPS和SSH端口,这部分需要指导用户如何配置ufw。 接下来是安装GitLab。用户可能不知道官方仓库的添加方法,需要说明用curl下载脚本并执行。之后使用apt安装gitlab-ce。这里需要强调使用社区版(ce),因为企业版需要许可证。 然后是配置部分。编辑/etc/gitlab/gitlab.conf文件,设置external_url,可能涉及域名或IP地址。用户可能会困惑这个配置的具体作用,需要简单说明这是GitLab访问的地址。配置完成后,必须运行gitlab-ctl reconfigure来应用更改,这个步骤很关键,容易遗漏。 初始化设置方面,用户首次访问需要设置管理员密码,这一步需要提醒用户记住密码。另外,创建项目、用户管理、备份策略等都是后续使用中的重要环节,应该简要提及,帮助用户全面了解。 最后,生成相关问题。需要根据安装配置的步骤,考虑用户可能遇到的后续问题,比如HTTPS配置、性能优化、备份恢复等,列出相关的问题引导用户进一步学习。 需要检查是否有遗漏的步骤,比如依赖包是否全面,防火墙规则是否正确,配置文件的路径是否准确。同时,确保所有命令正确无误,避免用户执行时出错。引用之前提供的参考信息,但要根据实际情况调整,确保步骤适用于最新的Ubuntu版本,比如20.04或22.04,而不仅仅是16.04。此外,提醒用户定期更新系统和GitLab,以保持安全性和稳定性。</think>以下是Ubuntu系统安装配置GitLab服务器的完整指南: ### 一、安装前准备 1. 更新系统软件包 ```bash sudo apt update && sudo apt upgrade -y ``` 2. 安装必要依赖 ```bash sudo apt install -y curl openssh-server ca-certificates postfix ``` 3. 配置防火墙(如使用UFW) ```bash sudo ufw allow http sudo ufw allow https sudo ufw allow ssh sudo ufw enable ``` ### 二、安装GitLab 1. 添加官方仓库 ```bash curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash ``` 2. 安装社区版 ```bash sudo apt install gitlab-ce ``` ### 三、配置GitLab 1. 编辑配置文件 ```bash sudo nano /etc/gitlab/gitlab.rb ``` 修改以下参数: ```ruby external_url 'http://your_domain_or_ip' ``` 2. 应用配置 ```bash sudo gitlab-ctl reconfigure ``` 3. 检查服务状态 ```bash sudo gitlab-ctl status ``` ### 四、初始化设置 1. 访问Web界面 浏览器打开配置的external_url地址,首次访问需设置root账户密码 2. 建议操作: - 创建普通用户账户 - 配置SMTP邮件服务 - 设置项目存储路径 - 配置自动备份 ```bash sudo gitlab-rake gitlab:backup:create ``` ### 五、维护命令 | 功能 | 命令 | |------|------| | 启动服务 | `sudo gitlab-ctl start` | | 停止服务 | `sudo gitlab-ctl stop` | | 重启服务 | `sudo gitlab-ctl restart` | | 查看日志 | `sudo gitlab-ctl tail` |
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿尔发go

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值