CentOS7安装GitLab安装

GitLab安装

更换Centos国内数据源

1.备份旧的配置文件

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2.下载Centos-Base.repo到 /etc/yum.repos.d/

centos8:

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

centos7:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

centos6:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

并替换部分字段(非阿里云机器需要做)

sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

3.生成缓存

 yum makecache

4.更新

yum -y update

安装GitLab

一、安装并配置必要的依赖关系

在CentOS系统上安装所需的依赖:ssh,防火墙,postfix(用于邮件通知) ,wget,以下这些命令也会打开系统防火墙中的HTTP和SSH端口访问。

1.安装ssh

sudo yum install -y curl policycoreutils-pythonopenssh-server

在这里插入图片描述

说明安装完成

2.将SSH服务设置为开机自启动

sudo systemctl enable sshd

3.启动SSH服务

sudo systemctl start sshd

在这里插入图片描述

4.安装防火墙(这里使用的是firewalld,若已有其他的防火墙软件,可直接跳过至第六步)

yum install -y firewalld systemd

出现完毕即安装完场。

在这里插入图片描述

5.开启防火墙

service firewalld start

在这里插入图片描述

6.添加http服务到firewalld,pemmanent表示永久生效,若不加–permanent系统下次启动后就会失效。

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

7.设置好后,需要重启一下防火墙

sudo systemctl reload firewalld

8.安装Postfix

sudo yum install postfix

9.将Postfix服务设置开机自启动

sudo systemctl enable postfix

10.启动postfix

sudo systemctl start postfix

在安装Postfix期间,可能会出现配置屏幕。选择“Internet Site”并按enter键。使用您的服务器的外部DNS以“mail name”并按enter。如果出现额外的屏幕,继续按enter键接受默认值。

11.wget用于从外网上下载插件

检查系统中是否已经安装wget,使用查看版本指令,出现版本信息,说明安装有wget,若没有需要安装

wget查看版本信息:

wget -V

出现下图,说明有wget

在这里插入图片描述

没有需要安装

yum -y install wget

12.安装vim编辑器,若不想安装可以直接使用自带的vi编辑器

yum install -y vim

13.安装policycoreutils-python依赖

yum install -y policycoreutils-python

二、添加GitLab镜像源并安装gitlab服务器

1.添加gitlab镜像(这里安装15.3.0若需要更换版本,可以进入镜像选择需要的版本)

GitLab社区版镜像源:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

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

若出现颁发的证书过期无法下载,则添加后缀 --no-check-certificate

2.安装gitlab命令

rpm -i gitlab-ce-15.3.0-ce.0.el7.x86_64.rpm   # (后面根据自己下载版本而定)

出现下图,说明安装成功

在这里插入图片描述

3.修改gitlab配置文件指定服务器ip和自定义端口

vim /etc/gitlab/gitlab.rb

在这里插入图片描述

没有域名可以设置IP+端口

有域名可以改为 : gitlab.xxxx.xxxxt 同时需要设置Ngnix的端口转发

5.重置并启动Gitlab

gitlab-ctl reconfigure   # 重新加载Gitlab配置文件

gitlab-ctl restart   # 重新启动Gitlab

在这里插入图片描述

重启完成

6.还需要配置一下防火墙的开放端口(根据自己设定的端口,打开即可)

firewall-cmd --zone=public --add-port=9982/tcp --permanent  # 打开9982端口
firewall-cmd reload # 配置完防火墙后需要重新加载一下

配置完成后,访问配置的地址即可

在这里插入图片描述

安装时遇到包的缺失

在Centos里面安装软件,提示软件已安装,但rpm -q和-e都提示包没有安装

查看与rpm包相关的文件和其他信息

rpm -qa | grep 包名

查看包是否被安装

rpm -q 包名

删除软件包

rpm -e 包名

运行这三步,把原来的包删除掉重新下载和安装

三、初始化管理员密码

获取/修改超级管理员root的密码

首先进入目录 /opt/gitlab/bin ,然后执行下面指令开始初始化密码

sudo gitlab-rails console production

在irb(main):001:0> 后面通过 u=User.where(id:1).first 或 u=User.where(name:“admin”) 来查找与切换账号(User.all 可以查看所有用户)

通过 u.password=‘xxxxx’ 设置密码,其中xxxxx为需要设置的root密码。

通过 u.password_confirmation=‘xxxxx’ 再次确认密码

最后通过 u.save! 进行保存(后面有感叹号!)

保存后看到返回true,说明成功了,执行 exit 退出当前设置流程即可。

若上面这个方法不行,可以尝试官方文档的方法


gitlab-rails console -e production  # 输入指令进入控制台

user = User.where(id: 1).first 或  user = User.find_by(email: '[email protected]') # 选择root用户

user.password='xxxxx'  # 需要设定的密码

user.password_confirmation='xxxxx'  # 再次确认密码

user.save!  # 保存

同样可以更据这个方法,修改用户的密码。

补充:

CentOS 7防火墙端口命令

在CentOS7当中的防火墙常用的是firewall,下面介绍firewall的常用方法:

>>>关闭防火墙

systemctl stop firewalld.service  # 停止firewall
systemctl disable firewald.service  # 禁止firewall开机启动

>>>开启端口

firewall-cmd --zone=public --add-port=80/tcp --permanent
含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent  # 永久生效,没有此参数重启后端口失效

>>>重新加载防火墙配置
firewall-cmd --reload

常用命令

firewall-cmd --state                           ##查看防火墙状态,是否是running
firewall-cmd --reload                          ##重新载入配置,比如添加规则之后,需要执行此命令
firewall-cmd --get-zones                       ##列出支持的zone
firewall-cmd --get-services                    ##列出支持的服务,在列表中的服务是放行的
firewall-cmd --query-service ftp               ##查看ftp服务是否支持,返回yes或者no
firewall-cmd --add-service=ftp                 ##临时开放ftp服务
firewall-cmd --add-service=ftp --permanent     ##永久开放ftp服务
firewall-cmd --remove-service=ftp --permanent  ##永久移除ftp服务
firewall-cmd --add-port=80/tcp --permanent     ##永久添加80端口 
iptables -L -n                                 ##查看规则,这个命令是和iptables的相同的
man firewall-cmd                               ##查看帮助

更多命令,使用  firewall-cmd --help 查看帮助文件

猜你喜欢

转载自blog.csdn.net/weixin_44030265/article/details/128865460