mkdir /tmp/ruby && cd /tmp/ruby
curl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz | tar xz
cd ruby-1.9.3-p327
./configure
make
sudo make install
Install the Bundler Gem:
sudo gem install bundler
3.创建系统账户
sudo useradd -r -m git
sudo useradd -g git gitlab
#Add x privilege to /home/git
sudo chmod g+x /home/git
# 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"
配置gitolite相关路径的权限
# Make sure the Gitolite config dir is owned by git
sudo chmod 750 /home/git/.gitolite/
sudo chown -R git:git /home/git/.gitolite/
配置仓库路径的权限
# 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/
sudo chmod -R ug-s /home/git/repositories/
find /home/git/repositories/ -type d -print0 | sudo xargs -0 chmod g+s
将域名加到gitlab账户的known_hosts列表中
# 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
如果测试失败,不要继续往下走,请查看https://github.com/gitlabhq/gitlab-public-wiki/wiki/Trouble-Shooting-Guide帮助解决问题
5. 搭建数据库
gitlab支持两种数据库:Mysql和PostgreSQL
Mysql:
# Install the database packages
sudo yum install mysql.x86_64 mysql-devel.x86_64 mysql-server.x86_64
# Login to MySQL
$ mysql -u root -p
# Create a user for GitLab. (change $password to a real password)
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password';
# Create the GitLab production database
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# Grant the GitLab user necessary permissopns on the table.
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
# Quit the database session
mysql> \q
# Try connecting to the new database with the new user
sudo -u gitlab -H mysql -u gitlab -p -D gitlabhq_production
PostgreSQL:
# Install the database packages
sudo yum install postgresql.x86_64 postgresql-devel.x86_64 postgresql-server.x86_64
# 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 6. 搭建GitLab
下载代码:
# We'll install GitLab into home directory of the user "gitlab"
cd /home/gitlab
# Clone GitLab repository
sudo -u gitlab -H git clone git://github.com/gitlabhq/gitlabhq.git gitlab
# Go to gitlab dir
cd /home/gitlab/gitlab
# Checkout to stable release
sudo -u gitlab -H git checkout 4-1-stable
设置配置项:
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+rwX log/
sudo chmod -R u+rwX tmp/
# Make directory for satellites
sudo -u gitlab -H mkdir /home/gitlab/gitlab-satellites
# Copy the example Unicorn config
sudo -u gitlab -H cp config/unicorn.rb.example config/unicorn.rb
配置数据库:
cd /home/gitlab/gitlab
sudo gem install charlock_holmes --version '0.6.9'
# For MySQL (note, the option says "without")
sudo -u gitlab -H bundle install --deployment --without development test postgres
# Or for PostgreSQL
sudo -u gitlab -H bundle install --deployment --without development test mysql
配置Git:
gitlab需要能够提交代码到gitolite,所以我们需要设置一个全局的用户信息: email和username (建议直接使用config/gitlab.yml配置文件中的email.from值)
sudo service mysql start
# or
sudo /etc/init.d/mysql start
启动Redis
sudo service redis-server start
# or
sudo /etc/init.d/redis restart
启动GitLab
sudo service gitlab start
# or
sudo /etc/init.d/gitlab start 7. 搭建Nginx
安装:
sudo yum install nginx
设置配置文件:
#Download an example site config:
sudo curl --output /etc/nginx/conf.d/gitlab.conf https://raw.github.com/gitlabhq/gitlab-recipes/4-1-stable/nginx/gitlab
#Make sure to edit the config file to match your setup:
# 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/conf.d/gitlab.conf
启动Nginx:
sudo service nginx start
sudo /etc/init.d/nginx start 8. 搭建完成
现在你可以使用管理员账户访问你的gitlab网站了:
git:
bin_path: /usr/bin/git
# Max size of git object like commit, in bytes
# This value can be increased if you have a very large commits
max_size: 524288000 # 500.megabytes
# Git timeout to read commit, in seconds
timeout: 10
#!/usr/bin/env bash
# Version 4.1
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
while read oldrev newrev ref
do
# For every branch or tag that was pushed, create a Resque job in redis.
repo_path=`pwd`
env -i /usr/local/bin/redis-cli rpush "resque:gitlab:queue:post_receive" "{\"class\":\"PostReceive\",\"args\":[\"$repo_path\",\"$oldrev\",\"$newrev\",\"$ref\",\"$GL_USER\"]}" > /dev/null 2>&1
done