centos 7安装配置Gitlab步骤
发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,这篇文章给大家分享的是centos 7安装配置Gitlab的步骤,相信大部分人都还不知道怎么安装配置,为了让大家学会,给大家总结了以下内容,话不多说,一起往下看吧。一、准备环境操作系统内存CPUcen
千家信息网最后更新 2025年12月03日centos 7安装配置Gitlab步骤
这篇文章给大家分享的是centos 7安装配置Gitlab的步骤,相信大部分人都还不知道怎么安装配置,为了让大家学会,给大家总结了以下内容,话不多说,一起往下看吧。
一、准备环境
| 操作系统 | 内存 | CPU |
|---|---|---|
| centos 7 | 4G以上 | 双核 |
二、安装Gitlab
1)安装Gitlab所需依赖
[root@gitlab ~]# yum -y install epel-release curl openssh-server openssh-clients postfix cronie policycoreutils-python2)获取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.rpm3)安装Gitlab
[root@gitlab ~]# rpm -ivh gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm #安装时间较长,耐心等待,安装过程中会出现gitlab的logo4) 修改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,就算不修改配置文件,也需要在安装后重新配置gitlab5)web页面访问测试
如图:
可以访问到表示没有问题,但是都是英文界面,对于英文不好的我表示很是头疼,还好可以通过一些方法使其汉化,方法如下!
三、汉化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 #重新配置gitlab3)web页面再次访问
如图:
四、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页面,操作如下:
2)创建一个基本库
如图:
回到服务器上输入测试的命令,如下:
[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页面即可,如图:
五、远端库的基本操作
当你从远端仓库克隆时,实际上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 #将本地的分支推送到远程仓库刷新页面之后,如图:
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界面进行刷新,即可看到新提交的分支:
#上述操作是在/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目录下提交的所有内容,如图:
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页面,如图:
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页面,如下:
六、重置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! #保存用户修改信息,如没有问题返回trueirb(main):004:0> exit #退出再次登录,就需要使用新密码yourpassword进行登录了。
至此,centos 7安装配置Gitlab的步骤就分享到这了,你们学会了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!
分支
配置
内容
再次
页面
推送
仓库
目录
如图
文件
版本
提示
信息
方法
补丁
登录
步骤
命令
软件
软件包
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
oa网软件开发的请示
linux服务器架构
查询公安网络安全网站
外国网络安全法律
我的世界航海王mod服务器
盟大集团软件开发蜡笔
北京软件开发人员价格
支付宝服务器怎么升级
网络安全审核建议书
安徽诚信网络技术开发哪个正规
单位网络安全情况自查表
腾讯云服务器云硬盘
数据库中列出所有列名
软件开发测试各个阶段
可运维大型软件开发
完美连接服务器次数过多禁止进入
小米笔记本服务器安全策略
杭州电脑软件开发自学步骤
网络安全手抄报大全初一
混沌2用什么服务器好
海南超频服务器联系方式
数据库备份和还原的基本方法
网络安全产品运维手册
互联网科技在职研究生
南京企业软件开发值得推荐
联想私有化网络安全规定
网站设计是软件开发吗
数据库应用系统报告书
商用数据库系统最流行
手动编写数据库连接池