FreeBSD 安裝Gitlab 4.1

GitLab

logoGitLab 是一套webbase的管理系統,與有名的github 非常類似.
特性 快速, 安全與穩定的方案使用 Rails & Gitolite開發,並且使用MIT License授權.
如果這樣還沒有概念那就看看官網的 screenshots.
再來看怎摸安裝…
FreeBSD官網不支援,觀玩建議安裝使用Debian/Ubuntu 其他如RedHat linux bases都有人安裝成功過.
就是沒有FreeBSD!!!!!!!!!阿阿阿阿阿阿阿阿阿阿

再來只好花費週末8個小時撞牆來安裝.

開始安裝GitLab on FreeBSD

請一邊服用官網的安裝說明.
開始先把該裝的東西先裝完.(這邊可是撞牆的到的結論)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cd /usr/ports/security/sudo  ; make install clean ; rehash
cd /usr/ports/devel/autoconf ; make install clean
cd /usr/ports/devel/git ; make install clean
cd /usr/ports/devel/py-pip ; make install clean
cd /usr/ports/textproc/py-pygments ; make install clean
cd /usr/ports/databases/redis ; make install celan
cd /usr/ports/lang/ruby19 ; make install clean
#這邊安裝好後 必須先編輯 /etc/make.conf 加入ruby 設定
# RUBY_VERSION=1.9.3
# RUBY_DEFAULT_VER=1.9
cd /usr/ports/ftp/curl ; make install clean ; rehash
cd /usr/ports/shells/bash ; make install clean ; rehash
#做一下link
ln -s /usr/local/bin/bash /bin/bash
cd /usr/ports/devel/ruby-gems ; make install clean
cd /usr/ports/databases/postgresql-plruby ; make install clean
#安裝 gitolite
cd /usr/ports/devel/gitolite ; make install clean;

安裝好的gitolite本來是要馬上生成ssh public key作為admin.
但是gitolite現在必須交由gitlab控管所以必須使用gitlab 使用者作為admin.
建立新使用者gitlab

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
$ adduser gitlab
Username: gitlab
Full name: GitLab
Uid (Leave empty for default): 
Login group [gitlab]: git #必須與git 同群組
Login group is git. Invite gitlab into other groups? []: 
Login class [default]: 
Shell (sh csh tcsh zsh rzsh git-shell bash rbash nologin) [sh]: 
Home directory [/home/gitlab]: 
Home directory permissions (Leave empty for default): 
Use password-based authentication? [yes]: no
Lock out the account after creation? [no]: 
Username   : gitlab
Password   : <disabled>
Full Name  : GitLab
Uid        : 1003
Class      : 
Groups     : git 
Home       : /home/gitlab
Home Mode  : 
Shell      : /bin/sh
Locked     : no
OK? (yes/no): yes
adduser: INFO: Successfully added (gitlab) to the user database.
Add another user? (yes/no): no
Goodbye!
#切換到 gitlab 使用者
$ su gitlab
$ cd ~
#產生ssh key
$ ssh-keygen -q -N '' -t rsa
Enter file in which to save the key (/home/gitlab/.ssh/id_rsa): 
$ cd .ssh/
#先丟到 /tmp 等等要給gitolite 作為admin
$ cp id_rsa.pub /tmp/gitlab.pub
$ exit
#補充 root key也必須是admin
$ cp ~/.ssh/id_rsa.pub /tmp/admin2.pub
#切換回git使用者
$ su git
$ touch /usr/local/git/.ssh/authorized_keys
$ chmod 644 /usr/local/git/.ssh/authorized_keys
$ cd /tmp
#設定gitolite admin
$ /usr/local/bin/gitolite setup -pk /tmp/gitlab.pub
$ /usr/local/bin/gitolite setup -pk /tmp/admin2.pub
# 設定git使用者環境
$ cd ~
$ mkdir bin
$ gitolite/install -ln ~/bin/
#編輯.profile
# PATH=$PATH:/usr/local/git/bin
# export PATH
$ exit

開始設定gitlab

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
#先連線一次
$ ssh git@localhost
#切換回gitlab使用者
$ su gitlab
#先連線一次
$ ssh git@localhost
$ cd ~
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
$ cd /home/gitlab/gitlab
$ git checkout 4-1-stable
$ cp config/gitlab.yml.example config/gitlab.yml
$ cp config/database.yml.mysql config/database.yml
#編輯好個上述設定檔
$ mkdir /home/gitlab/gitlab-satellites
$ chown -R gitlab log/
$ chown -R gitlab tmp/
$ chmod -R u+rwX  log/
$ chmod -R u+rwX  tmp/
#編輯 Gemfile line:104
$ vim Gemfile
 gem "therubyracer",
#改為下列
 gem "therubyracer", ref: "4c58fff920fd939395a71db62abecd3a58e512ef", git: "https://github.com/cowboyd/                therubyracer.git"
#這樣會重置Gemfile
$ bundle install --no-deployment
#安裝
$ gem install charlock_holmes --version '0.6.9'
$ bundle install --deployment --without development test postgres
#設定gitolite hook
$ cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive
$ chown git:git /home/git/.gitolite/hooks/common/post-receive
#安裝初始化DB
$ bundle exec rake gitlab:setup RAILS_ENV=production
..
.
.
.
login.........admin@local.host
password......5iveL!fe
 
$

gitlab Nginx設定

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
upstream gitlab {
  server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;
}
 
server {
  listen 80 default_server;         # e.g., listen 192.168.1.1:80;
  server_name gitlab.xxxxxxx;     # e.g., server_name source.example.com;
  root /home/gitlab/gitlab/public;
 
  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;
 
  location / {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
  }
 
  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location @gitlab {
    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_redirect     off;
 
    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;
 
    proxy_pass http://gitlab;
  }
}

啟動gitlab

1
2
3
4
#必需以root身分執行
$ cd /home/gitlab/gitlab
$ bundle exec rake sidekiq:start
$ bundle exec unicorn_rails -c /home/gitlab/gitlab/config/unicorn.rb -E production -D

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *