GitLab on FreeBSD

vermaden1 pts0 comments

GitLab on FreeBSD | ๐šŸ๐šŽ๐š›๐š–๐šŠ๐š๐šŽ๐š—

Today I will share how to install and setup a GitLab server on FreeBSD. Most people just use Microslopft GitHub these days but this approach has one big drawback โ€“ its cloud only solution. When it comes to on premise solutions there are GitLab and there is also Gitea. GitLab is closest to what GitHub provides while Gitea is very light and smaller brother trying to achieve the same goals by doing less. Good to have alternatives.

The Table of Contents is more or less like that:

Bhyve VM

Packages

PostgreSQL

Redis

GitLab

Nginx

Final GitLab Tweaks

GitLab Web Interface

Summary

We will use a dedicated Bhyve VM for that โ€“ with sysutils/vm-bhyve-devel help.

Bhyve VM

We will also use FreeBSD project provided ready to use FreeBSD-15.1-RELEASE-amd64-zfs.raw.xz VM image.

host # vm create -t freebsd gitlab

host # env EDITOR=cat vm config gitlab<br>loader="bhyveload"<br>cpu=4<br>memory=16G<br>network0_type="virtio-net"<br>network0_switch="public"<br>network0_mac="58:9c:fc:01:fb:f8"<br>disk0_type="nvme"<br>disk0_name="disk0.img"<br>uuid="15cd2fff-7942-4ca4-a29f-6ed48f063371"

host # xz -d -c FreeBSD-15.1-RELEASE-amd64-zfs.raw.xz > /vm/gitlab/disk0.img

host # truncate -s 30g /vm/gitlab/disk0.img

host # vm start gitlab<br>Starting gitlab<br>* found guest in /vm/gitlab<br>* booting...

host # vm console gitlab

login: root

root@gitlab:~ # :> ~/.hushlogin

root@gitlab:~ # gpart show -p<br>=> 34 62914486 nda0 GPT (30G)<br>34 347 nda0p1 freebsd-boot (174K)<br>381 66584 nda0p2 efi (33M)<br>66965 2097152 nda0p3 freebsd-swap (1.0G)<br>2164117 60750403 nda0p4 freebsd-zfs (29G)

To expand the disk/partition/pool this is the guide You are looking for โ€“ Expand GELI Encrypted Bhyve VM ZFS Disk โ€“ just omit the GELI part as its not used here.

Back to the VM configuration.

root@gitlab:~ # cat /etc/rc.conf<br># NETWORK<br>hostname="gitlab.local"<br>ifconfig_vtnet0="inet 10.1.1.44/24 up"<br>defaultrouter="10.1.1.1"

# DAEMONS<br>zfs_enable="YES"

root@gitlab:~ # sed -i '' s/quarterly/latest/g /etc/pkg/FreeBSD.conf

root@gitlab:~ # echo nameserver 1.1.1.1 > /etc/resolv.conf

root@gitlab:~ # netstat -Win -f inet<br>Name Mtu Network Address Ipkts Ierrs Idrop Opkts Oerrs Coll<br>vtnet0 - 10.1.1.0/24 10.1.1.44 905 - - 466 - -<br>lo0 - 127.0.0.0/8 127.0.0.1 633774 - - 633774 - -

Packages

Needed packages installation.

root@gitlab:~ # \<br>pkg install -y \<br>gitlab-ce \<br>postgresql18-server \<br>postgresql18-client \<br>postgresql18-contrib \<br>nginx \<br>redis

PostgreSQL

Now PostgreSQL database setup.

root@gitlab:~ # service postgresql enable<br>root@gitlab:~ # service postgresql initdb<br>root@gitlab:~ # service postgresql start<br>root@gitlab:~ # psql -d template1 -U postgres -c "CREATE USER git CREATEDB SUPERUSER PASSWORD 'password';"<br>root@gitlab:~ # psql -d template1 -U postgres -c "CREATE DATABASE gitlabhq_production OWNER git;"

Now lets try to connect to new database with new user.

root@gitlab:~ # psql -U git -d gitlabhq_production<br>psql (18.4)<br>Type "help" for help.

gitlabhq_production=#

Seems to work.

Now connect to PostgreSQL GitLab database and enable pg_trgm extension.

root@gitlab:~ # psql -U postgres -d gitlabhq_production -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"<br>root@gitlab:~ # psql -U postgres -d gitlabhq_production -c "CREATE EXTENSION IF NOT EXISTS btree_gist;"<br>root@gitlab:~ # psql -U postgres -d gitlabhq_production -c "CREATE EXTENSION IF NOT EXISTS plpgsql;"

Next enable 200 connections to PostgreSQL database.

root@gitlab:~ # psql -U postgres -c "ALTER SYSTEM SET max_connections TO '200';"<br>root@gitlab:~ # psql -U postgres -c "SELECT pg_reload_conf();"<br>root@gitlab:~ # service postgresql restart

Verify it is now set to 200.

root@gitlab:~ # psql -U postgres -c "show max_connections;"<br>max_connections<br>200<br>(1 row)

Redis

Setup Redis config.

root@gitlab:~ # echo 'unixsocket /var/run/redis/redis.sock' >> /usr/local/etc/redis.conf

Grant permission to socket to all members of the redis group.

root@gitlab:~ # echo 'unixsocketperm 770' >> /usr/local/etc/redis.conf

Add git user to redis group.

root@gitlab:~ # pw groupmod redis -m git

Allow Redis to be started and start it.

root@gitlab:~ # service redis enable<br>root@gitlab:~ # service redis start

GitLab

Find number of CPU cores.

root@gitlab:~ # sysctl hw.ncpu<br>hw.ncpu: 4

Change amount of workers to 4 next.

root@gitlab:~ # grep '^workers' /usr/local/www/gitlab/config/puma.rb<br>workers 4

Configure Git global settings for git user.

root@gitlab:~ # su -l git -c "git config --global core.autocrlf input"

Disable 'git gc --auto' because GitLab already runs 'git gc' when needed.

root@gitlab:~ # su -l git -c "git config --global gc.auto 0"

Enable packfile bitmaps.

root@gitlab:~ # su -l git -c "git config --global repack.writeBitmaps true"

Enable push options.

root@gitlab:~ # su -l git -c "git config --global receive.advertisePushOptions true"

Enable fsyncObjectFiles to reduce risk of repository corruption if server crashes.

root@gitlab:~ # su -l git -c "git config --global core.fsync...

gitlab root redis freebsd psql postgresql

Related Articles