centos7云服务器配置gitlab环境记录
前言
由于工作需要,经常使用到gitlab来管理项目代码,为了熟悉一些操作,干脆自己搭建一个gitlab环境来熟悉一下操作。
一、准备环境
重要的东西说在前,因为是自己的配置,所以很多服务都是较新的,比如我的centos7云服务器,还有win11的linux子系统,相对来说,一些企业提供的服务会因为历史遗留问题,许多都会比较老旧,但也有部分服务紧跟技术潮流,具体的资料参考,一定要贴合自身需求。
1.首先是一些重要依赖安装
首先是sshd服务,这是根据ssh协议提供远程主机shell的服务。
yum install -y curl policycoreutils-python openssh-server systemctl enable sshd #设定开机自启动 systemctl start sshd #启动sshd服务
2.配置防火墙
这里主要是开启远程连接,并且开放http访问,因为主要还是使用网页访问提供gitlab服务的云服务器,所以http方式免不了,问我为什么不是https?因为没钱啊!域名都还没买呢!回归正题,配置防火墙,主要是编辑/etc/sysctl.conf开启远程连接
#/etc/sysctl.conf文件 #Controls IP packet forwarding net.ipv4.ip_forward = 1
把net.ipv4.ip_forward的值设为1是我的更改,但不少博客说是直接在最后面添加net.ipv4.ip_forward = 1,我觉得应该是对前面的进行覆盖吧,所以我还是在变量原位置进行修改,然后启动防火墙。
systemctl enable firewalld systemctl start firewalld
放开http请求
firewall-cmd --permanent --add-service=http #permanent参数,对应修改为永久修改,上面是允许http服务通过 systemctl reload firewalld #重启防火墙服务
3.安装postfix
gitlab服务需要发送邮件,普遍的都是postfix来提供该服务,也有说可以用SMTP,这里就先用着postfix吧。嗯,当我使用yum进行安装的时候,好像服务器已经提供了?哈哈哈,如果没有的话,可以使用这个命令:
yum install postfix
然后编辑一下配置,vim我们的/etc/postfix/main.cf文件,定位到inet_protocols处,修改all为ipv4,老实说,我不太明白为什么,ipv6也没啥啊,通用配置不是更好吗?
然后又是熟悉的设置postfix服务开机自启动和启动其服务了。听说gitlab消耗资源严重,所以会创建一个交换分区来降低物理内存的压力,不过我不准备这样,先试一段时间。
二、安装gitlab
先来yum安装
yum install gitlab-ce
嗯,然后发现没有可用的rpm源?
[root@VM-0-17-centos ~]# yum install gitlab-ce 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 没有可用软件包 gitlab-ce。 错误:无须任何处理
那咋办?一个就是修改软件源为国内的,比如清华大学,另外的就是离线下载好压缩包,然后编译安装或者rpm包再rpm安装。地址如下:清华大学镜像源
添加软件源
在/etc/yum.repos.d目录下添加关于gitlab-ce的清华大学镜像源文件:
#gitlab-ce.repo文件,此为标示,无需添加到文件中 [gitlab-ce] name=Gitlab CE Repository baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/ gpgcheck=0 enabled=1
重新生成缓存,然后yum下载gitlab-ce
yum makecache yum install gitlab-ce
出现这个界面就ok了
如上面的显示,接下来就是配置你的访问url了。
配置外部url
如下,把external_url参数更改为个人服务器域名即可,没有的话就ip地址吧,这个是对应你的外网ip,别搞错了。
## GitLab URL ##! URL on which GitLab will be reachable. ##! For more details on configuring external_url see: ##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab ##! ##! Note: During installation/upgrades, the value of the environment variable ##! EXTERNAL_URL will be used to populate/replace this value. ##! On AWS EC2 instances, we also attempt to fetch the public hostname/IP ##! address from AWS. For more details, see: ##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html external_url 'http://gitlab.example.com'
修改成这样的就可以了 external_url 'http://119.29.102.00',然后我们初始化gitlab.
初始化gitlab
这里居然使用的是sudo命令来提升权限,让我惊讶的是它还管用了!因为平时见到这个使用都是在ubuntu等系统,不是在centos,具体怎样我倒是不太记得了,反正管用。
sudo gitlab-ctl reconfigure
不过奇怪的是它居然报执行错误:
Error executing action `run` on resource 'ruby_block[authorize Grafana with GitLab]'
然后我去查cup才发现好像爆满了,内存也快满了,可能还是要整个交换分区。
配置交换分区
还以为我的服务器作为单人的使用够可以了,想不到,还是高估了这个学生福利得到的云服务器,害。
#新建2g的交互分区 dd if=/dev/zero of=/root/forswap bs=1M count=2048 #格式化交互分区 mkswap /root/forswap swapon /root/forswap #/etc/fstab文件添加下面信息使其自启用 /root/forswap swap swap defaults 0 0
嗯,配置完后好像好很多了
继续初始化gitlab
sudo systemctl restart gitlab-runsvdir sudo gitlab-ctl reconfigure
嗯,结果还是不行,那就先不管吧。
Running handlers: There was an error running gitlab-ctl reconfigure: ruby_block[authorize Grafana with GitLab] (monitoring::grafana line 101) had an error: Mixlib::ShellOut::CommandTimeout: Command timed out after 600s: Command exceeded allowed execution time, process terminated ---- Begin output of /opt/gitlab/bin/gitlab-rails runner -e production 'app = Doorkeeper::Application.where(redirect_uri: "http://121.5.47.242/-/grafana/login/gitlab", name: "GitLab Grafana").first_or_create;puts app.uid.concat(" ").concat(app.secret);' ---- STDOUT: STDERR: ---- End output of /opt/gitlab/bin/gitlab-rails runner -e production 'app = Doorkeeper::Application.where(redirect_uri: "http://121.5.47.242/-/grafana/login/gitlab", name: "GitLab Grafana").first_or_create;puts app.uid.concat(" ").concat(app.secret);' ---- Ran /opt/gitlab/bin/gitlab-rails runner -e production 'app = Doorkeeper::Application.where(redirect_uri: "http://121.5.47.242/-/grafana/login/gitlab", name: "GitLab Grafana").first_or_create;puts app.uid.concat(" ").concat(app.secret);' returned
卸载gitlab
虽然初始化失败了,但并不是什么都没启动,gitlab服务是个软件集合,不是单个软件,现在需要停止服务然后卸载。
gitlab-ctl stop systemctl stop gitlab-runsvdir #查看一下还开着的gitlab进程 ps -ef | grep gitlab #free命令查看一下内存 free -mh
然后准备用yum卸载了gitlab-ce
[root@centos yum.repos.d]# yum remove gitlab-ce 错误:rpmdb: BDB0113 Thread/process 11737/140506376706112 failed: BDB1507 Thread died in Berkeley DB library 错误:db5 错误(-30973) 来自 dbenv->failchk:BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery 错误:无法使用 db5 - (-30973) 打开 Packages 索引 错误:无法从 /var/lib/rpm 打开软件包数据库 CRITICAL:yum.main: Error: rpmdb open failed
这下又要重构rpm数据库了:
[root@centos yum.repos.d]# ls /var/lib/rpm Basenames __db.001 __db.003 Group Name Packages Requirename Sigmd5 Conflictname __db.002 Dirnames Installtid Obsoletename Providename Sha1header Triggername [root@centos yum.repos.d]# rm -rf /var/lib/rpm/__db* [root@centos yum.repos.d]# ls /var/lib/rpm Basenames Conflictname Dirnames Group Installtid Name Obsoletename Packages Providename Requirename Sha1header Sigmd5 Triggername [root@centos yum.repos.d]# rpm --rebuilddb
然后就yum remove即可。
哎,要攒钱买高级点的服务器了。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程