本地Cento7-GitLab环境搭建

137 阅读1分钟

背景

本地GitLab环境搭建

系统版本

CentOS 7.6

安装过程

一、安装环境依赖

  1. 安装ssh
yum install -y curl policycoreutils-pythonopenssh-server

image.png 2. 设置ssh

1. 启用ssh
systemctl enable sshd
2. 设置自启动
sudo systemctl enable sshd
  1. 安装postfix(作为GitLab发送邮件使用。非必要,可以选择性安装
yum install -y postfix
  1. 配置postfix
编辑main.cf
vim /etc/postfix/main.cf'inet_protocols = all'更改为 'inet_protocols = ipv4'

image.png 5. 启动postfix并设置自启动

1. 启用postfix
systemctl enable postfix 
2. 设置自启动
systemctl start postfix
  1. 安装policycoreutils-python,必备组件
yum install -y policycoreutils-python
  1. 配置swap交换分区,2核4G或以下建议配置,否则服务器会很卡顿
1. 新建一个交换分区,这里为4G
dd if=/dev/zero of=/root/swapfile bs=1M count=4096
2. 格式化
mkswap /root/swapfile 
swapon /root/swapfile
3. 添加自启用
vim /etc/fstab
新增一行:/root/swapfile swap swap defaults 0 0
4. 查看分区情况
free -h

image.png

二、安装GitLab

  1. 下载GitLab镜像,国内推荐使用清华源,官方地址:mirrors.tuna.tsinghua.edu.cn/gitlab-ce/y…
  2. 可用工具下载好后上传至服务器,也可以直接使用wget命令下载
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.3.3-ce.0.el7.x86_64.rpm
  1. 安装
rpm -ivh gitlab-ce-15.3.3-ce.0.el7.x86_64.rpm

看到这个标志,就代表安装成功 image.png 4. 自定义GitLab信息

指定服务器ip和port
vim /etc/gitlab/gitlab.rb
将external_url 'http://gitlab.example.com' 更改为服务器自身IP地址,默认端口是80,如需更改,需要指定端口,并在防火墙开放该端口

image.png 5. 初始化GitLab(时间较久,耐心等待)

gitlab-ctl reconfigure
  1. 安装成功 image.png
  2. 登录相关
用户名(默认)
root
密码(自行在指定文档查看)
vim /etc/gitlab/initial_root_password

image.png 8. 常用命令

查看状态
gitlab-ctl status 
启动
gitlab-ctl start 
停止
gitlab-ctl stop
重启
gitlab-ctl restart