栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

gitlab使用教程

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

gitlab使用教程

GitLab是项目管理和代码托管平台,可通过Web界面进行访问公开的或者私人项目,常用于源代码版本控制,但是也可以用于保存各类文件。GitLab能够浏览源代码,管理缺陷和注释。GitLab可以管理团队对仓库的访问,非常易于浏览提交过的版本并提供一个文件历史库。GitLab提供一个代码片段收集功能,可以轻松实现代码复用,便于日后有需要的时候进行查找。

当前使用的是私服GitLab,搭建在内部服务器上,只有管理员授予账号才可以访问。

Gitlab环境部署

环境要求:内存不低于2G

第一步,查看Linux版本信息。

查看Linux系统的版本信息命令:cat /proc/version

查看Linux系统发行版信息命令:cat /etc/redhat-release

第二步,安装依赖包。

命令:yum install policycoreutils openssh-server openssh-clients postfix

systemctl enable sshd

systemctl start sshd

systemctl enable postfix

systemctl start postfix

第三步,下载并安装rpm包。

方法一:通过rpm包进行安装。(一般选择这种方法)

不同版本的Linux对应不同的rpm包。

若Linux版本为Centos 7,则需要下载el7版本的GitLab;

若Linux版本为Centos 8,则需要下载el8版本的GitLab;

若Linux版本为Alibaba Cloud Linux release 3,则需要下载el8版本的GitLab。

rpm包可以从官网上或清华镜像源获取,网址:

Index of /gitlab-ce/yum/el7/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el8/

下载rpm命令:cd /usr/local/rpm

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.7.5-ce.0.el7.x86_64.rpm

rpm -ivh gitlab-ce-12.7.5-ce.0.el7.x86_64.rpm

若结果显示“policycoreutils-python is needed by gitlab-ce”,则说明运行出现错误。又因为Linux版本为Centos 7,GitLab版本为el7,所以可以使用命令“yum install policycoreutils-python”来解决这个问题。若使用上述命令无效,则说明Linux版本一定不是centos 7。然后重新安装GitLab。

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el8/gitlab-ce-12.10.7-ce.0.el8.x86_64.rpm

rpm -ivh gitlab-ce-12.10.7-ce.0.el8.x86_64.rpm

若结果显示“policycoreutils-python-utils is needed by gitlab-ce”,则说明运行出现错误。又因为Linux版本为Centos 8或Alibaba Cloud Linux release 3,GitLab版本为el7,所以可以使用命令“yum install policycoreutils-python-utils”来解决这个问题。若使用上述命令无效,则说明Linux版本一定不是centos 8或Alibaba Cloud Linux release 3。然后重新安装GitLab。

方法二:通过yum源安装。

新建/etc/yum.repos.d/gitlab-ce.repo文件,并在文件中写入下面的代码:

[gitlab-ce]

name=gitlab-ce

baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7

Repo_gpgcheck=0

Enabled=1

Gpgkey=https://packages.gitlab.com/gpg.key

更新本地yum缓存命令:yum makecache

安装GitLab社区版命令:

yum install gitlab-ce              #自动安装最新版

或 yum install gitlab-ce-x.x.x     #安装指定版本

第四步,修改配置文件。

1)修改配置文件/etc/gitlab/gitlab.rb,在文件中做如下修改:

# 把网址改为服务器IP(默认IP为8080,若8080已经使用,自定义其它端口)

external_url 'http://120.55.72.8:8081'

2)确保防火墙启动成功

命令:systemctl status firewalld

若结果显示“Active: inactive (dead)”,则需要启动防火墙。

systemctl start firewalld

若结果显示“Active: active (running)”,则可以运行下面的命令:

sudo firewall-cmd --permanent --add-service=http

sudo firewall-cmd --permanent --add-service=https

sudo systemctl reload firewalld

若结果都显示“success”,则说明防火墙启动成功。

3)把GitLab的端口号放开

firewall-cmd --zone=public --add-port=8081/tcp --permanent

若结果显示“success”,则说明GitLab的端口号成功放开。

4)重新加载并启动

命令:gitlab-ctl reconfigure && gitlab-ctl restart

若结果显示“ok: run”,则说明配置文件修改完成。

GitLab常用命令

gitlab-ctl start                             # 启动所有GitLab组件

gitlab-ctl stop                             # 停止所有GitLab组件

gitlab-ctl restart                         # 重启所有GitLab组件

gitlab-ctl status                          # 查看服务状态

gitlab-ctl reconfigure                  # 启动服务

gitlab-rake gitlab:check SANITIZE=true --trace       # 检查GitLab

gitlab-ctl tail                               # 查看日志

1)GitLab的守护进程关闭和重启

# 备注:GitLab的守护进程会默认开启nginx

命令:gitlab-ctl stop nginx

gitlab-ctl restart nginx

释放资源,关闭GitLab命令:gitlab-ctl stop

2)服务器重启或者GitLab意外停止,执行命令“gitlab-ctl start”。

若结果显示“fail: sidekiq: runsv not running”等,则说明GitLab不能启动。可以使用下面命令来解决这个问题:

systemctl start gitlab-runsvdir

gitlab-ctl restart

GitLab使用

在浏览器的地址栏中输入ECS服务器的公网IP(GitLab的ip和端口号),无法访问。

1)linux系统开放GitLab的端口号

命令:cd /etc/sysconfig

ls -l

结果显示“ip6tables-config”和“iptables-config”,但是没有查看到iptables文件。

2)安装iptables-services

命令:yum install iptables-services

3)启动iptables

命令:systemctl enable iptables

systemctl start iptables

4)在iptables中配置开放GitLab的端口号

命令:vim /etc/sysconfig/iptables

在文件中添加下面的代码:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT

5)重启防火墙

命令:service iptables restart

6)在浏览器的地址栏中输入ECS服务器的公网IP(GitLab的ip和端口号),登录GitLab的界面,第一次登录使用的用户名和密码为 root和5iveL!fe。首次登录会强制用户修改密码。密码修改成功后,输入新密码进行登录。

7)设置gitlab发信功能

发信系统默认postfix和smtp都是开启的,但是两个都开启,两个都不会工作。因此,设置一个关闭,一个开启。

设置关闭smtp,开启postfix

关闭smtp方法:vim /etc/gitlab/gitlab.rb

把“#gitlab_rails['smtp_enable'] = true”改为“gitlab_rails['smtp_enable'] = false”

修改后执行命令:gitlab-ctl reconfigure && gitlab-ctl restart

创建Project

第一步,安装Git工具。

在linux中安装Git,使用自带的源安装。

命令:yum install git

第二步,生成密钥文件。

使用ssh-keygen生成密钥文件.ssh/id_rsa.pub。

命令:ssh-keygen                 #连续回车四下

cat .ssh/id_rsa.pub                #结果显示生成的秘钥

第三步,在GitLab的主页中新建一个Project。

点击“新建Project”,在“Blank Project”栏目中,填写“Project name”,其他默认,最后点击“创建Project”。

 

第四步,添加ssh key导入第二步中生成的密钥文件内容。

点击“添加ssh key”,然后在“key”中复制粘贴刚刚生成的秘钥,最后点击“添加key”。

项目地址在进行clone操作时需要用到。

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/942030.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号