前言
環境參數:
- OS:FreeBSD i386 , 10.3-RELEASE-p11
- CPU:Intel(R) Core(TM)2 Duo CPU @ 3.00GHz
- RAM:4096 MB
Gitlab需要以下的系統元件
要正常運作 Gitlab ,依照文件所載明,系統上需安裝以下的元件並能正常運行。
- Packages / Dependencies
- Ruby
- System Users
- Database
- Redis
- GitLab
- Nginx
安裝必要套件
更新系統符合utf-8
$ pkg update
$ pkg upgrade
安裝系統套件
以下的指令是一次下達完成,當然也可以一個個的下(略過已經安裝或不想升級的套級)
$ pkg install sudo bash icu cmake pkgconf git nginx node ruby ruby22-gems logrotate redis postgresql95-server postgresql95-contrib postfix krb5 gmake go
設定gem
$ gem install bundler --no-ri --no-rdoc
Fetching: bundler-1.14.3.gem (100%)
Bundler and RubyGems.org are free for anyone to use, but maintaining them costs more than $25,000 USD every month. Help us cover those costs so that we can keep the gem ecosystem free for everyone: https://ruby.to/support-bundler
Successfully installed bundler-1.14.3
1 gem installed
設定 /etc/rc.conf
$ vi /etc/rc.conf
sshd_enable="YES"
ntpd_enable="YES"
ntpd_sync_on_start="YES"
redis_enable="YES"
postgresql_enable="YES"
gitlab_enable="YES"
nginx_enable="YES"
postfix_enable="YES"
sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
設定 Git
新增git相關使用者及組群
直接以管理者身份進行定比方便,su -l或sudo -s
$ pw add user -n git -m -s /usr/local/bin/bash -c "GitLab"
$ pw groupmod redis -m git
設定 Postgres 資料庫
$ service postgresql initdb
$ service postgresql start
$ su - pgsql
$ psql -d template1
連接Postgres資料庫後,進行下列設定:
‘template1=#’是系統提示符號,不需要輸入.
template1=
template1=
template1=
template1=
設定 Redis
先備份原始設定/usr/local/etc/redis.conf。
$ cp /usr/local/etc/redis.conf /usr/local/etc/redis.conf.orig
redis.conf相關設定
修正 redis.conf的 port預設值,變更為0:
$ vi /usr/local/etc/redis.conf
port 0
Redis socket設定,
確定設定檔/usr/local/etc/redis.conf最後三行中的unixsocket對應值:
aof-rewrite-incremental-fsync yes
unixsocket /usr/local/var/run/redis/redis.sock
unixsocketperm 770
如果沒有這行設定,則利用下面指令達成:
echo 'unixsocket /usr/local/var/run/redis/redis.sock' | sudo tee -a /usr/local/etc/redis.conf
再來,確認權限:
aof-rewrite-incremental-fsync yes
unixsocket /usr/local/var/run/redis/redis.sock
unixsocketperm 770
如果沒有這行設定,則利用下面指令達成:
echo 'unixsocketperm 770' | sudo tee -a /usr/local/etc/redis.conf
設定相關目錄,
$ mkdir -p /usr/local/var/run/redis
$ chown redis:redis /usr/local/var/run/redis
$ chmod 755 /usr/local/var/run/redis
啟動 redis
$ sudo service redis restart
安裝並設定 GitLab
$ cd /home/git
$ sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-10-stable gitlab
$ cd /home/git/gitlab
$ sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
$ sudo -u git -H vim config/gitlab.ym
- host: git.mydomain #設定為自己的gitlab server網址名稱
- bin_path: /usr/local/bin/git #設定git的路徑
- 將所有的/home/git,變更實際系統路徑/usr/home/git, 視使用者家目錄的初始設定來彈性變更, 符號連結性的目錄名稱是無法運行的,故要變更為實際路徑.
接著,以root執行下列命令:
設定Gitlab Workhorse
$ cd /home/git
$ sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
cd gitlab-workhorse
$ sudo -u git -H git checkout v0.7.9
$ sudo -u git -H gmake
初始化GitLab資料庫
初始化資料庫,並開啟進階功能。
先確定config.yml的redis.sock路徑是否正確:
$ vi /home/git/gitlab/config/resque.yml
production: unix:/usr/local/var/run/redis/redis.sock
否則在建立資料表時會出現錯誤訊息:
rake aborted!
Errno::ENOENT: No such file or directory - connect(2) for /usr/local/usr/local/var/run/redis/redis.sock
/data/git/gitlab/vendor/bundle/ruby/2.2/gems/redis-3.2.2/lib/redis/connection/ruby.rb:180:in `connect_nonblock'
/data/git/gitlab/vendor/bundle/ruby/2.2/gems/redis-3.2.2/lib/redis/connection/ruby.rb:180:in `connect'
$ cd /home/git/gitlab
$ sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
Administrator 密碼設定及變更方式
- *第一次登入 GitLab 時會強制變更預設密碼。
- 如果想預先設定密碼,可在安裝時以參數GITLAB_ROOT_PASSWORD設定:
$ sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword
開機自動執行 GitLab
以root權限下載 FreeBSD的命令腳本,再置於* /usr/local/etc/rc.d*目錄下即可。
$ sudo cp ~git/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab
$ sudo chmod 555 /usr/local/etc/rc.d/gitlab
檢查設定並編譯執行檔
設定 GitLab 環境變數,
$ cd /home/git/gitlab
$ sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System:
Current User: git
Using RVM: no
Ruby Version: 2.2.6p396
Gem Version: 2.6.4
Bundler Version:1.14.3
Rake Version: 10.5.0
Sidekiq Version:4.1.4
GitLab information
Version: 8.10.13
Revision: c593548717
Directory: /data/git/gitlab
DB Adapter: postgresql
URL: http://git.twbest.biz
HTTP Clone URL: http://git.twbest.biz/some-group/some-project.git
SSH Clone URL: git@git.twbest.biz:some-group/some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 3.2.1
Repository storage paths:
- default: /data/git/repositories/
Hooks: /data/git/gitlab-shell/hooks/
Git: /usr/local/bin/git
順利看到成果後,就可以進行下一步的編譯工作,這會花一點時間,先喝杯咖啡,等會兒再回來看,依我的機器大概跑了10分鐘。
$ sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
$ sudo -u git -H RAILS_ENV=production bin/background_jobs start
啟動 GitLab
Start GitLab service
來到這個階段,總算大功完成,接下來就以git使用者權限啟動 GitLab 服務,否則會出現錯誤訊息而致無法啟動。
$ sudo -u git /usr/local/etc/rc.d/gitlab start
GitLab is not running.
Starting GitLab Unicorn
Starting GitLab Sidekiq
Starting gitlab-workhorse
.
The GitLab Unicorn web server with pid 49327 is running.
The GitLab Sidekiq job dispatcher with pid 49364 is running.
The gitlab-workhorse with pid 49349 is running.
GitLab and all its components are up and running.
設定Nginx
在FreeBSD下,Nginx 的預設值是沒有啟用 gzip_static 模組,所以要手動啟用。
$ sudo mkdir -p /usr/local/etc/nginx/conf.d
$ sudo mkdir -p /usr/local/etc/nginx/ssl
$ sudo mkdir -p /var/log/nginx
$ sudo fetch -o /usr/local/etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab-ssl
$ sudo fetch -o /usr/local/etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab
編輯/usr/local/etc/nginx/nginx.conf 設定檔:
$ sudo vi /usr/local/etc/nginx/nginx.conf
load_module /usr/local/libexec/nginx/ngx_mail_module.so;
load_module /usr/local/libexec/nginx/ngx_stream_module.so;
編輯/usr/local/etc/nginx/conf.d/gitlab.conf*設定檔:
server_name YOUR_SERVER_FQDN;
測試 Nginx的組態設定是否正常?
$ sudo nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
看到測試成功了,就可以重新啟動 Nginx 服務。
$ sudo service nginx start
完成安裝 GitLab
最後,再次確認GitLab的設定一切正常,
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
依照畫面指示命令,來修復該修正或更改之處。接著在瀏覽器訪問Nginx設定 /usr/local/etc/nginx/conf.d/gitlab.conf中所設定的YOUR_SERVER_FQDN網址(http://your_server_fqdn)即可登入GitLab,首次登入按本例則必需要變更root(登入名稱)的密碼。
參考來源
https://github.com/gitlabhq/gitlabhq/blob/7-6-stable/doc/install/installation.md
本文大網