GitLab是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的Web服务。
一、基础
GitLab是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的Web服务。Gitlab是被广泛使用的基于git的开源代码管理平台, 基于Ruby on Rails构建, 主要针对软件开发过程中产生的代码和文档进行管理, Gitlab主要针对group和project两个维度进行代码和文档管理, 其中group是群组, project是工程项目, 一个group可以管理多个project, 可以理解为一个群组中有多项软件开发任务, 而一个project中可能包含多个branch, 意为每个项目中有多个分支, 分支间相互独立, 不同分支可以进行归并。
二、使用
- 安装(Alibaba Cloud Linux)
- 输入手机号、公司名、验证码
- yum update
- 安装依赖
1 | sudo yum install -y curl policycoreutils-python openssh-server perl |
- Postfix,可选
1 | sudo yum install postfix |
安装GitLab
- curl -L get.gitlab.cn | bash
- Successfully added gitlab-jh repo. To install JiHu GitLab, run “sudo yum/dnf install gitlab-jh”.
- 添加一个A解析,指向GitLab所部署的服务器
- sudo EXTERNAL_URL=”https://your_domain" yum install -y gitlab-jh
- 自定义root密码:sudo GITLAB_ROOT_PASSWORD=”
“ EXTERNAL_URL=”https://your_domain" apt install gitlab-jh
- 自定义root密码:sudo GITLAB_ROOT_PASSWORD=”
- 访问:https://your_domain/users/sign_in,失败
- gitlab-ctl tail,80端口被占用
- vim /var/opt/gitlab/nginx/conf/gitlab-http.conf,更换为81
- 重启服务gitlab-ctl restart
- 如果修改:/etc/gitlab/gitlab.rb,则需要重新加载配置:gitlab-ctl reconfigure
- curl -L get.gitlab.cn | bash
修改密码
在后台修改(已知密码)
在命令行修改(忘记密码)
sudo -u git -H bundle exec rails console
sudo: bundle: command not found
- yum install ruby-devel
- bundle -v
- echo ‘export PATH=”$HOME/.gem/ruby/
/bin:$PATH”‘ >> ~/.bashrc - source ~/.bashrc
Could not locate Gemfile or .bundle/ directory
cd
ls -a
vim Gemfile
1
2source 'https://rubygems.org'
gem 'rails'bundle install
开始使用
- 设置语言为中文
- 创建群组
- 创建项目
- 本地推送
- git remote add origin http://your_domain/your_group/your_project.git
- git remote remove origin
- git remote rm origin
- git remote set-url origin 新仓库的URL
- git branch -M main
- git push -uf origin main
- git config –unset https.proxy
- git config –unset http.proxy
- git config –global –unset https.proxy
- git config –global –unset http.proxy
- git config http.proxy 代理地址:端口号
- git config https.proxy 代理地址:端口号
- git config –global http.proxy 代理地址:端口号
- git config –global https.proxy 代理地址:端口号
- remote: GitLab: You are not allowed to force push code to a protected branch on this project.
- 设置->仓库->受保护分支->取消保护,等推送完在添加保护分支
- git checkout master
- git push -uf origin master
- git remote add origin http://your_domain/your_group/your_project.git
- 注册
- 管理员批准
- 项目邀请
常用命令
- gitlab-ctl start
- gitlab-ctl stop
- gitlab-ctl restart
- gitlab-ctl status
- gitlab-ctl reconfigure
- vi /etc/gitlab/gitlab.rb
- gitlab-ctl tail
卸载GitLab,参考
删除repo: /etc/yum.repos.d && rm gitlab-jh.repo
- 适用于内存太小安装报错的情况
gitlab-ctl stop
rpm -e gitlab-ce
- 报错:error: package gitlab-ce is not installed
- rpm -e gitlab-jh或yum remove gitlab-jh.x86_64,通过tab补全可以看到具体安装的什么版本
ps aux | grep gitlab,杀掉第一个进程(runsvdir -P /opt/gitlab/service log)
- kill -9 pid
find / -name gitlab | xargs rm -rf,主要是下面的几个目录:
1
2
3
4
5
6rm -rf /etc/gitlab
rm -rf /opt/gitlab
rm -rf /log/gitlab
rm -rf /var/opt/gitlab
rm -rf /var/log/gitlab
rm -rf /run/gitlab
三、问题
- sudo yum install -y curl policycoreutils-python openssh-server perl
1 | Last metadata expiration check: 11:51:19 ago on Sat 26 Apr 2025 10:34:38 PM CST. |
- yum update
- yum search policycoreutils-python
- sudo yum install -y curl policycoreutils-python-utils openssh-server perl
- sudo firewall-cmd –permanent –add-service=http
1 | FirewallD is not running |
- systemctl start firewalld
- systemctl start nginx.service启动失败,提示80端口被占用
- sudo ss -tulnp | grep :80
- sudo netstat -tulnp | grep :80
- sudo systemctl status httpd
- sudo systemctl stop httpd
- 修改httpd端口号为8080,重启服务
- 重启失败,直接重启ECS实例
- yum install lsof,cpu和内存飙升
- yum clean all
- yum makecache
- curl -L get.gitlab.cn | bash,非常慢
- curl -L -v get.gitlab.cn | bash
- 报错:main: line 52: 2086 Killed sudo yum -q makecache -y –disablerepo=’*’ –enablerepo=’gitlab-jh’
- 内存不够或程序本身出错
- 80端口被占用