linux环境搭建私有gitlab仓库

news/2025/2/22 19:11:11/
  1. 搭建之前,需要安装相应的依赖包,并且要启动sshd服务

(1).安装policycoreutils-python openssh-server openssh-clients

[root@VM-0-2-centos ~]# sudo yum install -y curl policycoreutils-python openssh-server openssh-clients 
[root@VM-0-2-centos ~]# sudo systemctl enable sshd 
[root@VM-0-2-centos ~]# sudo systemctl start sshd 

(2).在安装时可能会报错

在安装yum install -y curl policycoreutils-python openssh-server openssh-clients时可能会报如下错误:
Error: Unable to find a match: policycoreutils-python
产生这个错误的原因是未配置yum源,所以需要安装 EPEL 源,命令如下:
[root@VM-0-2-centos ~]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

然后运行

[root@VM-0-2-centos ~]# yum install -y curl policycoreutils-python3 openssh-server openssh-clients

(3).安装postfix

gitlab配置需要用到邮件发送,所以需要安装postfix
[root@VM-0-2-centos ~]# yum -y install postfix
#安装完之后,启动postfix
[root@VM-0-2-centos ~]# 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.
解决办法,vim打开/etc/postfix/main.cf, 修改如下两项,修改之前可以先备份:
#修改 /etc/postfix/main.cf的设置  
inet_protocols = ipv4  
inet_interfaces = all
修改完成后,再次启动,就不会报错了,设置postfix为开机自启动
[root@VM-0-2-centos ~]# systemctl enable postfix
查看启动状态
[root@VM-0-2-centos ~]# systemctl status postfix

2.gitlab安装

centos系统的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
找最新版去下载gitlab-ce-15.8.3-ce.0.el7.x86_64.rpm
下载rpm包并安装
[root@VM-0-2-centos ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.8.3-ce.0.el7.x86_64.rpm
[root@VM-0-2-centos ~]# mkdir /usr/local/gitlab
[root@VM-0-2-centos ~]# mv gitlab-ce-15.8.3-ce.0.el7.x86_64.rpm /usr/local/gitlab/
[root@VM-0-2-centos ~]# cd /usr/local/gitlab/
[root@VM-0-2-centos ~]# rpm -i itlab-ce-15.8.3-ce.0.el7.x86_64.rpm 
[root@VM-0-2-centos ~]#  warning: itlab-ce-15.8.3-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
[root@VM-0-2-centos ~]# error: Failed dependencies:policycoreutils-python is needed by itlab-ce-15.8.3-ce.0.el7.x86_64.rpm
# 如果出现上面这个报错就执行yum install policycoreutils-python

如果运行上面的yum install policycoreutils-python命令还是报错,解决办法:

可以在安装rpm包命令的后面加两个参数,如:

[root@VM-0-2-centos ~]# rpm -i itlab-ce-15.8.3-ce.0.el7.x86_64.rpm --nodeps --force
--force是强制安装
--nodeps是不依赖关系
加上那两个参数的意义就在于,
安装时不再分析包之间的依赖关系而直接安装,
也就不会再提示error: Failed dependencies:这样的错误了

上述 rpm -i itlab-ce-15.8.3-ce.0.el7.x86_64.rpm --nodeps --force命令成功后展示如下:

warning: gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
It looks like GitLab has not been configured yet; skipping the upgrade script.*.                  *.***                 ********               *****.******             ***************            ********,,,,,,,,,***********,,,,,,,,,,,,,,,,,,,,*********,,,,,,,,,,,.,,,,,,,,,,,*******,,,,,,,,,,,,,,,,,,,,,*****,,,,,,,,,.,,,,,,,****,,,,,,.,,,***,,,,,*,._______ __  __          __/ ____(_) /_/ /   ____ _/ /_/ / __/ / __/ /   / __ `/ __ \/ /_/ / / /_/ /___/ /_/ / /_/ /\____/_/\__/_____/\__,_/_.___/Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:sudo gitlab-ctl reconfigureFor a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

安装完成之后,会出现gitlab官方文档地址https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

3.配置并启动gitlab-ce

gitlab安装完成后,需要设置一个访问地址(或域名),打开/etc/gitlab/gitlab.rb,将默认的external_url = 'http://git.example.com'修改为自己的IP地址:http://xxx.xx.xxx
[root@VM-0-2-centos ~]# vim /etc/gitlab/gitlab.rb

原来默认的external_url

## 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
external_url 'http://git.example.com'

修改成自己定义的url地址,端口自己设置一个,别和已有的冲突了

## 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
external_url 'http://152.26.xx.xx:8181'

修改完成后:wq保存退出,执行以下命令,让配置生效

[root@VM-0-2-centos ~]# gitlab-ctl reconfigure

启动Gitlab

[root@VM-0-2-centos ~]# gitlab-ctl start
[root@VM-0-2-centos ~]# gitlab-ctl start
ok: run: gitaly: (pid 6638) 186s
ok: run: gitlab-monitor: (pid 6656) 186s
ok: run: gitlab-workhorse: (pid 6659) 186s
ok: run: logrotate: (pid 6703) 185s
ok: run: nginx: (pid 6709) 185s
ok: run: node-exporter: (pid 6715) 184s
ok: run: postgres-exporter: (pid 6720) 184s
ok: run: postgresql: (pid 7324) 44s
ok: run: prometheus: (pid 6752) 171s
ok: run: redis: (pid 6761) 171s
ok: run: redis-exporter: (pid 6765) 170s
ok: run: sidekiq: (pid 7299) 45s
ok: run: unicorn: (pid 7476) 18s

启动完成后,在浏览器输入http://152.26.xx.xx:8181,就是gitlab的登录首页了

重启下服务,刷新页面就可以访问了

[root@VM-0-2-centos ~]# gitlab-ctl restart

为了避免8080端口冲突问题,可以修改下unicorn的默认端口,vim打开/etc/gitlab/gitlab.rb配置文件,新增一项unicorn['port'] = 8101

## 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
external_url 'http://152.26.xx.xx:8181'unicorn['port'] = 8101

修改完成后:wq保存退出,执行gitlab-ctl reconfigure命令,让配置生效,再重新启动服务

[root@VM-0-2-centos ~]# gitlab-ctl reconfigure
[root@VM-0-2-centos ~]# gitlab-ctl stop
[root@VM-0-2-centos ~]# gitlab-ctl start
gitlab常用命令
启动服务:gitlab-ctl start
查看状态:gitlab-ctl status
停掉服务:gitlab-ctl stop
重启服务:gitlab-ctl restart
让配置生效:gitlab-ctl reconfigure

当运行命令gitlab-ctl reconfigure时,如果报错:STDERR: initdb: error: invalid locale settings; check LANG and L...,这是默认字符集问题

There was an error running gitlab-ctl reconfigure:execute[/opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8] (postgresql::enable line 49) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
STDOUT: The files belonging to this database system will be owned by user "gitlab-psql".
This user must also own the server process.
STDERR: initdb: error: invalid locale settings; check LANG and LC_* environment variables
---- End output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
Ran /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 returned 1

解决办法

  1. 确保服务器内存在4G以上

  1. 修改配置

vim /etc/profile
# 将以下内容添加到配置文件末尾
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# 重读环境变量
[root@localhost src]# source /etc/profile
# 重新加载
[root@localhost src]# gitlab-ctl reconfigure
第一次进入最好修改密码

4.搭建GItLab以后出现卡顿

(1).原因分析

gitlab 启动运行占用了大量的内存,2G内存在启动后已经所剩无几,想再进行git 相关操作自然也就会出现卡顿现象.正常 centos 应该是启用 swap 分区的,但是阿里云,腾讯云的服务器却没有swap分区
通过以下命令查看swap分区情况:
cat /proc/swaps

(2).解决方法

1).创建 swap 分区(这里需要等待几秒)

dd if=/dev/zero of=/swap bs=512 count=8388616
注意:创建swap大小为bs*count=4294971392(4G)

2).通过mkswap命令将上面新建出的文件做成swap分区

mkswap /swap

3).查看内核参数vm.swappiness中的数值是否为0,如果为0则根据实际需要调整成60

# 查看参数
cat /proc/sys/vm/swappiness
# 设置参数
# sysctl -w vm.swappiness=60

4).启用 swap 分区

swapon /swapecho “/swap swap swap defaults 0 0” >> /etc/fstab

5).再次使用cat /proc/swaps 查看swap分区是否启动

可以看到,swap分区已经启用,现在通过 gitlab 进行操作会发现很流畅


http://www.ppmy.cn/news/26096.html

相关文章

网页设计html期末大作业

网页设计html期末大作业网页设计期末大作业-自制网站大一期末作业,外卖网站设计网页设计期末大作业-精美商城-首页框架网页设计期末大作业-自制网站 有导航栏,轮播图,按钮均可点进去,如下图所示 点我下载资源》》》》 大一期末…

CoreDNS

目录 文章目录目录本节实战前言1、环境变量2、DNS1.DNS 解析过程2.根域名服务器3.顶级域名服务器4.权威性域名服务器5.dig 域名3、CoreDNS1.CoreDNS 扩展配置(1)开开启日志服务(2)特定域名使用自定义 DNS 服务器(3&…

基于AIOT技术的智慧校园空调集中管控系统设计与实现

毕业论文(设计)题 目 基于AIOT技术的智慧校园空调集中管控系统设计与实现指导老师 XXXX 专业班级 电子商务2XXXX 姓 名 XXXX 学 号 20XXXXXXXXX 20XX年XX月XX日摘要近年来,随着物联网技术和人工智能技术的快速发展,智慧校园逐渐…

VSCode远程调试Linux代码,python解释器配置

安装插件并配置 安装后找到插件图标,点击 点击SSH上的 号 在弹出框中输入命令:ssh usernameip -p port username: 远程服务器的用户名 ip: 远程ip port:端口号,没有可以不用 输入完毕后点击enter 选择ssh配置文件保存…

【C语言】预编译

🚩write in front🚩 🔎大家好,我是謓泽,希望你看完之后,能对你有所帮助,不足请指正!共同学习交流🔎 🏅2021年度博客之星物联网与嵌入式开发TOP5&#xff5…

【原创】java+swing+mysql图书管理系统设计与实现

图书管理系统是一个比较常见的系统,今天我们主要介绍如何使用javaswiingmysql去开发一个cs架构的图书管理系统,方便学生进行图书借阅。 功能分析: 宿舍报修管理系统的使用角色,一般分为管理员和学生,管理员主要进行学…

LeetCode 350. 两个数组的交集 II

原题链接 难度:easy\color{Green}{easy}easy 题目描述 给你两个整数数组 nums1nums1nums1 和 nums2nums2nums2 ,请你以数组形式返回两数组的交集。返回结果中每个元素出现的次数,应与元素在两个数组中都出现的次数一致(如果出现…

pytorch零基础实现语义分割项目(一)——数据概况及预处理

语义分割之数据加载项目列表前言数据集概况数据组织形式数据集划分数据预处理均值与方差结尾项目列表 语义分割项目(一)——数据概况及预处理 语义分割项目(二)——标签转换与数据加载 语义分割项目(三&#xff09…