目前代码版本控制分为两种:集中式管理SVN和分布式管理Git,微软近期以75亿美元收购了Github平台,而GitLab也颇受企业喜爱,因为Github平台只能提供一个私有仓库,而Gitlab服务器可以企业自己搭建。下面就是简单Gitlab服务器的搭建过程。
服务器硬件配置介绍:
https://docs.gitlab.com.cn/ce/install/requirements.html
如果低于4GB+2vCPU请不要尝试,浪费时间。
就算你配置好了,启动了,clone和push代码时也会有各种问题,类似API不可读等。
Centos系统下官网安装步骤:https://about.gitlab.com/installation/#centos-6
docker镜像安装:https://hub.docker.com/r/gitlab/gitlab-ce/
清华开源软件镜像站wget下载安装ce版本:
yum -y install policycoreutils openssh-server openssh-clients postfix
yum install policycoreutils-python
systemctl enable postfix && systemctl start postfix
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.0.13-ce.0.el7.x86_64.rpm
rpm -i gitlab-ce-10.8.4-ce.0.el7.x86_64.rpm
如果安装postfix时出现了以下错误:parameter inet_interfaces: no local interface found for ::1
解决方案如下:
vi /etc/postfix/main.cf
修改配置
inet_interfaces = localhost
为
inet_interfaces = all
完成以上安装步骤在配置文件/etc/gitlab/gitlab.rb中添加:
external_url 'http://your IP:your port'
执行配置命令:
gitlab-ctl reconfigure
修改配置文件 修改:
vim ./gitlab/embedded/service/gitlab-shell/config.yml
gitlab_url: "http://IP:port"
启动Gitlab:
gitlab-ctl start
如果页面打开没有输入管理员密码的请删除数据保存目录重新安装,如果还是不行请换版本安装。
如果在创建库之后无法通过点击创建库文件按钮来创建,网页回复为没权限读则替换版本,这是8版本中的一个bug。
管理员账号为root
之后生成ssh秘钥并且将公钥复制到账号下的ssh管理区域,便于代码无秘下载和之后利用各服务器插件来沟通。
ssh-keygen -t rsa -C 'your email'
之后可以创建库和创建组管理的库,我们可以给组下的成员相关的权限级别,是Owner、Master、Developer、Reporter、Guest。测试ssh配置
ssh -T git@**.**.***.***
Welcome to GitLab, Administrator!
创建一个私有仓库之后,除了管理员,其他成员只能clone,不能push,这也为GerRit的git review提供了保证,在 Replication插件(GerRit中介绍)中可以使用管理员权限来同步仓库
如果在ssh添加公钥之后还是需要输入密码,这个时候可能是git用户被锁。
出错信息如下:
vim /var/log/secure:
Jun 17 22:32:22 jiche sshd[14931]: reprocess config line 50: Deprecated option RSAAuthentication
Jun 17 22:32:22 jiche sshd[14931]: User git not allowed because account is locked
Jun 17 22:32:22 jiche sshd[14931]: input_userauth_request: invalid user git [preauth]
Jun 17 22:32:24 jiche sshd[14931]: Connection closed by **.**.***.*** port 47170 [preauth]
原因:git用户没有设置密码
解除git用户被锁状态,以root权限执行后重启服务:
#passwd -u -f git
Unlocking password for user git.
passwd: Success