最近換了公司,在交接公司,所以很忙也沒有時間寫部落格,同時隨著能力的逐漸提升,很多知識感覺很簡單,也沒有必要專門寫部落格,只是把遇到的情況與解決方法寫入到了筆記裡,正好現在沒什麼事,就把我最近研究的gitlab如何在centos裡安裝的筆記分享給大家。

先給大家介紹一下gitlab

GitLab 是一個用於倉庫管理系統的開源專案。使用Git作為程式碼管理工具,並在此基礎上搭建起來的web服務。
應用特點:
1. Web框架使用Ruby on Rails
2. 基於MIT程式碼釋出協議。
3. 需要gitolite協同工作。
安裝GitLab的需求:
Ubuntu/Debian(推薦這2個系統,也可以安裝到CentOS系統中,並且在GitHub上有CentOS的GitLab一鍵安裝指令碼)

官方推薦的是那2個系統,但我這裡需要安裝在centos裡,所以沒辦法自己多研究與測試,總結的安裝經驗如下:

前置要求

一定要先關閉iptableselinux

本文安裝的系統為centos 6.2 64位系統,安裝在dell r410機器

1、安裝epel與基礎依賴庫及軟體

cd /tmp
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm
yum install -y readline-devel  libyaml-devel gdbm-devel  ncurses-devel redis openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel curl-devel expat-devel gettext-devel  tk-devel  libxml2-devel libffi-devel libxslt-devel libicu-devel httpd httpd-devel gitolite git-all python-devel python-pip sqlite-devel sendmail vim mysql-devel mysql-server patch libyaml* pcre-devel

2、安裝ruby(一般預設安裝都是1.8的,官方要求1.9以上)

mkdir /tmp/ruby && cd /tmp/ruby
curl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz | tar xz
cd ruby-1.9.3-p392/
./configure
make
make install
gem install bundler
ln -s /usr/local/bin/ruby /usr/bin/ruby
ln -s /usr/local/bin/gem /usr/bin/gem
ln -s /usr/local/bin/bundle /usr/bin/bundle

3、建立一個git使用者供GitLab使用

adduser --comment `GitLab` git
chmod –R 755 /home/git

4、安裝gitlab 的shell

# Login as git
sudo su git
# Go to home directory
cd /home/git
# Clone gitlab shell
git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
# switch to right version
git checkout v1.3.0
cp config.yml.example config.yml
# Edit config and replace gitlab_url
# with something like `http://domain.com/`
vim config.yml
# Do setup
./bin/install

5、建立gitlab資料庫並授權

# 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 `gitlab`;
# 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, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO `gitlab`@`localhost`;
# Quit the database session
mysql> q

6、克隆gitlab源

# Clone GitLab repository
cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
# Go to gitlab dir
cd /home/git/gitlab
# Checkout to stable release
sudo -u git -H git checkout 5-1-stable
Configure it
cd /home/git/gitlab
# Copy the example GitLab config
sudo -u git -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 git -H vim config/gitlab.yml
# Make sure GitLab can write to the log/ and tmp/ directories
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX  log/
sudo chmod -R u+rwX  tmp/
# Create directory for satellites
sudo -u git -H mkdir /home/git/gitlab-satellites
# Create directories for sockets/pids and make sure GitLab can write to them
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
sudo chmod -R u+rwX  tmp/pids/
sudo chmod -R u+rwX  tmp/sockets/
# Create public/uploads directory otherwise backup will fail
sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwX  public/uploads
# Copy the example Puma config
sudo -u git -H cp config/puma.rb.example config/puma.rb
# Configure Git global settings for git user, useful when editing via web
# Edit user.email according to what is set in gitlab.yml
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"

7、配置gitlab資料庫

sudo -u git cp config/database.yml.mysql config/database.yml
sudo -u git vim config/database.yml
Make sure to update username/password in config/database.yml.

這個資料庫的賬戶與密碼是在第5步那裡建立的。

8、安裝gem

cd /home/git/gitlab
sudo gem install charlock_holmes --version `0.6.9.4`
sudo -u git -H bundle install --deployment --without development test postgres

9、啟動redis

/etc/init.d/redis start

10、對資料庫進行初始化

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

11、下載啟動指令碼

Download the init script (will be /etc/init.d/gitlab):
sudo curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlabhq/master/lib/support/init.d/gitlab
sudo chmod +x /etc/init.d/gitlab
Make GitLab start on boot:
chkconfig --add gitlab

12、檢測應用狀態

Check if GitLab and its environment are configured correctly:
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
To make sure you didn`t miss anything run a more thorough check with:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
If all items are green, then congratulations on successfully installing GitLab! However there are still a few steps left.
出現了Running? ... no
Try fixing it:
sudo -u git -H bundle exec rake sidekiq:start RAILS_ENV=production
For more information see:
doc/install/installation.md in section "Install Init Script"
see log/sidekiq.log for possible errors
Please fix the error above and rerun the checks.
執行sudo -u git -H bundle exec rake sidekiq:start RAILS_ENV=production
然後在執行sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

13、啟動gitlab

sudo service gitlab start

14、下載nginx(我選nging作為web伺服器)

yum install nginx

15、下載官方提供gitlab的虛擬配置檔案,並修改配置

Download an example site config:
sudo curl --output /etc/nginx/conf.d/gitlab https://raw.github.com/gitlabhq/gitlabhq/master/lib/support/nginx/gitlab
Make sure to edit the config file to match your setup:
# **YOUR_SERVER_FQDN** to the fully-qualified
# domain name of your host serving GitLab. Also, replace
# the `listen` line with the following:
#   listen 80 default_server;         # e.g., listen 192.168.1.1:80;
sudo vim /etc/nginx/conf.d/gitlab
cd /etc/nginx/conf.d
mv default.conf default.conf.bak
mv gitlab default.conf
Restart
sudo service nginx restart

16、登陸你在nginx裡新增的ip,然後輸入賬戶與密碼,預設為

admin@local.host
5iveL!fe

現在就完成了gitlab在centos系統裡的安裝,希望本文對大家有益。