GitLab5發布快一個月了,決定試用下,5.0最大的特性就是用GitLab-Shell取代了Gitolite,這大大降低了安裝難度,不多本人在安裝過程中還是越到了一些問題,所以記錄下來供要安裝GitLab5的朋友參考!
主要參考文檔: https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md
安裝步驟總覽
- 安裝依賴包
- 安裝Ruby/RVM
- 創建Git用戶
- 安裝GitLab-Shell
- 配置數據庫
- 安裝GitLab
- 啟動
安裝依賴庫
yum install libicu-devel mysql-devel pcre-devel
安裝python,官方要求版本必須在2.5以上,而且不支持3.0,Fedora一般的版本都在2.7以上,因此直接安裝源自帶的即可
yum install python
安裝完查看下版本
python --version
還要確保python2命令有效
python2 --version
如果提示 bash: python2: 未找到命令
,那你需要link一下
sudo ln -s /usr/bin/python /usr/bin/python2
安裝Ruby
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
sudo make install
curl -#L https://get.rvm.io | bash -s stable --ruby
默然安裝ruby2.0, GitLab推薦用1.9.3
rvm install ruby-1.9.3-p392
還要安裝Bundler
sudo gem install bundler
添加系統Git用戶
創建一個 git
用戶供GitLab使用
adduser --comment 'GitLab' git
讓git用戶無密碼登陸
sudo chmod 644 /etc/shadow vim /etc/shadow
去掉用戶的嘆號
git:!!:15814:0:99999:7::: 修改為 git::15814:0:99999:7:::
加入sudo組
chmod u+w /etc/sudoers
vim /etc/sudoers
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
git ALL=(ALL) ALL #加入這行
安裝GitLab Shell
切換到git用戶
su - git cd ~/
克隆GitLab Shell
git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
切換到最新的分支
git checkout v1.2.0
生產配置文件
cp config.yml.example config.yml
更改配置信息,一般就改下你部署的域名地址gitlab_url
vim config.yml
# Url to gitlab instance. Used for api calls. Should be ends with slash.
gitlab_url: "http://localhost/" #改成你的域名或者IP
安裝
./bin/install
安裝數據庫
gitlab支持mysql和postgresql,這里以mysql為例,postgresql會比較麻煩!
切換回root用戶
su - root
安裝mysql及開發包
yum install -y mysql-server mysql mysql-devel
啟動數據庫
service mysqld start
初始化GitLab數據庫
mysql -u root -p
Enter password:
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
測試gitlab用戶連接mysql
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production
安裝GitLab
終于到GitLab的安裝了,進入git用戶
su - git
cd ~/
克隆GitLab
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab
切換到5.0穩定分支
sudo -u git -H git checkout 5-0-stable
配置
cd /home/git/gitlab
# 用樣例配置生成gitlab配置
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
# 更改域名
sudo -u git -H vim config/gitlab.yml
# 確保gitlab對 log/ 和 tmp/ 目錄有寫權限
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/
# 創建附屬目錄
sudo -u git -H mkdir /home/git/gitlab-satellites
# 創建pids目錄并確保對gitlab可寫
sudo -u git -H mkdir tmp/pids/
sudo chmod -R u+rwX tmp/pids/
# 生成Unicorn配置
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
配置GitLab DB設置
# Mysql sudo -u git cp config/database.yml.mysql config/database.yml
安裝Gems
cd /home/git/gitlab
sudo gem install charlock_holmes --version '0.6.9'
# For MySQL (note, the option says "without")
bundle install --deployment --without development test postgres
初始化數據并激活高級特性
首先編輯/home/git/gitlab/config/database.yml
#
# PRODUCTION
#
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlabhq_production
pool: 5
username: root
password: "secure password" #更改為你mysql的root用戶密碼
# host: localhost
# socket: /tmp/mysql.sock
#
執行rake
bundle exec rake gitlab:setup RAILS_ENV=production
報錯了,提示 Error connecting to Redis on localhost:6379 (ECONNREFUSED)
解決辦法:
切到root,安裝Redis
bc(command). yum install redis*
service redis start #啟動redis
重新執行rake
bundle exec rake gitlab:setup RAILS_ENV=production
如果你安裝最新版可能會報 /home/git/repositories/root
目錄找不到,手工建上即可!
如果你看到如下信息:
...
Administrator account created:
login.........admin@local.host
password......5iveL!fe
恭喜你!你已經成功安裝GitLab了!別忘了記錄輸出的管理用戶名和密碼!
啟動GitLab
bundle exec rails s -e production
=> Booting WEBrick
=> Rails 3.2.13 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-04-19 15:04:41] INFO WEBrick 1.3.1
[2013-04-19 15:04:41] INFO ruby 1.9.3 (2013-02-22)
[x86_64-linux] [2013-04-19 15:04:41] INFO WEBrick::HTTPServer#start: pid=11488 port=3000
Ok,你現在可以訪問GitLab了,默認端口是 @3000@, 訪問 http://你的域名或IP:3000
第一訪問會比較慢,因為要編譯很多js和css.
哈哈!看到登陸頁面了吧!

輸入管理用戶名和密碼!開始享受GitLab吧!

2013-04-19