Debian下GitLab 安裝步驟詳解

來源:互聯網
上載者:User

部落格又是好久不更新了,趁著中秋假期在家學習安裝了GitLab。這個折騰啊,然後寫個筆記,下次可以參考。
基本上參考官方文檔:https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md然後有些需要注意的地方做下記錄。

一、安裝要求

Debian**
MySQL
git
gitlab-shell
redis
二、安裝教程

1. 首先需要確定賬戶可以使用sudo, 並更新系統package
# run as root!
apt-get update
apt-get upgrade
apt-get install sudo #正常情況系統都帶sudo命令 如果沒有的話 手動安裝下
2. 安裝一些必要包
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils pkg-config cmake
檢查Python版本,2.5+ (3.0+還沒支援)python --version
如果版本不對,請安裝

sudo apt-get install python2.7
python2 --version
sudo ln -s /usr/bin/python /usr/bin/python2
安裝郵件發送支援 預設即可

sudo apt-get install -y postfix
3. 安裝Ruby 這裡我們使用taobao的鏡像進行安裝 可以大大的縮短下載包的時間
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress http://ruby.taobao.org/mirrors/ruby/2.1/ruby-2.1.2.tar.gz | tar xz
cd ruby-2.1.2
./configure --disable-install-rdoc
make
sudo make install
Note: 請不要使用rvm來安裝ruby 可能會因為環境變數導致這樣那樣的錯誤, 當然 如果你能解決這些問題可以使用rvm來安裝ruby
安裝bundler 這裡我們也使用taobao鏡像來縮短下載時間, 注意請使用sudo!!

sudo gem sources --remove http://rubygems.org/
sudo gem sources -a http://ruby.taobao.org/
sudo gem install bundler
4. 添加Git使用者
sudo adduser –disabled-login –gecos ‘GitLab’ git

5. 安裝 GitLab-shell 新版本使用GitLab-shell來代替gitolite
# 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.4.0

cp config.yml.example config.yml

# Edit config and replace gitlab_url
# with something like 'http://domain.com/'
# 這裡修改成自己的內部網域名稱 如: http://git.test.com/
vim config.yml

# Do setup
./bin/install
6. 安裝資料庫 推薦MySQL
以下所有操作需要使用可以sudo的賬戶

# Install the database packages
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev

# 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 '123456';

# 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 permissions on the table.
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
7. 開始安裝GitLab主程式
## We'll install GitLab into home directory of the user "git"
cd /home/git

# Clone GitLab repository
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 7-2-stable
8. 配置GitLab
# Go to GitLab installation folder
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
# 這裡僅需要修改host即可,
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
sudo chmod u+rwx,g=rx,o-rwx /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

# Copy the example Puma config
# 該設定檔預設即可
sudo -u git -H vim config/puma.rb

#如果沒有puma.rb可以用下面的,二選一
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H editor config/unicorn.rb
# listen "142.23.21.76:8080", :tcp_nopush => true

# Copy the example Rack attack config
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.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"
sudo -u git -H git config --global core.autocrlf input

sudo -u git cp config/database.yml.mysql config/database.yml

# 修改資料庫帳號密碼, 剛才添加過gitlab這個資料庫使用者 直接修改成該帳號即可
sudo -u git vim config/database.yml
#資料庫密碼  只需修改production即可
#  username: gitlab
#  password: "123456"      
#  host: localhost
9. 安裝 Gems
cd /home/git/gitlab

sudo gem install charlock_holmes --version '0.6.9.4'

# 修改Bundle源地址為taobao, 首行改成 source 'http://ruby.taobao.org/'
sudo -u git vim Gemfile

# 這個是使用mysql資料庫, 這個命令意思是排除postgres 請別搞錯
sudo -u git -H bundle install --deployment --without development test postgres aws
10. 初始化資料庫並啟用進階功能
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
11. 安裝init指令碼
cd /home/git/gitlab
sudo curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlabhq/7-2-stable/lib/support/init.d/gitlab
cp lib/support/init.d/gitlab /etc/init.d/
sudo chmod +x /etc/init.d/gitlab

#設定開機啟動GitLab
sudo update-rc.d gitlab defaults 21

cd /home/git/gitlab
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
12. 最後檢測一下程式狀態
cd gitlab
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
Note: 這裡可能會告訴你init指令碼有問題或者git版本過低, 可以無視

13. 啟動GitLab
sudo service gitlab start
三、Nginx配置

你可以安裝nginx來代理訪問GitLab 配置過程如下

1. 安裝nginx
sudo apt-get install nginx
cd /home/git/gitlab
1. 增加GitLab設定檔
sudo curl --output /etc/nginx/sites-available/gitlab https://raw.github.com/gitlabhq/gitlabhq/7-2-stable/lib/support/nginx/gitlab
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

# 修改設定檔 Listen 直接監聽80連接埠即可 e.g. listen 80;
# 修改server_name為你的內部網域名稱 e.g. server_name git.test.com;
sudo vim /etc/nginx/sites-available/gitlab
2. 重啟nginx
sudo service nginx restart
儲存伺服器名字的hash表是由指令 server_names_hash_max_size 和 server_names_hash_bucket_size所控制的。參數hash bucket size總是等於hash表的大小,並且是一路處理器緩衝大小的倍數。如果Nginx給出需要增大 hash max size 或 hash bucket size的提示,那麼首要的是增大前一個參數的大小.

vim /etc/nginx/sites-enabled/gitlab
server_names_hash_bucket_size 64;
sudo service nginx restart
這樣你就可以通過nginx來訪問gitlab了
預設的賬戶如下

使用者名稱:admin@local.host
密碼: 5iveL!fe

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.