在虚拟机中安装Gitlab
随着Github的盛行,social coding逐渐浮出水面,正好Gitlab刚发布了Gitlab 4.0,我今天边学习边记录安装Gitlab的过程,希望对大家有用。1. 我是在ubuntu server 10.4上安装的,首先要准备一个VitualBox并安装ubuntu server。
2. Packages / Dependencies
这里是Gitlab的安装说明:
https://github.com/gitlabhq/gitlabhq/blob/stable/doc/install/installation.md
我们先更新和安装Gitlab必须的依赖,以下操作请保持网络畅通:
# run as root
sudo apt-get update // 会有些更新失败,不必管它
sudo apt-get upgrade // 这个比较慢,可以去喝杯茶
# Install vim
sudo apt-get install -y vim
Install the required packages: // 下面这句比较长,不要打错了
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-devwget curl git-core openssh-server redis-server postfix checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev
# Install Python
sudo apt-get install python
# Make sure that Python is 2.5+ (3.x is not supported at the moment)
python –version// 我装上的版本是python 2.7.3
# If it's Python 3 you might need to install Python 2 separately
sudo apt-get install python2.7
# Make sure you can access Python via python2
python2 --version
# If you get a "command not found" error create a link to the python binary
sudo ln -s /usr/bin/python /usr/bin/python2 // 我的python2似乎已经存在了,不管它
2. 安装Ruby
mkdir /tmp/ruby && cd /tmp/ruby // 建个临时目录下载ruby
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz// 下载并解压
tar xfvz ruby-1.9.3-p327.tar.gz
cd ruby-1.9.3-p327
./configure // configure & make有些慢,耐心等下
make
sudo make install
Install the Bundler Gem:
sudo gem install bundler
3. 创建gitlab用户
// 创建Git账户
sudo adduser \
--system \
--shell /bin/sh \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
Git
// 创建Gitlab账户, 并禁止登录
sudo adduser --disabled-login --gecos 'GitLab' gitlab
# Add it to the git group
sudo usermod -a -G git gitlab
# Generate the SSH key// 一定是用gitlab用户生成id_rsa
sudo -u gitlab -H ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa
4. Gitolite
克隆Gitolite并安装:
// 以下所有操作要在git用户下操作,所有命令前加”sudo –u git”
cd /home/git
sudo -u git -H git clone -b gl-v320 https://github.com/gitlabhq/gitolite.git /home/git/gitolite
# Add Gitolite scripts to $PATH
sudo -u git -H mkdir /home/git/bin
sudo -u git -H sh -c 'printf "%b\n%b\n" "PATH=\$PATH:/home/git/bin" "export PATH" >> /home/git/.profile'
sudo -u git -H sh -c 'gitolite/install -ln /home/git/bin'
# Copy the gitlab user's (public) SSH key ...
sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
sudo chmod 0444 /home/git/gitlab.pub
# ... and use it as the admin key for the Gitolite setup
sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"
Fix the directory permissions for theconfiguration directory:
# Make sure the Gitolite config dir is owned by git
sudo chmod 750 /home/git/.gitolite/
sudo chown -R git:git /home/git/.gitolite/
Fixthe directory permissions for the repositories:
# Make sure the repositories dir is owned by git and it stays that way
sudo chmod -R ug+rwXs,o-rwx /home/git/repositories/
sudo chown -R git:git /home/git/repositories/
测试下git是否可以clone
# Clone the admin repo so SSH adds localhost to known_hosts ...
# ... and to be sure your users have access to Gitolite
sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin
# If it succeeded without errors you can remove the cloned repo
sudo rm -rf /tmp/gitolite-admin
到这里,基本算完成一半了。
安装数据库
Gitlab 4.0 支持PostgreSQL,我们用PostgreSQL:
# Install the database packages
sudo apt-get install -y postgresql-9.1 libpq-dev
# Login to PostgreSQL
sudo -u postgres psql -d template1
# Create a user for GitLab. (change $password to a real password)
template1=# CREATE USER gitlab WITH PASSWORD '$password';
# Create the GitLab production database & grant all privileges on database
template1=# CREATE DATABASE gitlabhq_production OWNER gitlab;
# Quit the database session
template1=# \q
# Try connecting to the new database with the new user
sudo -u gitlab -H psql -d gitlabhq_production
安装Gitlab
# We'll install GitLab into home directory of the user "gitlab"
cd /home/gitlab
# Clone GitLab repository
sudo -u gitlab -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
# Go to gitlab dir
cd /home/gitlab/gitlab
# Checkout to stable>
sudo -u gitlab -H git checkout 4-0-stable
Configure it
cd /home/gitlab/gitlab
# Copy the example GitLab config
sudo -u gitlab -H cp config/gitlab.yml.example config/gitlab.yml
# Make sure to change "localhost" to the fully-qualified domain name of your
# host serving GitLab where necessary
sudo -u gitlab -H vim config/gitlab.yml
# Make sure GitLab can write to the log/ and tmp/ directories
sudo chown -R gitlab log/
sudo chown -R gitlab tmp/
sudo chmod -R u+rwXlog/
sudo chmod -R u+rwXtmp/
# Copy the example Unicorn config
sudo -u gitlab -H cp config/unicorn.rb.example config/unicorn.rb
Configure GitLab DB settings
# 我们用的是PostgreSQL,所以使用postgresql模板
sudo -u gitlab cp config/database.yml.postgresql config/database.yml
# 记得修改database.yml里的username为“gitlab”,密码为空
sudo –u gitlab vi config/database.yml
Install Gems
cd /home/gitlab/gitlab
sudo gem install charlock_holmes --version '0.6.9'
// 安装需要几分钟时间
sudo -u gitlab -H bundle install --deployment --without development test mysql
Configure Git
sudo -u gitlab -H git config --global user.name "GitLab"
sudo -u gitlab -H git config --global user.email "gitlab@localhost"
Setup 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
Initialise Database and Activate Advanced Features
sudo -u gitlab -H bundle exec rake gitlab:app:setup RAILS_ENV=production
Install Init Script
Downloadthe init script (will be /etc/init.d/gitlab):
sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab -P /etc/init.d/
sudo chmod +x /etc/init.d/gitlab
MakeGitLab start on boot:
sudo update-rc.d gitlab defaults 21
// 重启系统后并测试
# reboot
sudo -u gitlab -H bundle exec rake gitlab:check RAILS_ENV=production
如果你也像下图一样,说明一切顺利:
Nginx
最后一步,配置Nginx web service:
sudo apt-get install nginx
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
# Change **YOUR_SERVER_IP** and **YOUR_SERVER_FQDN**
# to the IP address and fully-qualified domain name
# of your host serving GitLab
sudo vim /etc/nginx/sites-enabled/gitlab
// 稳妥些,重新系统
reboot
系统重启后,直接输入你虚拟机的http://IP地址,It’s works!!
不要忘了,初始用户密码是:
admin@local.host
5iveL!fe
Good luck!
页:
[1]