centos6安裝gitlab

Git是一個分佈式版本控制/軟件配置管理軟件node

github是一個基於git的代碼託管平臺,付費用戶能夠建私人倉庫,咱們通常的免費用戶只能使用公共倉庫,也就是代碼要公開。(因此本身搭建一個gitlab)python

GitLab,是一個利用 Ruby on Rails 開發的開源應用程序,實現一個自託管的Git項目倉庫,可經過Web界面進行訪問公開的或者私人項目,它擁有與Github相似的功能,可以瀏覽源代碼,管理缺陷和註釋。能夠管理團隊對倉庫的訪問,它很是易於瀏覽提交過的版本並提供一個文件歷史庫。團隊成員能夠利用內置的簡單聊天程序(Wall)進行交流。它還提供一個代碼片斷收集功能能夠輕鬆實現代碼複用,便於往後有須要的時候進行查找。mysql


參考 https://github.com/gitlabhq/gitlab-recipes/tree/master/install/centosnginx

     https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md  //比較全面,好比環境等安裝要求c++


環境:centos 6.3 x86_64  內存最好1Ggit

//表示能夠沒必要執行github


1.系統初始化web

Add EPEL repositoryredis

wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://www.fedoraproject.org/static/0608B895.txtspring

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

Verify that the key got installed successfully:

//rpm -qa gpg*

Now install the epel-release-6-8.noarch package, which will enable EPEL repository on your system:

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Add PUIAS Computational repository

centos6默認yum安裝的git版本是1.7.1,是不兼容gitlab的,至少要1.7.10,能夠下git最新版本編譯或者

Create /etc/yum.repos.d/PUIAS_6_computational.repo and add the following lines:

[PUIAS_6_computational]

name=PUIAS computational Base $releasever - $basearch

mirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist

#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias

Next download and install the gpg key.

wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puias http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias

Verify that the key got installed successfully:

//rpm -qa gpg*

Verify that the EPEL and PUIAS Computational repositories are enabled as shown below:

yum repolist

If you can't see them listed, use the folowing command (from yum-utils package) to enable them:

//yum-config-manager --enable epel --enable PUIAS_6_computational //啓用指定的repos   (yum-config-manager is part of the yum-utils)

Install the required tools for GitLab

//yum -y update

yum -y groupinstall 'Development Tools'

yum -y install vim-enhanced readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc \

sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel python-devel redis sudo \

wget crontabs logwatch logrotate perl-Time-HiRes git

RHEL Notes


If some packages (eg. gdbm-devel, libffi-devel and libicu-devel) are NOT installed, add the rhel6 optional packages repo to your server to get those packages:


yum-config-manager --enable rhel-6-server-optional-rpms 

Configure redis


Make sure redis is started on boot:


chkconfig redis on

service redis start

Configure sendmail

未配置


2. Ruby


Download and compile it:


mkdir /tmp/ruby && cd /tmp/ruby

wget -c http://ruby.taobao.org/mirrors/ruby/ruby-2.1.0.tar.gz

tar zxvf ruby-2.0.0-p353.tar.gz 

cd ruby-2.0.0-p353/

./configure --prefix=/usr/local/

make && make install

Install the Bundler Gem:


gem install bundler --no-ri --no-rdoc

3. System Users


Create user for Git


adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git

We do NOT set the password so this user cannot login.

Forwarding all emails

未配置

4. GitLab shell


GitLab Shell is a ssh access and repository management software developed specially for GitLab.

# Login as git

su - git


# Clone gitlab shell

git clone https://github.com/gitlabhq/gitlab-shell.git

cd gitlab-shell


# Switch to right version

git checkout v1.8.0

cp config.yml.example config.yml


# Edit config and replace gitlab_url with something like 'http://domain.com/'

#

# Note, 'gitlab_url' is used by gitlab-shell to access GitLab API. Since 

#     1. the whole communication is locally

#     2. next steps will explain how to expose GitLab over HTTPS with custom cert

# it's a good solution is to set gitlab_url as "http://localhost:8080/"


# Do setup

./bin/install

5. Database

這裏我使用的是mysql


yum install -y mysql-server mysql-devel

chkconfig mysqld on

service mysqld start

Secure MySQL by entering a root password and say "Yes" to all questions:


/usr/bin/mysql_secure_installation

Create a new user and database for GitLab:


# Login to MySQL

mysql -u root -p

# Type the database root password

# Create a user for GitLab. (change supersecret to a real password)

CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'supersecret';


# Create the GitLab production database

CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;


# Grant the GitLab user necessary permissopns on the table.

GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';


退出來用新建的用戶登陸測試下


6. GitLab

su - git

Clone the Source


# Clone GitLab repository

git clone https://github.com/gitlabhq/gitlabhq.git gitlab


# Go to gitlab directory

cd /home/git/gitlab


# Checkout to stable release

git checkout 6-4-stable

Configure it


# Copy the example GitLab config

cp config/gitlab.yml.example config/gitlab.yml


# Replace your_domain_name with the fully-qualified domain name of your host serving GitLab

sed -i 's|localhost|your_domain_name|g' config/gitlab.yml


# Make sure GitLab can write to the log/ and tmp/ directories

chown -R git log/

chown -R git tmp/

chmod -R u+rwX  log/

chmod -R u+rwX  tmp/


# Create directory for satellites

mkdir /home/git/gitlab-satellites


# Create directories for sockets/pids and make sure GitLab can write to them

mkdir tmp/pids/

mkdir tmp/sockets/

chmod -R u+rwX  tmp/pids/

chmod -R u+rwX  tmp/sockets/


# Create public/uploads directory otherwise backup will fail

mkdir public/uploads

chmod -R u+rwX  public/uploads


# Copy the example Unicorn config

cp config/unicorn.rb.example config/unicorn.rb


# Enable cluster mode if you expect to have a high load instance

# E.g. change amount of workers to 3 for 2GB RAM server

vi config/unicorn.rb   //timeout 120


# Configure Git global settings for git user, useful when editing via web

# Edit user.email according to what is set in gitlab.yml

git config --global user.name "GitLab"

git config --global user.email "gitlab@your_domain_name"

git config --global core.autocrlf input

Important: Make sure to edit both gitlab.yml and unicorn.rb to match your setup.

vi config/gitlab.yml  

  ## GitLab settings

  gitlab:

    ## Web server settings

    host: localhost

    port: 80

    https: true

    port: 443


Configure GitLab DB settings


# MySQL

cp config/database.yml{.mysql,}

Make config/database.yml readable to git only


chmod o-rwx config/database.yml

vi config/database.yml   

production:

  adapter: mysql2

  encoding: utf8

  reconnect: false

  database: gitlabhq_production

  pool: 10

  username: gitlab

  password: "supersecret"

  # host: localhost

  # socket: /tmp/mysql.sock


Install Gems


su -

gem install charlock_holmes --version '0.6.9.4'

exit

For MySQL (note, the option says "without ... postgres"):


cd /home/git/gitlab/   //vi Gemfile 淘寶源

bundle install --deployment --without development test postgres puma aws

Initialize Database and Activate Advanced Features


bundle exec rake gitlab:setup RAILS_ENV=production   //yes

Administrator account created:


login.........admin@local.host

password......5iveL!fe

Install Init Script


Download the init script (will be /etc/init.d/gitlab):


su -

wget -O /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn

chmod +x /etc/init.d/gitlab

chkconfig --add gitlab

Make GitLab start on boot:


chkconfig gitlab on

Check Application Status


Check if GitLab and its environment are configured correctly:


cd gitlab/

bundle exec rake gitlab:env:info RAILS_ENV=production


Start your GitLab instance:


service gitlab start

Double-check Application Status


To make sure you didn't miss anything run a more thorough check with:


su - git

cd gitlab/

bundle exec rake gitlab:check RAILS_ENV=production  //沒事多檢測

7. Configure the web server


Use either Nginx or Apache, not both. Official installation guide recommends nginx.


Nginx


su -

yum -y install nginx

chkconfig nginx on

mkdir /etc/nginx/sites-{available,enabled}

wget -O /etc/nginx/sites-available/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/web-server/nginx/gitlab-ssl

ln -sf /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

Edit /etc/nginx/nginx.conf and replace include /etc/nginx/conf.d/*.conf; with include /etc/nginx/sites-enabled/*;


Edit /etc/nginx/sites-available/gitlab and replace git.example.com with your FQDN.


Add nginx user to git group.


usermod -a -G git nginx

chmod g+rx /home/git/

Note: Don't forget to add a SSL certificate or generate a Self Signed Certificate


cd /etc/nginx

openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key

Finally start nginx with:


service nginx start




注意:

添加淘寶源可能更快點

gem sources --remove https://rubygems.org/

gem sources -a http://ruby.taobao.org/

vi /home/git/gitlab/Gemfile  //首行替換

問題一:

You are trying to install in deployment mode after changing

your Gemfile. Run `bundle install` elsewhere and add the

updated Gemfile.lock to version control.


You have added to the Gemfile:

* gon (~> 5.0.0)


You have deleted from the Gemfile:

* gon


You have changed in the Gemfile:

* gon from `no specified source` to `rubygems repository https://rubygems.org/`

vi /home/git/gitlab/Gemfile.lock gon! 替換 gon (~> 5.0.0)

問題二:

使用nginx作http server時,訪問出現502 bad gateway,同時/var/log/nginx/gitlab_error.log顯示upstream prematurely closed connection while reading response header from upstream


檢查gitlab/log下的unicorn.stderr.log,通常會發現timeout (31s > 30s), killing.緣由是第一次訪問時,gitlab須要初始化,機器太次時初始化所需時間超過了gitlab/config/unicorn.rb中的timeout,只需調大timeout便可. 【120S/1G內存】

問題三:

Could not find 'bundler' (>= 0) among 9 total gem(s) (Gem::LoadError)

gem install bundle