本文主要参考文档:https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md
Debian/Ubuntu主要参考https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md
Centos主要参考下文内容,辅助参考https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md
1.安装依赖包
2.安装Ruby
3.创建Git用户
4.安装GitLab-Shell
5.配置数据库
6.安装GitLab
7.启动GitLab
yum install -y wget curl gcc checkinstall libxml2-dev libxslt-dev sqlite3 libsqlite3-dev libcurl4-openssl-dev libreadline6-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip libyaml-dev postfix
yum install libicu-devel mysql-devel pcre-devel
安装python,官方要求版本必须在2.5以上,而且不支持3.0。
yum install python
安装完查看下版本
python --version
还要确保python2命令有效
python2 --version
如果提示
bash: python2: 未找到命令 ,那你需要link一下
sudo ln -s /usr/bin/python /usr/bin/python2
系统自带旧版本python被严重依赖时,就不要卸载旧版本python,直接安装新版本python即可。
wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar zxvf Python-2.7.6.tgz
cd Python-2.7.6
./configure --prefix=/usr/bin/python2.7
make
make install
查看python是否正常
/usr/bin/python2.7/bin/python2.7 -V
创建一个连接是系统默认python变为python2.7
ln -s /usr/bin/python2.7/bin/python2.7 /usr/bin/python
!!!注意:
在安装Ruby之前需要先安装libyaml,如果没先安装libyaml,后期执行 bundle exec rake
gitlab:setup RAILS_ENV=production ,会报 can't dump anonymous class Class 错误。
安装 libyaml
wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
tar xzvf yaml-0.1.4.tar.gz
cd yaml-0.1.4
./configure --prefix=/usr/local
make
make install
安装
Ruby 1.9.3-p0
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
tar xzvf ruby-1.9.3-p0.tar.gz
cd ruby-1.9.3-p0
./configure --prefix=/usr/local --enable-shared --disable-install-doc --with-opt-dir=/usr/local/lib
make
make install
!!!注意:
Ruby 1.9.3-p0执行 make 时,会出现 ossl_pkey_ec.c 错误,
解决方法:
vi ext/openssl/ossl_pkey_ec.c #此文件放置在ruby-1.9.3-p0目录下
#在method = EC_GFp_nist_method();下一行新增 #if !defined(OPENSSL_NO_EC2M)
#在method = EC_GFp_simple_method();下一行新增 #endif
if (id == s_GFp_simple) {
method = EC_GFp_simple_method();
} else if (id == s_GFp_mont) {
method = EC_GFp_mont_method();
} else if (id == s_GFp_nist) {
method = EC_GFp_nist_method();
#if !defined(OPENSSL_NO_EC2M)
} else if (id == s_GF2m_simple) {
method = EC_GF2m_simple_method();
#endif
}
#在new_curve = EC_GROUP_new_curve_GFp;下一行新增 #if !defined(OPENSSL_NO_EC2M)
#在new_curve = EC_GROUP_new_curve_GF2m;下一行新增 #endif
if (id == s_GFp) {
new_curve = EC_GROUP_new_curve_GFp;
#if !defined(OPENSSL_NO_EC2M)
} else if (id == s_GF2m) {
new_curve = EC_GROUP_new_curve_GF2m;
#endif
} else {
ossl_raise(rb_eArgError, "unknown symbol, must be :GFp or :GF2m");
}
安装完成后,执行 ruby -v 查看ruby版本,执行gem -v 查看gem版本(执行完毕如果只出现版本而不是提示需要安装libyaml,证明libyaml安装成功)
安装 Bundler
sudo gem install bundler
创建一个 git 用户供GitLab使用
adduser --comment 'GitLab' git
让git用户无密码登陆
sudo chmod 644 /etc/shadow vim /etc/shadow
这里感觉 664 权限不够用那就改为 777 权限
去掉用户的感叹号
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 #加入这行
切换到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及开发包的情况
安装mysql及开发包
yum install -y mysql-server mysql mysql-devel
安装过mysql及开发包的情况,省略上边的mysq安装。
启动数据库
service mysqld start #或 /etc/init.d/mysql.server start等
初始化GitLab数据库
!!!注意:
注意1,执行 mysql -u root -p Enter password:时报ERROR 2002 (HY000): Can’t connect to
local MySQL server through socket ‘/var/lib/mysql/mysql.sock错误,
因为sock文件存放有时不是指向 /var/lib/mysql目录下的(安装方式不同,sock文件存放位置不同),
使用 ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock 加个连接。
如,创建用户user01,CREATE USER user01@'localhost' IDENTIFIED BY 'password1'; 修改用户
user01密码,SET PASSWORD FOR 'user01'@'localhost' = PASSWORD('password2');
初始化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
!!!注意:
这里可能报 sudo: /etc/sudoers is mode 0640, should be 0440 错误
解决方法:root用户 chmod 0440 /etc/sudoers
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
!!!注意:
安装Gems中执行 bundle install --deployment --without development test postgres ,会卡住很长时间,几个小时甚至更多,
原因,gem sources 是 https://rubygems.org/ ,解决,gem sources 改为 http://ruby.taobao.org/
!!!注意:
执行 bundle install --deployment --without development test postgres 命令时会出现各种匪夷所思的错误,到时候别着急,慢慢来。
先整体看看此命令执行后显示(非常重要),有可能是库缺失,如出现
An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue.Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling.
可能就是libxml2、libxslt库缺失,显示会有libxml2 is missing libxslt is missing等
sudo yum install -y gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel
这里关键是不要慌,看完执行后全部显示。
修改方式 ,
vi /home/git/gitlab/Gemfile
source "http://ruby.taobao.org" // 旧 source "http://rubygems.org/"
初始化数据并激活高级特性
首先编辑/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
!!!注意:
报错,提示 can't dump anonymous class Class,检查第二步 Ruby 时,libyaml是否优先安装
报错,提示 rake aborted! getaddrinfo: Name or service not known,检查你的hosts, /etc/hosts 中 127.0.0.1 对应是否有localhost
解决办法,切换到root,安装Redis
安装epel
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
别忘了安装yum install yum-priorities
yum install redis*
#启动redis
service redis start
重新执行rake
bundle exec rake gitlab:setup RAILS_ENV=production
!!!注意:
如果你安装最新版可能会报 /home/git/repositories/root 目录找不到,手工建上即可!
如果你看到如下信息:
...
Administrator account created:
[email protected]
password......5iveL!fe
恭喜你!你已经成功安装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.
!!!注意:
3000端口可能受防火墙影响,关闭防火墙 chkconfig iptables off(重启后永久性生效)service
iptables stop(及时生效,重启后失效),或修改/etc/sysconfig/iptables文件
添加 -A RH-Firewall-1-INPUT -m state ——state NEW -m tcp -p tcp ——dport 3000 -j ACCEPT
登陆页面
输入管理用户名和密码!