5分钟安装GitLab,搭建属于自己的代码仓库托管平台。
环境
系统版本:Ubuntu 22.04.3 LTS
一、安装
1、对于Debian/Ubuntu
# 添加GitLab的APT仓库
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
# 安装GitLab
sudo apt install gitlab-ce
2、对于RHEL/CentOS
# 添加GitLab的YUM仓库
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
# 安装GitLab
sudo yum install gitlab-ce
二、配置、启动
1、编辑配置文件
vim /etc/gitlab/gitlab.rb
2、配置参数
在external_url配置访问IP和端口
【注意!!】端口不能为8080,否则会和默认的unicorn[‘port’] = 8080冲突
(这玩意坑了我一个小时,端口冲突导致gitlab一直起不来)
# 修改配置
external_url 'http://your_domain_or_IP'
# 例如
external_url 'http://192.168.10.112:8081'
3、应用配置,并启动gitlab
#重启
gitlab-ctl reconfigure
4、浏览器访问
http://192.168.10.112:8081
三、创建用户
1、登录到gitlab,创建一个账户
http://192.168.10.112:8081
或使用控制台创建账户
# 进入控制台
gitlab-rails console
# 创建账户
user = User.create(
username: 'Master_Owen',
name: 'xxx',
email: 'xxx@qq.com',
password: 'xxxx',
password_confirmation: 'xxxx',
admin: true
)
user.save!
2、进入控制台,分配为管理员、并启用账户
gitlab-rails console
user = User.find_by(username: 'Master_Owen')
user.admin = true
user.state = 'active'
user.save!
四、正常登录
之后就可以访问到GitLab,并通过注册的账号登录了。