Centos7 搭建Gitlab服务器并配置项目全过程

一、在Centos7上安装Gitlab

之前尝试过直接yum安装,但服务器从该yum源下载实在太慢,故手动下载rpm包安装。

1.先安装相关依赖

yum -y install policycoreutils openssh-server openssh-clients postfix

2.启动postfix,并设置开机自启动

目的:支持gitlab邮件发送 
systemctl enable postfix && systemctl start postfix

如果报错:Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.

修改 /etc/postfix/main.cf的设置 即可

inet_protocols = ipv4

inet_interfaces = all

3.下载并安装Gitlab社区版RPM包

我的下载路径如下:gitlab-ce-10.5.2-ce.0.el7.x86_64.rpm 
注意根据自己的linux系统选择合适的包 
再输入:rpm -ivh gitlab-ce-10.5.2-ce.0.el7.x86_64.rpm 安装完毕

如果报错:

warning: gitlab-ce-10.1.0-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
error: Failed dependencies:
        policycoreutils-python is needed by gitlab-ce-10.1.0-ce.0.el7.x86_64

安装gitlab依赖 后重新安装

yum install policycoreutils-python

4.修改Gitlab访问URL配置

cd /opt/gitlab/embedded/service/gitlab-rails/config  

修改gitlab.yml文件

[root@localhost config]# vim gitlab.yml  

gitLab:

   host:11.11.11.11

   port:80

5.重置并启动Gitlab

重置:gitlab-ctl reconfigure

注:第一次预计需要几分钟 
这里写图片描述

启动:gitlab-ctl restart 
这里写图片描述

6.浏览器访问Gitlab

直接通过域名端口访问:http://10.3.1.12:8082

我在此处出现问题: 
1.502错误 
这里写图片描述 
排查过程: 
首先保证Gitlab可用运行内存大于4G,端口未被占用 
再赋予权限:chmod -R 755 /var/log/gitlab 
再重置重启 
访问后仍然可能遇到502,不过我刷新2次就一切ok了。。

2.进去后会提醒你重新设置密码,此处报错 
用户名默认为root,密码自己设置 
这里写图片描述 
无论怎么样修改密码都报这个错 
然后我重置重启,结果ok了。。


二、在Gitlab里配置项目

先本地Git导入项目到Gitlab,再通过IDEA导入GItlab上的项目

1.配置Gitlab用户邮箱

User Settings - Emails 中添加邮箱并confirm

2.添加开发电脑的key到Gitlab上

先确保你的开发电脑上已安装Git,并做好基本准备,这个不再多说 
打开Git Bash生成key: 
在bash中输入ssh-keygen -t rsa -C “yourEmail@example.com” 即可,后面输入自己的邮箱 
再在 ~/.ssh/id_rsa.pub中复制其中所有内容,在User Settings - SSH Keys中添加复制内容 
这里写图片描述 
这里写图片描述

3.将开发电脑上已存在的项目导入到Gitlab上

先在Gitlab上创建一个空项目-test 
这里写图片描述

再打开本地Git Bash,配置全局的 user.name 和 user.email:

 
  1. git config --global user.name "root"

  2. git config --global user.email "yuanjie@397.com"

  • 1
  • 2

首先cd到你需要导入的项目目录下,再执行导入命令:

 
  1. git init

  2. git remote add origin git@10.3.1.12:root/test.git

  3. git add .

  4. git commit -m "测试-test"

  5. git push -u origin master

  • 1
  • 2
  • 3
  • 4
  • 5

至此,可以到浏览器刷新test项目,发现导入成功 
这里写图片描述

4.在IDEA上clone项目

根据图示依次操作即可: 
这里写图片描述 
这里写图片描述 
这里写图片描述


至此,Gitlab搭建及初步测试完成!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值