一.GitLab是什么
GitLab 是一个用于仓库管理系统的开源项目。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
可通过Web界面进行访问公开的或者私人项目。它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,随着git的流行,越来越多的技术团队通过在自己的服务器搭建gitlab来实现代码的管理。
安装流程:
-
卸载本机gitliab以及相关文件
-
安装相关依赖
-
启动postfix,并设置为开机启动
-
防火墙设置
-
获取安装包
-
安装rpm包
-
修改配置文件gitlab.rb
-
加载配置文件并启动
-
访问gitlab
-
更改密码
-
gitlab创建一个项目
-
导入客户端公钥
-
查找客户端公钥
-
将客户端公钥添加进gitlab
-
提交本地项目到gitlab
-
报错处理
-
查看gitlab日志修正报错
卸载本机gitliab以及相关文件
sudo gitlab-ctl uninstall
sudo rpm -e gitlab-ce
find / -name gitlab|xargs rm -rf
安装相关依赖
yum install curl openssh-server openssh-clients postfix cronie policycoreutils-python –y
启动postfix,并设置为开机启动
systemctl start postfix
systemctl enable postfix
防火墙设置
#此命令需在防火墙开启后使用
firewall-cmd --add-service=http --permanent
firewall-cmd --reload
获取安装包
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-8.6.7-ce.0.el7.x86_64.rpm
安装rpm包
rpm -ivh gitlab-ce-8.6.7-ce.0.el7.x86_64.rpm
修改配置文件gitlab.rb
vim /etc/gitlab/gitlab.rb
查找到
external_url 这个属性,将其改为ip+地址
加载配置文件并启动
gitlab-ctl reconfigure
gitlab-ctl restart
访问gitlab
更改密码
首次进入会提示更改密码,在界面直接操作即可,也可以使用命令行操作。
root命令下
[root@svr34 bin]# gitlab-rails console production
Loading production environment (Rails 4.2.5.2)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id: 1, email: "admin@example.com", ...
irb(main):002:0> user.password=12345678
=> 12345678
irb(main):003:0> user.password_confirmation=12345678
=> 12345678
irb(main):004:0> user.save!
=> true
irb(main):005:0> quit
即获取用户名和重置密码。
gitlab创建一个项目
创建了一个jpa_test项目
导入客户端公钥
点击项目上方的add an SSH key
超链,即可进入导入客户端秘钥界面
查找客户端公钥
公钥存在地址路径为 ~/.ssh
查看公钥
-
cat ~/.ssh/id_rsa.pub
将客户端公钥添加进gitlab
提交本地项目到gitlab
cd existing_folder
git init
git remote add origin git@47.104.225.224:root/jpa_test.git
git add .
git commit -m 'first commit'
git push -u origin master
如遇报错
如果遇到clone和push都ok了,发现提交后的文件在线无法查看,页面显示500错
查看gitlab日志查看错误并修正
这是一台阿里云的新机器,内容为2G,已经满足gitlab最小内存1G的需求,通过free -h命令发现Swap为0
于是根据网上资料通过增加swap来看看效果
修改后在线查看文件正常
至此gitlab搭建完美结束!
https://mp.weixin.qq.com/s/LynXXhAzFCjBwT_PBuSiJw