本文將教導您如何架設 Git Hosting Website,由於 Gitlab 是採用 Rails 框架開發,請先確定您的主機是否已建置 Rails 環境。
1. 下載並安裝 git-core
1 2 3 4 5 6 |
# wget https://git-core.googlecode.com/files/git-1.7.11.tar.gz # tar zxvf git-1.7.11.tar.gz # cd git-1.7.11 # ./configure # make # make install |
註:若要安裝 git 說明文件,請參考以下步驟
1 2 3 |
# yum install asciidoc xmlto # make man # make install-man |
2. 安裝 gitlab 所需套件 – Part.1
1 2 3 4 5 |
# yum install openssl openssl-devel zlib zlib-devel mysql mysql-devel sqlite sqlite-devel libicu-devel # wget http://peak.telecommunity.com/dist/ez_setup.py # python ez_setup.py # easy_install pip # pip install pygments |
3. 安裝 gitlab 所需套件 – Part.2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# wget https://redis.googlecode.com/files/redis-2.4.15.tar.gz # tar zxvf redis-2.4.15.tar.gz # cd redis-2.4.15 # make # mkdir /etc/redis /var/lib/redis # cp src/redis-server src/redis-cli /usr/local//bin/ # cp redis.conf /etc/redis/ # vim /etc/redis/redis.conf 將相關設定值修改如下: ● daemonize yes ● bind 127.0.0.1 (若要由其它電腦存取 redis 則不要修改此項目) ● loglevel notice ● logfile /var/log/redis.log ● dir /var/lib/redis |
1 2 3 4 5 6 |
# wget https://raw.github.com/gist/2986035/e64b4b8ad7d38676f7e7f70b24f3f004b4f10b74/redis-server # mv redis-server /etc/init.d # chmod 755 /etc/init.d/redis-server # chkconfig --add redis-server # chkconfig --level 345 redis-server on # service redis-server start |
4. 建立帳號 git 及 gitlab
1 2 |
# adduser -r -s /bin/sh -c 'git version control' -U -m git # adduser -c 'gitlab system' -U -m gitlab |
5. 設定帳號群組
1 |
# usermod -a -G git gitlab |
6. 修改資料夾權限
1 2 |
# chmod 755 /home/git # chmod 755 /home/gitlab |
7. 產生 gitlab 使用的 ssh 金鑰
1 |
# sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa |
8. 下載並安裝 gitolite
1 2 3 4 5 6 7 8 9 10 |
# cd /home/git # sudo -H -u git /usr/local/bin/git clone http://github.com/gitlabhq/gitolite /home/git/gitolite # sudo -u git sh -c 'echo -e "PATH=\$PATH:/home/git/bin\nexport PATH" > /home/git/.profile' # sudo -u git -i -H /home/git/gitolite/src/gl-system-install # cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub # chmod 777 /home/git/gitlab.pub # sudo -u git -H sed -i 's/0077/0007/g' /home/git/share/gitolite/conf/example.gitolite.rc # sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gl-setup -q /home/git/gitlab.pub" |
9. 修改資料夾權限及擁有者
1 2 |
# chmod -R g+rwX /home/git/repositories/ # chown -R git:git /home/git/repositories/ |
10. 測試 gitlab 是否可以正常下載 gitolite 管理檔案庫
1 2 3 4 |
# su - gitlab $ git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin $ rm -rf /tmp/gitolite-admin $ exit |
11. 設定 Gitlab
1 2 3 4 5 6 7 8 9 10 11 |
# gem install charlock_holmes # gem install bundler # su - gitlab $ git clone http://github.com/gitlabhq/gitlabhq.git gitlab $ cd gitlab $ cp config/gitlab.yml.example config/gitlab.yml 依照要使用的資料庫,下列指令擇一執行後,修改資料庫登入帳號及密碼 $ cp config/database.yml.sqlite config/database.yml (For SQLite) $ cp config/database.yml.mysql config/database.yml (For MySQL) |
12. 檢查及安裝 gitlab 所有依存的套件
1 |
$ bundle install --without development test --deployment |
13. 安裝資料庫
1 |
$ bundle exec rake gitlab:app:setup RAILS_ENV=production |
注意:安裝過程中如出現以下錯誤訊息,請確認 /home/gitlab/gitlab 中是否有 tmp 目錄,若無該目錄則手動建立,建立完畢後再次執行上述指令。
1 2 3 4 5 |
rake aborted! gitolite timeout Tasks: TOP => gitlab:app:setup => gitlab:app:enable_automerge (See full trace by running task with --trace) |
14. 確認狀態
1 |
$ bundle exec rake gitlab:app:status RAILS_ENV=production |
註:若出現類似如下訊息,代表環境正常無誤
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Starting diagnostic config/database.yml............exists config/gitlab.yml............exists /home/git/repositories/............exists /home/git/repositories/ is writable?............YES remote: Counting objects: 12, done. remote: Compressing objects: 100% (8/8), done. Receiving objects: 100% (12/12), 1.12 KiB, done. Resolving deltas: 100% (1/1), done. remote: Total 12 (delta 1), reused 0 (delta 0) Can clone gitolite-admin?............YES UMASK for .gitolite.rc is 0007? ............YES Finished |
15. 啟動伺服器測試
1 |
$ bundle exec rails s -e production |
預設帳號/密碼為:admin@local.host / 5iveL!fe
16. 測試無誤後可使用 Passenger 來佈署 Gitlab
注意:使用 Passenger 佈署後若在網頁上出現錯誤訊息 No such file or directory – git ls-files 請執行以下指令
1 |
# ln -ns /usr/local/bin/git /usr/bin/git |
備註:若需啟用 Gitlab 的 automerge 功能,請執行以下指令
1 |
$ bundle exec rake gitlab:app:enable_automerge RAILS_ENV=production |
評論
此文章尚無評論。