centos7 上搭建gitlab服务超详细

版权声明:未经允许,不得转载 https://blog.csdn.net/wanchaopeng/article/details/85121279

注意:内网防火墙关闭

一, 在centos7上安装gitlab

本文采用rpm包安装

1.安装相关依赖

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

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

systemctl enable postfix && systemctl start postfix

支持gitlab邮件发送

3.下载并安装gitlab社区版rpm包

下载路径为:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/xenial/main/g/gitlab-ce/

注意根据自己的linux系统选择合适的包再输入:rpm -ivh gitlab-ce-11.3.0-ce.0.el7.x86_64.rpm 安装完毕!

EL是Red Hat Enterprise Linux的简写 

- EL6软件包用于在Red Hat 6.x, CentOS 6.x, and CloudLinux 6.x进行安装 

- EL5软件包用于在Red Hat 5.x, CentOS 5.x, CloudLinux 5.x的安装
 
- EL7 软件包用于在Red Hat 7.x, CentOS 7.x, and CloudLinux 7.x的安装

yum安装

1, 配置yum源

vim /etc/yum.repos.d/gitlab-e.repo

添加以下内容

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

2.更新本地yum缓存

yum makecache

3.安装gitlab社区版

sudo yum install gitlab-ce
     
#自动安装最新版

sudo yum install gitlab-ce-x.x.x

#安装指定版本

4.gitlab常用命令

sudo gitlab-ctl start       # 启动所有 gitlab 组件

sudo gitlab-ctl stop        # 停止所有 gitlab 组件

sudo gitlab-ctl restart     # 重启所有 gitlab 组件

sudo gitlab-ctl status      # 查看服务状态

sudo gitlab-ctl reconfigure # 启动服务

sudo vim /etc/gitlab/gitlab.rb  # 修改默认的配置文件

gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab

sudo gitlab-ctl tail        # 查看日志

5. 汉化

Gitlab中文社区版地址:https://gitlab.com/xhang/gitlab

5.1查看版本

[root@DH-SVNSERVER ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

5.2 克隆版本库

cd /usr/local/src/

git clone https://gitlab.com/xhang/gitlab.git

5.3 获取当前的git版本

gitlab_version=$(cat /opt/gitlab/embedded/service/gitlab-rails/VERSION)

5.4 比较汉化标签和原标签,导出patch用的diff文件

cd /usr/local/src/gitlab

git diff v${gitlab_version} v${gitlab_version}-zh > ../${gitlab_version}-zh.diff

5.5 停止gitlab

gitlab-ctl stop

5.6 导入汉化补丁

patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < ../11.0.0-zh.diff

一路回车一直跳过

5.7 重启gitlab

gitlab-ctl restart 

二, 使用

1.修改gitlab访问URL配置

可以使用自定义域名,也可以直接IP地址+端口访问 

vim /etc/gitlab/gitlab.rc

此处注意别使用已被占用的端口!默认80

2.启动gitlab

gitlab-ctl reconfigure

gitlab-ctl restart 

第一次时间较长

3.浏览器访问gitlab

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

3.1报错502

排查过程: 
首先保证Gitlab可用运行内存大于4G,端口未被占用 
再赋予权限:chmod -R 755 /var/log/gitlab 
再重置重启 
访问后仍然可能遇到502,不过我刷新2次就一切ok了。。

3.2 进去之后会提醒重新设置密码,此处报错

用户名默认是root,密码自己设置

3.3 重置密码

[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: "[email protected]", ...
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里配置项目

1.配置gitlab用户邮箱

User Settings - Emails 中添加邮箱并confirm

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

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

查看公网秘钥添加到gitlab的ssh-key里面

打开本地git bash .配置全局的user.name和user.email:

git config --global user.name "chaopeng"
git config --global user.email "[email protected]"

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

git init
git remote add origin [email protected]:root/test.git
git add .
git commit -m "测试-test"
git push -u origin master

参考:

https://blog.csdn.net/wanchaopeng/article/details/80825263

https://blog.csdn.net/wanchaopeng/article/details/80824508

猜你喜欢

转载自blog.csdn.net/wanchaopeng/article/details/85121279