温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

centos 7安装配置Gitlab步骤

发布时间:2020-06-01 13:52:00 来源:亿速云 阅读:305 作者:Leah 栏目:系统运维

这篇文章给大家分享的是centos 7安装配置Gitlab的步骤,相信大部分人都还不知道怎么安装配置,为了让大家学会,给大家总结了以下内容,话不多说,一起往下看吧。

一、准备环境

操作系统内存CPU
centos 74G以上双核

二、安装Gitlab

1)安装Gitlab所需依赖
[root@gitlab ~]# yum -y install  epel-release curl openssh-server openssh-clients postfix cronie policycoreutils-python
2)获取Gitlab的RPM软件包

方法一:通过清华大学的开源镜像站获取软件包(推荐)

[root@gitlab ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm

方法二:通过Gitlab官网来获取软件包(网络稳定时使用)

[root@gitlab ~]# wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm/download.rpm
3)安装Gitlab
[root@gitlab ~]# rpm -ivh gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm 
#安装时间较长,耐心等待,安装过程中会出现gitlab的logo
4) 修改gitlab的url并执行reconfigure
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb         #修改gitlab的配置文件
………………………………                 #省略部分内容
external_url 'http://192.168.1.8'                       #将此处改为本机的IP地址,便于访问
[root@gitlab ~]# gitlab-ctl reconfigure        #重新配置gitlab,就算不修改配置文件,也需要在安装后重新配置gitlab
5)web页面访问测试

如图:
centos 7安装配置Gitlab步骤
可以访问到表示没有问题,但是都是英文界面,对于英文不好的我表示很是头疼,还好可以通过一些方法使其汉化,方法如下!

三、汉化Gitlab

1)获取gitlab汉化补丁包(如果不需要汉化,则跳过此步骤即可)
[root@gitlab ~]# head -1 /opt/gitlab/version-manifest.txt           #查看gitlab的版本
gitlab-ce 12.3.5
[root@gitlab ~]# git clone https://gitlab.com/xhang/gitlab.git -b v12.3.5-zh
#获取汉化补丁包(注意需与gitlab的版本保持一致)
[root@gitlab ~]# cd gitlab/               #进入刚才clone下来的gitlab目录
[root@gitlab gitlab]# git diff v12.3.5 v12.3.5-zh > /root/v12.3.5-zh.diff
#用diff将英文原版与中文版的对比生成.diff文件
2)将中文补丁导入gitlab
[root@gitlab gitlab]# gitlab-ctl stop              #停止gitlab
[root@gitlab gitlab]# yum -y install patch
[root@gitlab gitlab]# patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 <  ../v12.3.5-zh.diff
 #将刚才的diff文件做为补丁导入到gitlab中
#该命令执行过程中,一路回车跳过即可
[root@gitlab gitlab]# gitlab-ctl start                 #启动gitlab
[root@gitlab gitlab]# gitlab-ctl reconfigure      #重新配置gitlab
3)web页面再次访问

如图:
centos 7安装配置Gitlab步骤
centos 7安装配置Gitlab步骤
centos 7安装配置Gitlab步骤

四、gitlab基本操作

1)配置SSH方式免密登录
[root@gitlab ~]# ssh-keygen -t rsa -C "1454295320@qq.com"
#生成秘钥对,一路回车即可,“-C”后是自己的邮箱
[root@gitlab ~]# cat ~/.ssh/id_rsa.pub         #查看生成的公钥并复制 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvNm+nXc59ugb0SGr9iMHDSFjvmdSJk0ORuX3hbjt822Y2ofXysUrIuBSQ1Jn0Rss/LPU54K32i4bIDsa/jD9gIpN/GqU+YP1MQ9bEw3YVUONAs+nYeWJWahQ1rMTeM0HC9aKvNTrNsOqrXIboJymBrs6Odt+1NnZsYHMwA/KlpYCFsi0HQgBzsLbrD5v++cIDTvM/V4rMq6fqFsfWoYYMHWc8JeNMl/aWJV1RhJpt7wm17FEv3XiH+wyoef5ZYI60IkH5qMJkjWhKcRXCWG5SH3nphUb1fmktB4DH92TW/EGw///VQEnE7tkpNjyJpOTXDuHnEk2tw43cctDN2sJH 1454295320@qq.com

回到web页面,操作如下:
centos 7安装配置Gitlab步骤
centos 7安装配置Gitlab步骤
centos 7安装配置Gitlab步骤

2)创建一个基本库

如图:
centos 7安装配置Gitlab步骤
centos 7安装配置Gitlab步骤
centos 7安装配置Gitlab步骤
回到服务器上输入测试的命令,如下:

[root@gitlab ~]# git config --global user.name "Administrator"
[root@gitlab ~]# git config --global user.email "admin@example.com"
[root@gitlab ~]# git clone git@192.168.1.8:root/test01.git         
#克隆到本地,根据提示输入“yes”即可!
[root@gitlab ~]# cd test01/
[root@gitlab test01]# touch README.md
[root@gitlab test01]# git add README.md
[root@gitlab test01]# git commit -m "add README"
[root@gitlab test01]# git push -u origin master

刷新web页面即可,如图:
centos 7安装配置Gitlab步骤

五、远端库的基本操作

当你从远端仓库克隆时,实际上git自动把本地的master分支和远端的master分支对应起来了,并且远程仓库的默认名称是origin。

1)查看关联的远程库的信息
[root@gitlab test01]# git remote        #简洁信息
origin
[root@gitlab test01]# git remote -v         #详细信息
origin  git@192.168.1.8:root/test01.git (fetch)
origin  git@192.168.1.8:root/test01.git (push)
2)推送分支到远程仓库
[root@gitlab test01]# git checkout -b dev             #创建并切换到dev分支
[root@gitlab test01]# git push origin dev              #将本地的分支推送到远程仓库

刷新页面之后,如图:
centos 7安装配置Gitlab步骤

3)解决多人协作产生的问题

当我们整个小组对同一个分支进行开发时,如果在你提交之前,你的同事已经修改了分支的内容并推送到远端仓库,而碰巧你也对同样的文件做了修改,并试图推送,那么会推送失败,因为你的同事的最新提交的数据和你试图提交的数据有冲突(你本地的内容比远端仓库的旧了),解决的办法会在提示你推送失败的返回信息中给出,这里我们模拟一下这一过程。

#进入另一个目录,克隆远端仓库,模拟多人操作
[root@gitlab test01]# cd /tmp           
[root@gitlab tmp]# git clone git@192.168.1.8:root/test01.git
[root@gitlab tmp]# cd test01/
[root@gitlab test01]# git checkout -b etc            #重新创建一个分支并切换
[root@gitlab test01]# echo -e "touch /tmp/test01" > tmp.txt
[root@gitlab test01]# git add tmp.txt
[root@gitlab test01]# git commit -m "commmit from /tmp"
[root@gitlab test01]# git push origin etc                #将新修改的内容推送到远端

回到web界面进行刷新,即可看到新提交的分支:
centos 7安装配置Gitlab步骤
centos 7安装配置Gitlab步骤

#上述操作是在/tmp目录下执行的,接下来的操作在/root目录下执行:
[root@gitlab test01]# cd /root/test01/
[root@gitlab test01]# git checkout -b etc
[root@gitlab test01]# echo "touch /root/test01.txt" > root.txt
[root@gitlab test01]# git add root.txt
[root@gitlab test01]# git commit -m "commit from /root"
[root@gitlab test01]# git push origin  etc            
#再次推送,将会出现以下错误
To git@192.168.1.8:root/test01.git
 ! [rejected]        etc -> etc (fetch first)
error: 无法推送一些引用到 'git@192.168.1.8:root/test01.git'
提示:更新被拒绝,因为远程版本库包含您本地尚不存在的提交。这通常是因为另外
提示:一个版本库已推送了相同的引用。再次推送前,您可能需要先合并远程变更
提示:(如 'git pull')。
提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。
[root@gitlab test01]# git pull origin etc              #将远端的etc分支pull到本地
[root@gitlab test01]# ls               #可以看出在/tmp目录下提交的文件就存在了
README.md  root.txt  tmp.txt
[root@gitlab test01]# git push origin etc                  #然后再次将本地的dev分支推送到gitlab,即可成功

再次刷新web页面,etc分支下就会有了我们在/tmp目录和/root目录下提交的所有内容,如图:
centos 7安装配置Gitlab步骤

4)合并远程分支
[root@gitlab test01]# git checkout master           #切换至master分支
[root@gitlab test01]# git merge etc                    #合并etc分支
[root@gitlab test01]# ls                   #查看合并后的分支下内容
README.md  root.txt  tmp.txt
[root@gitlab test01]# git add .
[root@gitlab test01]# git commit -m "提交"
[root@gitlab test01]# git push origin master             #推送到远端版本库

再次刷新web页面,如图:
centos 7安装配置Gitlab步骤

5)删除远程的分支
[root@gitlab test01]# git branch -d etc                 #删除本地的dev分支
[root@gitlab test01]# git branch -r -d origin/etc     #删除指定的远程分支
[root@gitlab test01]# git push origin :etc               #将删除的分支提交到远程版本库中
[root@gitlab test01]# git branch -d dev
[root@gitlab test01]# git branch -r -d origin/dev
[root@gitlab test01]# git push origin :dev                      #同上

再次刷新web页面,如下:
centos 7安装配置Gitlab步骤

六、重置gitlab管理员密码

[root@gitlab ~]# gitlab-rails console production             #必须是root用户登录服务器执行该命令
irb(main):001:0> user = User.where(id: 1).first             #id为1的是超级管理员
irb(main):002:0> user.password = 'yourpassword'       #密码必须至少8个字符
irb(main):003:0> user.save!                  #保存用户修改信息,如没有问题返回true
irb(main):004:0> exit                             #退出

再次登录,就需要使用新密码yourpassword进行登录了。

至此,centos 7安装配置Gitlab的步骤就分享到这了,你们学会了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI