|
原文地址:http://www.pwhack.me/archives/installation_of_gitlab.html
GitLab简单来说就是开源的GitHub,是用ruby写的,基于rails框架的web应用。由于最近一个想法比较需要一个自己的版本管理系统,因此开始了我的艰辛之旅。安装过程遇到了很多问题,期间还在segmentfault和gitlhub的gitlab专页提了问题,但没人回复啊哈哈。最后自己解决,期间felix给了我很大的帮助。
GitLab的安装过程非常复杂,不过官方安装文档还算详细。先说下我成功的详细安装过程吧,大部分与官网的步骤相同,但完全相同的话我是没有成功的。稍微有一点出入:
安装环境:纯净ubuntu server 11.04
1.先安装必要的包和依赖
1
2
3
4
sudo apt-get update;
sudo apt-get upgrade;
sudo apt-get install -y wget curl gcc checkinstall libxml2-dev libxslt-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 libpq-dev;
sudo pip install pygments;
2.安装ruby
1
2
3
4
5
6
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz;
tar xfvz ruby-1.9.3-p194.tar.gz;
cd ruby-1.9.3-p194;
./configure;
make;
sudo make install;
3.创建用户
创建git用户
1
2
3
4
5
6
7
8
sudo adduser \
--system \
--shell /bin/sh \
--gecos 'git version control' \
--group \
--disabled-password \
--home /home/git \
git
创建gitlab用户
1
sudo adduser --disabled-login --gecos 'gitlab system' gitlab
将用户加入用户组
1
2
sudo usermod -a -G git gitlab
sudo usermod -a -G gitlab git
生成公玥
1
sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa;
4.安装Gitolite
git clone 经过GitLab fork的gitolite源码
1
sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite;
安装
1
2
3
4
5
6
7
8
9
cd /home/git;
sudo -u git -H mkdir bin;
sudo -u git sh -c 'echo -e "PATH=\$PATH:/home/git/bin\nexport PATH" >> /home/git/.profile';
sudo -u git sh -c 'gitolite/install -ln /home/git/bin';
sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub;
sudo chmod 0444 /home/git/gitlab.pub;
sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub";
赋予权限
1
2
3
4
5
6
sudo chmod -R g+rwX /home/git/repositories/;
sudo chown -R git:git /home/git/repositories/;
sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin;
sudo rm -rf /tmp/gitolite-admin;
5.安装并设置mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
# Login to MySQL
$ mysql -u root -p
# Create the GitLab production database
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# Create the MySQL User change $password to a real password
mysql> CREATE USER 'gitlab'@'localhost'>
# Grant proper permissions to the MySQL User
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX,>
6.安装GitLab
1
cd /home/gitlab
获取源码
1
2
3
4
5
6
# Get gitlab code. Use this for stable setup
sudo -H -u gitlab git clone -b stable https://github.com/gitlabhq/gitlabhq.git gitlab
# Skip this for stable setup.
# Master branch (recent changes, less stable)
sudo -H -u gitlab git clone -b master https://github.com/gitlabhq/gitlabhq.git gitlab
复制配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
d gitlab
# Rename config files
#
sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml
# Copy mysql db config
#
# 这里之后要vim config/database.yml将里面前两个root的密码填上。
#
sudo -u gitlab cp config/database.yml.mysql config/database.yml
# Copy unicorn config
#
sudo -u gitlab cp config/unicorn.rb.example config/unicorn.rb
安装gems
1
2
3
4
5
cd /home/gitlab/gitlab
sudo gem install charlock_holmes --version '0.6.9'
sudo gem install bundler
sudo -u gitlab -H bundle install --without development test sqlite postgres --deployment
配置git客户端
1
2
sudo -u gitlab -H git config --global user.email "gitlab@localhost"
sudo -u gitlab -H git config --global user.name "Gitlab"
安装GitLab应用
1
2
bundle install --without development test --deployment
sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production
安装GitLab Hooks
1
2
sudo cp lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive
sudo chown git:git /home/git/.gitolite/hooks/common/post-receive
检查应用是否正确安装
1
sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production
如果返回的都是绿色的yes或exists,那就说明安装基本正确。
初始化脚本
在/etc/init.d/中创建初始化脚本
1
2
sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab -P /etc/init.d/
sudo chmod +x /etc/init.d/gitlab
设置gitlab的自动启动
1
sudo update-rc.d gitlab defaults 21
7.安装并配置Nginx
运行gitlab后台处理服务
1
2
cp config/unicorn.rb.example config/unicorn.rb
bundle exec unicorn_rails -c config/unicorn.rb -E production -D
安装nginx,然后将gitlab的nginx代理配置文件拷贝到nginx代理目录下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Install first
sudo apt-get install nginx
# Add GitLab to nginx sites & change with your host specific settings
sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab -P /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
# Change **YOUR_SERVER_IP** and **YOUR_SERVER_FQDN**
# to the IP address and fully-qualified domain name
# of the host serving GitLab.
sudo vim /etc/nginx/sites-enabled/gitlab
# Restart nginx:
sudo /etc/init.d/nginx restart
默认账号密码:
admin@local.host
5iveL!fe
我遇到的问题
sudo执行不成功
这个问题是因为我这个vps的特性导致的。我登上ssh后,本机地址显示的不是localhost,而是我的账号名,xxxxx。这也导致了每次执行sudo的时候,会提示无法解析主机名xxxxx。
解决办法:修改/etc/hosts,加上127.0.0.1 xxxxx
1
vim /etc/hosts
Nginx 502 Bad Gateway
按照官网的步骤一步一步装完之后,访问出现502。先查看日志:
1
2
3
cat /var/log/nginx/gitlat_error.log
2012/12/21 10:42:17 [crit] 32573#0: 30 connect() to unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket failed (2: No such file or directory) while connecting to upstream, client: **********, server: **********, request: "GET / HTTP/1.1", upstream: "http://unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket:/", host: "*******"
可以看到502的原因是因为gitlab.socket不存在,这说明gitlab没有正常运行。而我是执行了service gitlab start的,这很奇怪。
我猜测可能是脚本出了点问题,先stop掉。先提示找不到pid,然后再提示已经结束了。
stop之后,我再start一次,然后执行一次service gitlab status,这次成功返回了gitlab的运行状态和它的pid。
或者直接执行init.d/gitlab中的原始start脚本。
现在再通过浏览器访问一次,发现url被跳到了/user/sign_in。
但还是502。
第二次Nginx 502 Bad GateWay
这一次502,查看log发现是正常的。说明gitlab正常运行着,但脚本有问题。
几经搜索,执行了如下语句,问题得到解决(已在以上步骤中列出)。
1
2
cp config/unicorn.rb.example config/unicorn.rb
bundle exec unicorn_rails -c config/unicorn.rb -E production -D
|
|
|