OS: Ubuntu 12.04 Desktop x64
安裝Gitlab + MySQL
- 系統更新
apt-get update
apt-get upgrade -y
apt-get dist-upgrade
- 安裝基本需求
update-alternatives --set editor /usr/bin/vim.basic
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
sudo apt-get install -y python
python --version
python2 --version
# 確認 python版本,如果版本是3.x以上,則需額外安裝2.x版
# sudo apt-get install -y python2.7
# python --version # Python 2.7.3
# python2 --version # 命令執行會採用 python2, 所以需要確認 python2 的版本
# python2 不存在的話, 需要把 python 2.7 版 的 ln 過去.
# sudo ln -s /usr/bin/python /usr/bin/python2
apt-get install -y python-docutils
- 安裝Git
# 檢查Git目前可apt安裝的版本
apt-cache showpkg git-core
# 如果版本大於1.7.10,則可以直接使用~否則建議手動安裝新版本
# 直接安裝 => apt-get install -y git-core
# 如果原本就安裝舊有版本,移除 => apt-get remove git-core
# 手動安裝Git
apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential
cd /tmp
curl --progress https://git-core.googlecode.com/files/git-1.9.0.tar.gz | tar xz
cd git-1.9.0/
make prefix=/usr/local all
make prefix=/usr/local install
- 安裝postfix,以便後續提供發信服務
# 選擇Internet Site並輸入Domain Name
apt-get install -y postfix
- 安裝Ruby
# 如果裝有1.8版,先行移除
# apt-get remove ruby1.8
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p481.tar.gz | tar xz
cd ruby-2.0.0-p481/
./configure --disable-install-rdoc
make -j `cat /proc/cpuinfo | grep 'cpu cores' | awk '{if ($4=1) print $4; else print $4-1}'`
make install
gem install bundler --no-ri --no-rdoc
- 新增Gitlab系統帳號
adduser --disabled-login --gecos 'GitLab' git
- 安裝GitLab Shell
cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
#查看最新版本為何
sudo -u git -H git tag
sudo -u git -H git checkout v1.9.6
sudo -u git -H cp config.yml.example config.yml
#修改gitlab_url,改成要使用的domain
sudo -u git -H editor config.yml
sudo -u git -H ./bin/install
- 安裝MySQL Database
apt-get install -y mysql-server mysql-client libmysqlclient-dev
mysql -u root -p
> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'GITLAB_PASSWORD';
> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
>GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
# 使用gitlab帳號測試MySQL
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production
- 安裝GitLab
cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd /home/git/gitlab
# 檢查版本,找stable的
sudo -u git -H git branch -a
sudo -u git -H git checkout 7-0-stable
- 設定GitLab
cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
# 所有 localhost 改成要使用的domain.
# /usr/bin/git 改成 /usr/local/bin/git
sudo -u git -H editor config/gitlab.yml
#調整檔案權限
chown -R git log/
chown -R git tmp/
chmod -R u+rwX log/
chmod -R u+rwX tmp/
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
chmod -R u+rwX tmp/pids/
chmod -R u+rwX tmp/sockets/
sudo -u git -H mkdir public/uploads
chmod -R u+rwX public/uploads
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
chmod -R u+rwX public/uploads
sudo -u git -H mkdir public/uploads
#如果硬體記憶體規格超過2G,可將worker_processes改成3
#sudo -u git -H editor config/unicorn.rb
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
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
- GitLab DB設計
sudo -u git cp config/database.yml.mysql config/database.yml
# 將production區塊的secure password值改成MySQL gitlab帳號設定的帳號、密碼
sudo -u git -H editor config/database.yml
sudo -u git -H chmod o-rwx config/database.yml
- 安裝Gems
cd /home/git/gitlab
sudo -u git -H bundle install --deployment --without development test postgres aws
- 初始化 Database
# 問啥就輸入yes以便建立Database
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# 取得系統預設帳號、密碼 (所有新安裝都一樣,務必要更改)
Administrator account created:
login.........admin@local.host
password......5iveL!fe
- 設定開機自動啟動
cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
update-rc.d gitlab defaults 21
- 設定Logtotate
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
- 檢查GitLab應用程式設定狀態
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
- 啟動GitLab
service gitlab start
19.安裝、設定apache2
apt-get install apache2
cd /tmp
wget https://raw.github.com/gitlabhq/gitlab-recipes/master/web-server/apache/gitlab.conf
# 修改ServerName => 使用的Domain
# 修改ProxyPassServerse => (http://127.0.0.1:8080) 及 (http://使用的domain)
# 修改Log => /var/log/httpd/logs/ 改成 /var/log/apache2/
vim gitlab.conf
mv gitlab.conf /etc/apache2/sites-enabled/
# 將整個檔案註解,最前面加上'#'
vim /etc/apache2/sites-enabled/000-default
a2enmod rewrite proxy proxy_http
service apache2 restart
- 用網頁連線到http://使用的domain以上面取得的帳號密碼進行測試