1. 安裝依賴包
請(qǐng)記住,Debian 默認(rèn)并沒(méi)有安裝 sudo,請(qǐng)使用 root 安裝它:
apt-get update apt-get upgrade apt-get install sudo
現(xiàn)在你可以安裝必須包:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y wget curl gcc checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libreadline6-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip libyaml-dev postfix libpq-dev
數(shù)據(jù)庫(kù)
SQLite
sudo apt-get install -y sqlite3 libsqlite3-dev
MySQL
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
# Login to MySQL
$ mysql -u root -p
# Create the GitLab production database
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# Create the MySQL User change $password to a real password
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password';
# Grant proper permissions to the MySQL User
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
PostgreSQL
sudo apt-get install -y postgresql-9.2 postgresql-server-dev-9.2
# Connect to database server
sudo -u postgres psql -d template1
# Add a user called gitlab. Change $password to a real password
template1=# CREATE USER gitlab WITH PASSWORD '$password';
# Create the GitLab production database
template1=# CREATE DATABASE IF NOT EXISTS gitlabhq_production;
# Grant all privileges on database
template1=# GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production to gitlab;
# Quit from PostgreSQL server
template1=# \q
# Try connect to new database
$ su - gitlab
$ psql -d gitlabhq_production -U gitlab
(譯者注:以上3種數(shù)據(jù)庫(kù)根據(jù)需要安裝其一即可)
2. 安裝 Ruby
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar xfvz ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194
./configure
make
sudo make install
3. 安裝 Gitolite
為 Git 創(chuàng)建用戶:
sudo adduser \
--system \
--shell /bin/sh \
--gecos 'git version control' \
--group \
--disabled-password \
--home /home/git \
git
為 GitLab 創(chuàng)建用戶:
# ubuntu/debian
sudo adduser --disabled-login --gecos 'gitlab system' gitlab
將 gitlab 用戶添加到 git 用戶組:
sudo usermod -a -G git gitlab
將 git 用戶添加到 gitlab 用戶組:
sudo usermod -a -G gitlab git
生成密鑰:
sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa
克隆 GitLab 的 Gitolite 分支源代碼:
sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite
安裝:
cd /home/git
sudo -u git -H mkdir bin
sudo -u git sh -c 'echo -e "PATH=\$PATH:/home/git/bin\nexport PATH" >> /home/git/.profile'
sudo -u git sh -c 'gitolite/install -ln /home/git/bin'
sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
sudo chmod 0444 /home/git/gitlab.pub
sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"
權(quán)限:
sudo chmod -R g+rwX /home/git/repositories/
sudo chown -R git:git /home/git/repositories/
檢查:退出并重新登錄以使 git 用戶組生效
# 克隆 admin 資源庫(kù)以將 localhost 添加到 known_hosts
# 并且確認(rèn) gitlab 用戶有權(quán)訪問(wèn) gitolite
sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin
# 如果執(zhí)行成功,你可以將其刪除
sudo rm -rf /tmp/gitolite-admin
重要! 如果你不能克隆 gitolite-admin 資源庫(kù),請(qǐng)不要繼續(xù)本次安裝,請(qǐng)根據(jù) Trouble Shooting Guide 并且確認(rèn)你已經(jīng)小心的完成上文的全部步驟。
筆者注:這一步測(cè)試能否克隆成功。本人沒(méi)有注意這個(gè)提示,完成后續(xù)安裝后發(fā)現(xiàn)怎么都不能通過(guò)git@localhost:gitolite-admin.git的方式克隆工程,原因就是ssh認(rèn)證失敗,所以請(qǐng)務(wù)必確認(rèn)這一點(diǎn)。順便說(shuō)下本人ssh認(rèn)證失敗的原因: /etc/ssh/sshd_config配置文件里面PubkeyAuthentication的值為no,意味著不允許公鑰認(rèn)證,改為yes就可以了。如果還是不能克隆,重復(fù)下第3步,并且注意每個(gè)命令是否執(zhí)行成功?;蛘邉h除git和gitlab用戶,重新執(zhí)行第3步。
4. 克隆 GitLab 源代碼并安裝先決條件
sudo gem install charlock_holmes --version '0.6.8'
sudo pip install pygments
sudo gem install bundler
cd /home/gitlab
# Get gitlab code. Use this for stable setup
sudo -H -u gitlab git clone -b stable https://github.com/gitlabhq/gitlabhq.git gitlab
(2013/1/6,最近發(fā)現(xiàn)最新的版本是4.0.0.rc2,這個(gè)版本已經(jīng)沒(méi)有支持sqlite,而我選擇sql數(shù)據(jù)庫(kù)的時(shí)候沒(méi)有成功,
克隆之后執(zhí)行、
sudo -u gitlab git checkout 2.9.1
可以回到2.9.1的版本,這個(gè)版本既支持sqlite,其gitlab管理界面也較美觀。3.1.0以后的版本管理界面都有點(diǎn)難看。)
# Skip this for stable setup.(筆者注:執(zhí)行了上個(gè)命令就不用執(zhí)行這個(gè)命令了)
# Master branch (recent changes, less stable)
sudo -H -u gitlab git clone -b master https://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab
# Rename config files
sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml
選擇你希望使用的數(shù)據(jù)庫(kù)
筆者注:建議選擇SQLite
# SQLite
sudo -u gitlab cp config/database.yml.sqlite config/database.yml
# Mysql
sudo -u gitlab cp config/database.yml.mysql config/database.yml
# PostgreSQL
sudo -u gitlab cp config/database.yml.postgres config/database.yml
# 修改 config/database.yml 確認(rèn)輸入了正確的用戶名/密碼
安裝數(shù)據(jù)庫(kù) gems
# mysql
sudo -u gitlab -H bundle install --without development test sqlite postgres --deployment
# 或者 postgres
sudo -u gitlab -H bundle install --without development test sqlite mysql --deployment
# 或者 sqlite
sudo -u gitlab -H bundle install --without development test mysql postgres --deployment
初始化數(shù)據(jù)庫(kù)
sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production
設(shè)置 GitLab hooks
sudo cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive
sudo chown git:git /home/git/.gitolite/hooks/common/post-receive
確認(rèn)應(yīng)用程序狀態(tài):
sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production
# OUTPUT EXAMPLE
Starting diagnostic
config/database.yml............exists
config/gitlab.yml............exists
/home/git/repositories/............exists
/home/git/repositories/ is writable?............YES
remote: Counting objects: 603, done.
remote: Compressing objects: 100% (466/466), done.
remote: Total 603 (delta 174), reused 0 (delta 0)
Receiving objects: 100% (603/603), 53.29 KiB, done.
Resolving deltas: 100% (174/174), done.
Can clone gitolite-admin?............YES
UMASK for .gitolite.rc is 0007? ............YES
/home/git/share/gitolite/hooks/common/post-receive exists? ............YES
筆者注:如果所有結(jié)果都是 YES,恭喜!你可以繼續(xù)進(jìn)行下一步。
5. 設(shè)置 web server
應(yīng)用可以用下一個(gè)命令行動(dòng):
# 用于測(cè)試目的
sudo -u gitlab bundle exec rails s -e production
# 用于守護(hù)進(jìn)程
sudo -u gitlab bundle exec rails s -e production -d
默認(rèn)登錄用戶名及密碼:
筆者注:記住這個(gè)用戶名和密碼,在通過(guò)瀏覽器登錄gitlab工程主頁(yè)的時(shí)候有用。
admin@local.host
5iveL!fe
6. 運(yùn)行 Resque 進(jìn)程(用于處理工作隊(duì)列)
# 手動(dòng)啟動(dòng)
sudo -u gitlab bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production BACKGROUND=yes
# GitLab 啟動(dòng)腳本
sudo -u gitlab ./resque.sh
# 如果你使用 root 運(yùn)行此腳本,會(huì)導(dǎo)致 /home/gitlab/gitlab/tmp/pids/resque_worker.pid 文件的擁有者為 root
# 將導(dǎo)致 resque 在下一次系統(tǒng)初始化中無(wú)法啟動(dòng)
自定義 Resque 使用的 Redis 連接
如果你希望 Resque 連接到一個(gè)非標(biāo)準(zhǔn)端口號(hào)或另一臺(tái)服務(wù)器上的 Redis,你可以在 config/resque.yml 文件修改連接信息:
production: redis.example.com:6379
好了,我們已經(jīng)擁有了一個(gè)工作正常的 GitLab 了,但請(qǐng)繼續(xù)下去,有一些事情是必須完成的。
7.Nginx 與 Unicorn
(1). Unicorn
cd /home/gitlab/gitlab
sudo -u gitlab cp config/unicorn.rb.example config/unicorn.rb
sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
(2). Nginx
# 初次安裝 Nginx
sudo apt-get install nginx
# 添加GitLab 到 nginx sites
sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab -P /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
# 修改 **YOUR_SERVER_IP** 與 **YOUR_SERVER_FQDN**
# 為起初的 IP 地址與準(zhǔn)備讓 GitLab 服務(wù)的域名
sudo vim /etc/nginx/sites-enabled/gitlab
筆者注:本人最初的時(shí)候不知道這個(gè)配置文件怎么配置,在瀏覽器里輸入服務(wù)器ip的時(shí)候老是出現(xiàn)“welcome to nginx”頁(yè)面。
后來(lái)的配置是
listion 80; #監(jiān)聽(tīng)所有80端口的客戶端請(qǐng)求
server_name: 192.168.1.120; #這是我ubuntu服務(wù)器的ip地址。因?yàn)槲覀兪切〗M局域網(wǎng)訪問(wèn),所以直接配ip地址就可以了。遠(yuǎn)程訪問(wèn)的話可以通過(guò)vpn鏈接。
# 重啟 nginx:
sudo /etc/init.d/nginx restart
(3). Init 腳本
在 /etc/init.d/gitlab 創(chuàng)建 init 腳本:
sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab -P /etc/init.d/
sudo chmod +x /etc/init.d/gitlab
設(shè)置 GitLab 自動(dòng)啟動(dòng):
sudo update-rc.d gitlab defaults 21
現(xiàn)在你可以用這種方式啟動(dòng)/重啟/停止 GitLab 服務(wù):
sudo /etc/init.d/gitlab restart