当前位置: 首页 > news >正文

linux环境搭建私有gitlab仓库

  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.lryc.cn/news/11820.html

相关文章:

  • SpringSecurity授权
  • 学习 Python 之 Pygame 开发坦克大战(一)
  • 2.5|iot冯|方元-嵌入式linux系统开发入门|2.13+2.18
  • 一起Talk Android吧(第四百九十六回:自定义View实例二:环形进度条)
  • 上传图片尺寸校验
  • 【Python】缺失值处理和拉格朗日插值法(含源代码实现)
  • SpringCloudAlibaba-Sentinel
  • 【程序化天空盒】过程记录02:云扰动 边缘光 消散效果
  • 链表OJ(三) 反转链表合集
  • SQLSERVER2019安装步骤过程
  • Java模块化概述
  • Connext DDSPersistence Service持久性服务(2)
  • MongoDB
  • python 迭代器生成器
  • Iceberg基于Spark MergeInto语法实现数据的增量写入
  • JavaScript Array(数组) 对象
  • Debian如何更换apt源
  • Connext DDSPersistence Service持久性服务
  • 自抗扰控制ADRC之微分器TD
  • 链表学习之复制含随机指针的链表
  • 【人脸检测】Yolov5Face:优秀的one-stage人脸检测算法
  • 【Unity3d】Unity与Android之间通信
  • Allegro如何更改DRC尺寸大小操作指导
  • Mongodb WT_PANIC: WiredTiger library panic
  • 【HTML】HTML 表格总结 ★★★ ( 表格标签 | 行标签 | 单元格标签 | 表格标签属性 | 表头单元格标签 | 表格标题标签 | 合并单元格 )
  • linux013之文件和目录的权限管理
  • 设计模式之状态模式
  • XQuery 选择 和 过滤
  • 室友打了一把王者的时间,我理清楚了grep,find,管道|,xargs的区别与联系,用的时候不知道为什么要这样用
  • python 刷题时常见的函数