Source : https://raw.githubusercontent.com/gitlabhq/gitlab-recipes/master/install/freebsd/freebsd-10.md
1. Update system
1 2 |
<span>pkg update</span> <span>pkg upgrade</span> |
2. Install dependencies
1 2 |
<span>pkg install sudo bash icu cmake pkgconf git go nginx node ruby ruby21-gems logrotate redis postgresql94-server postgresql94-contrib postfix krb5</span> <span>gem install bundler --no-ri --no-rdoc</span> |
Add this to /etc/rc.conf:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<span># GitLab services</span> <span>redis_enable="YES"</span> <span>postgresql_enable="YES"</span> <span>gitlab_enable="YES"</span> <span># Web server</span> <span>nginx_enable="YES"</span> <span># Postfix/Sendmail</span> <span>postfix_enable="YES"</span> <span>sendmail_enable="NO"</span> <span>sendmail_submit_enable="NO"</span> <span>sendmail_outbound_enable="NO"</span> <span>sendmail_msp_queue_enable="NO"</span> |
3. Create git user
Create user git :
1 |
<span>pw add user -n git -m -s /usr/local/bin/bash -c "GitLab"</span> |
Add git user to redis group :
1 |
<span>pw user mod git -G redis</span> |
4. Set up Postgres database
As root, make sure that Postgres is running:
1 |
<span>service postgresql start</span> |
Set up the database:
1 2 3 4 5 6 7 8 9 10 11 |
<span># Initialize First start of PG DB</span> <span>service postgresql initdb</span> <span># Initialise Postgres db</span> <span>service postgresql start</span> <span># Log in to Postgres user account</span> <span>su - pgsql</span> <span># Connect to Postgres database</span> <span>psql -d template1</span> |
When logged into the database:
1 2 3 4 5 6 7 8 9 10 11 |
<span># Create a user for GitLab</span> <span>template1=# CREATE USER git CREATEDB;</span> <span># Create the GitLab production database & grant all privileges on database</span> <span>template1=# CREATE DATABASE gitlabhq_production OWNER git encoding='UTF8';</span> <span># Create extension</span> <span>CREATE EXTENSION pg_trgm;</span> <span># Quit the database session</span> <span>template1=# \q</span> |
Then type exit to drop back to the root user. Try connecting to the new database with the git user:
1 2 3 |
<span>su - git</span> <span>psql -d gitlabhq_production</span> <span>CREATE EXTENSION pg_trgm;</span> |
If this succeeds, quit the database session by typing \q
or hitting CTRL-D.
5. Install and set up Redis
Back up the original Redis config file:
1 |
<span>cp /usr/local/etc/redis.conf /usr/local/etc/redis.conf.orig</span> |
Edit /usr/local/etc/redis.conf to obtain:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
<span>unixsocket /usr/local/var/run/redis/redis.sock</span> <span>unixsocketperm 770</span> <span>daemonize yes</span> <span>pidfile /var/run/redis/redis.pid</span> <span>port 6379</span> <span>tcp-backlog 511</span> <span>timeout 0</span> <span>tcp-keepalive 0</span> <span>loglevel notice</span> <span>logfile /var/log/redis/redis.log</span> <span>databases 16</span> <span>save 900 1</span> <span>save 300 10</span> <span>save 60 10000</span> <span>stop-writes-on-bgsave-error yes</span> <span>rdbcompression yes</span> <span>rdbchecksum yes</span> <span>dbfilename dump.rdb</span> <span>dir /var/db/redis/</span> <span>slave-serve-stale-data yes</span> <span>slave-read-only yes</span> <span>repl-diskless-sync no</span> <span>repl-diskless-sync-delay 5</span> <span>repl-disable-tcp-nodelay no</span> <span>slave-priority 100</span> <span>appendonly no</span> <span>appendfilename "appendonly.aof"</span> <span>appendfsync everysec</span> <span>no-appendfsync-on-rewrite no</span> <span>auto-aof-rewrite-percentage 100</span> <span>auto-aof-rewrite-min-size 64mb</span> <span>aof-load-truncated yes</span> <span>lua-time-limit 5000</span> <span>slowlog-log-slower-than 10000</span> <span>slowlog-max-len 128</span> <span>latency-monitor-threshold 0</span> <span>notify-keyspace-events ""</span> <span>hash-max-ziplist-entries 512</span> <span>hash-max-ziplist-value 64</span> <span>list-max-ziplist-entries 512</span> <span>list-max-ziplist-value 64</span> <span>set-max-intset-entries 512</span> <span>zset-max-ziplist-entries 128</span> <span>zset-max-ziplist-value 64</span> <span>hll-sparse-max-bytes 3000</span> <span>activerehashing yes</span> <span>client-output-buffer-limit normal 0 0 0</span> <span>client-output-buffer-limit slave 256mb 64mb 60</span> <span>client-output-buffer-limit pubsub 32mb 8mb 60</span> <span>hz 10</span> <span>aof-rewrite-incremental-fsync yes</span> |
Then:
1 2 3 |
<span>mkdir -p /usr/local/var/run/redis</span> <span>chown redis:redis /usr/local/var/run/redis</span> <span>chmod 755 /usr/local/var/run/redis</span> |
And we restart Redis:
1 |
service redis restart |
6. Install and set up GitLab
Change to git home directory:
1 |
<span>cd /home/git</span> |
Clone GitLab source:
1 |
<span>sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-7-stable gitlab</span> |
Go to GitLab source folder:
1 |
<span>cd /home/git/gitlab</span> |
Copy the example GitLab config:
1 |
<span>sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml</span> |
Edit the GitLab configuration file:
1 |
<span>sudo -u git -H vim config/gitlab.yml</span> |
The option host: should be set to your domain, e.g. “gitlab.mysite.com”.
The line bin_path: should be set to FreeBSD’s git location: /usr/local/bin/git.
Change /home/ to be /usr/home/ (home is a symbolic link that doesn’t work)
As root:
1 2 3 4 5 |
<span>cd /home/git/gitlab</span> <span>chown -R git log/</span> <span>chown -R git tmp/</span> <span>chmod -R u+rwX,go-w log/</span> <span>chmod -R u+rwX tmp/</span> |
Make folder for satellites and set the right permissions:
1 2 |
<span>sudo -u git -H mkdir /home/git/gitlab-satellites</span> <span>sudo -u git -H chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites</span> |
Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories:
1 2 |
<span>sudo -u git -H chmod -R u+rwX tmp/pids/</span> <span>sudo -u git -H chmod -R u+rwX tmp/sockets/</span> |
Make sure GitLab can write to the public/uploads/ directory:
1 2 |
<span>mkdir -p public/uploads</span> <span>sudo -u git -H chmod -R u+rwX public/uploads</span> |
Copy the example Unicorn config:
1 |
<span>sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb</span> |
Set the number of workers to at least the number of cores:
1 |
<span>sudo -u git -H vim config/unicorn.rb</span> |
Copy the example Rack attack config:
1 |
<span>sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb</span> |
Configure Git global settings for git user, useful when editing via web
1 2 3 4 |
<span># Edit user.email according to what is set in gitlab.yml</span> <span>sudo -u git -H git config --global user.name "GitLab"</span> <span>sudo -u git -H git config --global user.email "example@example.com"</span> <span>sudo -u git -H git config --global core.autocrlf input</span> |
Copy Redis connection settings:
1 |
<span>sudo -u git -H cp config/resque.yml.example config/resque.yml</span> |
Configure Redis to use the modified socket path:
1 2 |
<span># Change 'production' line to 'unix:/usr/local/var/run/redis/redis.sock'</span> <span>sudo -u git -H vim config/resque.yml</span> |
Copy database config:
1 |
<span>sudo -u git -H cp config/database.yml.postgresql config/database.yml</span> |
Install Ruby Gems:
1 |
<span>sudo -u git -H bundle install --deployment --without development test mysql aws</span> |
7. GitLab Shell
Run the rake task for installing gitlab-shell:
1 |
<span>sudo -u git -H bundle exec rake gitlab:shell:install[v2.4.1] REDIS_URL=unix:/usr/local/var/run/redis/redis.sock RAILS_ENV=production</span> |
Edit the gitlab-shell config:
1 2 3 4 5 |
<span># Change /home/* to be /usr/home/* (home is a symbolic link that doesn't work)</span> <span># Change the 'socket' option to '/usr/local/var/run/redis/redis.sock'</span> <span># Change the 'gitlab_url' option to 'http://localhost:8080/'</span> <span># Don't bother configuring any SSL stuff in here because it's used internally</span> <span>sudo -u git -H vim /home/git/gitlab-shell/config.yml</span> |
8. Initialise Database
Initialize Database and Activate Advanced Features:
1 2 3 |
<span>sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword</span> <span># Type 'yes' to create the database tables.</span> <span># When done you see 'Administrator account created:'</span> |
9. Init script
Download the FreeBSD init script as root:
1 |
<span>wget -O /usr/local/etc/rc.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/init/freebsd/gitlab-unicorn</span> |
10. Check Configuration and Compile Assets
1 2 |
<span>cd /home/git/gitlab</span> <span>sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production</span> |
If this all passes (all green and/or no errors are reported), then go ahead and compile all of the assets for GitLab. This can take ~10-15 minutes on a smaller machine, so don’t panic if it takes a while!
1 |
<span>sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production</span> |
11. Start GitLab service
As root:
1 |
<span>service gitlab start</span> |
12. Nginx
You might want to create /usr/local/etc/nginx/conf.d/ and include it in nginx.conf first.
1 |
<span>wget -O /usr/local/etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab</span> |
Edit /usr/local/etc/nginx/conf.d/gitlab.conf and replace git.example.com with your FQDN. Make sure to read the comments in order to properly set up SSL.
Add nginx user to git group:
1 2 |
<span>pw usermod -a -G git nginx</span> <span>chmod g+rx /home/git/</span> |
Finally start nginx with:
1 |
<span>service nginx start</span> |
Troubleshooting
504 – Gateway Timed Out errors
- Check the logs! Look in /home/git/gitlab/log for clues.
- Check what’s running! The command sockstat -4l usually gives an idea of which services are running on which ports. (Redis uses port
6379
, Unicorn uses port8080
, and Postgres uses port5432
).
What it usually boils down to:
- GitLab’s assets haven’t been precompiled (there is a command above)
- Postgres isn’t running or the database isn’t set up properly
- Redis isn’t running
- Nginx isn’t set up properly
Unicorn / nginx: “Failed to set accept_filter=httpready”
This is to do with an HTTP buffering kernel module in FreeBSD that some HTTP servers expect to be loaded. Run this:
1 2 3 4 5 6 |
<span>kldload accf_http</span> <span>echo 'accf_http_load="YES"' >> /boot/loader.conf</span> <span>sudo service gitlab restart</span> <span>sudo service redis restart</span> <span>sudo service nginx restart</span> |