曦涵猫猫
曦涵猫猫
发布于 2025-08-15 / 4 阅读
0
0

从源码编译安装GitLab

这是我的工作log, 可能写的不够易懂请谅解

No.1 你需要先安装系统依赖

全部回车即可

# deb系列
sudo apt-get update && sudo apt-get install -y gcc autoconf cmake unzip vim libcurl4-openssl-dev zlib1g-dev libexpat1-dev gettext openssl libperl-dev nodejs libicu-dev wget curl vim postfix gem golang postgresql postgresql-client libpq-dev postgresql-contrib redis-server
yun uupdate && yum -y install gcc autoconf cmake unzip vim libcurl-devel zlib-devel curl-devel expat-devel gettext-devel openssl-devel perl-devel nodejs libicu-devel wget curl vim postfix gem golang postgresql postgresql-client libpq-dev postgresql-contrib redis-server

No.2 编译依赖

我们需要编译安装git, 首先在https://www.kernel.org/pub/software/scm/git/下载最新版本.我下载的是git-2.50.1.tar.xz因此后面使用git-2.50.1.tar.xz,如有需要自行替换为你的版本

tar -xvf git-2.50.1.tar.xz
cd git-2.50.1
./configure
make prefix=/usr/local all

No.3 添加系统设置

添加用于执行git相关操作的系统用户,防止越权

useradd -c 'Gitlab' -s /bin/bash git

让git用户的$PATH包含/usr/local/bin

sudo vim /etc/sudoers

在Defaults secure_path=里面多加一条:/usr/local/bin, 确认无误后使用:wq!写入并退出

No.4 安装Ruby

你需要先确认你的系统没有ruby环境,如果有就卸载.

使用你的gitlab推荐的ruby版本,我以V18.2为准

gem update --system

No.5 安装go-lang

go-lang相关套装使用包管理器安装过了,不再赘述

No.6 安装Node.Js

这里使用node.js推荐的nvm进行安装,版本为22

# Download and install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

# in lieu of restarting the shell
\. "$HOME/.nvm/nvm.sh"

# Download and install Node.js:
nvm install 22

# Verify the Node.js version:
node -v # Should print "v22.18.0".
nvm current # Should print "v22.18.0".

# Verify npm version:
npm -v # Should print "10.9.3".

No.7 配置PGSql数据库

PGSql已经使用包管理安装过了,但是GitLab需要PGSql的数据库扩展和配置

1. 为GitLab创建一个数据库用户

sudo -u postgres psql -d template1 -c "CREATE USER git CREATEDB;"

2. 为GitLab安装需要的扩展

sudo -u postgres psql -d template1 -c "
    CREATE EXTENSION IF NOT EXISTS pg_trgm;
    CREATE EXTENSION IF NOT EXISTS btree_gist;
    CREATE EXTENSION IF NOT EXISTS plpgsql;"

3. 创建GitLab数据库用户和数据库

sudo -u postgres psql -d template1 -c "CREATE DATABASE gitlabhq_production OWNER git;"

4. 测试链接

sudo -u git -H psql -d gitlabhq_production

5. 测试插件

gitlabhq_production=> SELECT true AS enabled 
FROM pg_available_extensions 
WHERE name = 'pg_trgm' AND installed_version IS NOT NULL
UNION ALL
SELECT true AS enabled 
FROM pg_available_extensions 
WHERE name = 'btree_gist' AND installed_version IS NOT NULL
UNION ALL
SELECT true AS enabled 
FROM pg_available_extensions 
WHERE name = 'plpgsql' AND installed_version IS NOT NULL;

应该返回以下结果

 enabled 
---------
 t
 t
 t
(3 rows)

6. 推出

gitlabhq_production=> \q

No.8 配置Redis

cp /etc/redis.conf /etc/redis.conf.orig
#sed 's/^port .*/port 0/' /etc/redis.conf.orig |tee /etc/redis.conf #不需要执行
echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis.conf
echo 'unixsocketperm 770' | sudo tee -a /etc/redis.conf
mkdir /var/run/redis
sudo chown redis:redis /var/run/redis
sudo chmod 755 /var/run/redis
 
# Persist the directory which contains the socket, if applicable
if [ -d /etc/tmpfiles.d ]; then
    sudo echo 'd /var/run/redis 0755 redis redis 10d -' | sudo tee -a /etc/tmpfiles.d/redis.conf
fi
 
sudo systemctl start redis
sudo usermod -aG redis git

No.9 GitLab

1. 需要先clone gitlab仓库

sudo mkdir gitlab
sudo chmod -R 777 gitlab
cd /opt/gitlab
git clone https://gitlab.com/gitlab-org/gitlab-ce.git gitlab

2. 配置gitlab

sudo mkdir -p git
sudo chmod -R 755 git
sudo chown git:git git
cd /home/git
sudo -u git bash
exit 0
cd /opt/gitlab/config
cp gitlab.yml.example gitlab.yml
vim gitlab.yml

修改以下的bin_path路径为/usr/local/bin/使用从源码编译的git

git:
    bin_path: /usr/bin/git


评论