Centos下gitlab安装指南[原创]
By admin
- 4 minutes read - 842 words最后一次更新时间:2013-05-29
gitlab 5.2.0 centos6.3 i686 Redis 2.6.13 nginx-1.4.1 mysql-5.5.31-linux2.6-i686.tar.gz
这里与官方的教程有些不一样,主要是一些软件如mysql nginx redis之类的以前是手动编译安装的.
网上也有提供一键安装包工具:http://bitnami.com/stack/gitlab
gitlab中文使用指南:GitLab使用介绍
首先我们选择比较快的yum源,不然安装速度会非常的慢的.这里使用中国科技大学的yum源更换yum源方法参考:,
说明: 默认安装的git版本可能会低一些,需要升级到最新版本才可以.
1. Packages / Dependencies
[shell]yum -y install readline-devel gdbm-devel ncurses-devel openssl-devel zlib-devel gcc gcc-c++ make autoconf curl-devel expat-devel gettext-devel tk-devel libxml2-devel libffi-devel libxslt-devel libicu-devel git-all python-devel vim sudo[/shell]
[shell]python2 –version[/shell]
要求为3以下的python版本,但要高于2.5版本,如果版本过低,请升级Python版本.参考:.这里我们使用 2.5.6版本的,测试的2.7版本好像也不支持的.换成2.5.6版本就正常了.
安装libyaml库
[shell]wget -c 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 cd ../[/shell]
2. Ruby Remove old 1.8 ruby if present
#sudo apt-get remove ruby1.8 Download and compile it:
[shell]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 make install cd ../[/shell]
Install the Bundler Gem:
[shell]gem install bundler[/shell]
3. System Users
Create a git user for Gitlab:
[shell]groupadd git adduser git -g git[/shell]
4. GitLab shell GitLab Shell is a ssh access and repository management software developed specially for GitLab.
# Login as git
[shell]su git[/shell]
# Go to home directory
[shell]cd /home/git[/shell]
# Clone gitlab shell
[shell]git clone https://github.com/gitlabhq/gitlab-shell.git cd gitlab-shell[/shell]
# switch to right version
[shell]git checkout v1.4.0[/shell]
[shell]cp config.yml.example config.yml[/shell]
# Edit config and replace gitlab_url # with something like ‘http://domain.com/’
[shell]vim config.yml[/shell]
# Do setup
[shell]./bin/install cd ../[/shell]
gitlab要使用redis-server软件,redis的安装参考:
5. Database
mysql安装教程参考 http://blog.haohtml.com/archives/12473
安装Mysql数据库,gitlab数据库配置:To setup the MySQL/PostgreSQL database and dependencies please see doc/install/databases.md
.
6. GitLab # We’ll install GitLab into home directory of the user “git”
[shell]cd /home/git[/shell]
Clone the Source
# Clone GitLab repository
[shell]sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab[/shell]
# Go to gitlab dir
[shell]cd /home/git/gitlab[/shell]
# Checkout to stable release
[shell]sudo -u git -H git checkout 5-2-stable[/shell]
Note: You can change 5-2-stable to master if you want the bleeding edge version, but do so with caution!
Configure it
[shell]cd /home/git/gitlab[/shell]
# Copy the example GitLab config
[shell]sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml[/shell]
# Make sure to change “localhost” to the fully-qualified domain name of your # host serving GitLab where necessary
[shell]sudo -u git -H vim config/gitlab.yml[/shell]
# Make sure GitLab can write to the log/ and tmp/ directories
[shell]sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/[/shell]
# Create directory for satellites
[shell]sudo -u git -H mkdir /home/git/gitlab-satellites[/shell]
# Create directories for sockets/pids and make sure GitLab can write to them
[shell]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/[/shell]
# Create public/uploads directory otherwise backup will fail
[shell]sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwX public/uploads[/shell]
# Copy the example Puma config
[shell]sudo -u git -H cp config/puma.rb.example config/puma.rb[/shell]
# Configure Git global settings for git user, useful when editing via web # Edit user.email according to what is set in gitlab.yml
[shell]sudo -u git -H git config –global user.name “GitLab”
sudo -u git -H git config –global user.email “gitlab@localhost”[/shell]
Important Note: Make sure to edit both gitlab.yml and puma.rb to match your setup. Configure GitLab DB settings
# Mysql(我们使用mysql)
[shell]sudo -u git cp config/database.yml.mysql config/database.yml[/shell]
# PostgreSQL(这里不使用这个数据库,所有不用执行)
[shell]sudo -u git cp config/database.yml.postgresql config/database.yml[/shell]
Make sure to update username/password in config/database.yml.
Install Gems
[shell]su root
cd /home/git/gitlab
gem install charlock_holmes –version ‘0.6.9.4’[/shell]
# For MySQL (note, the option says “without”)
[shell]bundle install –deployment –without development test postgres[/shell]
# Or for PostgreSQL
[shell]bundle install –deployment –without development test mysql[/shell]
Initialize Database and Activate Advanced Features
[shell]bundle exec rake gitlab:setup RAILS_ENV=production[/shell]
Install Init Script
Download the init script (will be /etc/init.d/gitlab):
[shell]cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab[/shell]
Make GitLab start on boot:
[shell]chkconfig gitlab on[/shell]
Check Application Status
Check if GitLab and its environment are configured correctly:
[shell]bundle exec rake gitlab:env:info RAILS_ENV=production[/shell]
Start Your GitLab Instance
[shell]service gitlab start[/shell]
# or
[shell]/etc/init.d/gitlab restart[/shell]
启用服务时,如何提示:
bash: bundle: command not found GitLab service started
错误信息,说明用户的环境变量不合适,先whereis bundle 命令查看出来bundle命令所在的位置,然后添加到 /etc/profile 里就可以了. 在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL下面添加一行 export PATH=$PATH:/usr/local/bin 参考:Double-check Application Status
To make sure you didn’t miss anything run a more thorough check with:
[shell]su git
bundle exec rake gitlab:check RAILS_ENV=production[/shell]
If all items are green, then congratulations on successfully installing GitLab! However there are still a few steps left.
这里可能会提示git的版本过低的问题(上面的git-all),只需要重新安装一下git,参考: 然后在配置文件config/gitlab.yml里git的bin_path路径就可以了, 这里我将git安装在/usr/local/目录里了.命令在 /usr/local/bin/git 位置,所以配置为(bin_path: /usr/local/bin/git). 可能还会提示需要执行一次下面的命令
[shell]bundle exec rake sidekiq:start RAILS_ENV=production[/shell]
7. Nginx
Installation
Nginx安装教程可参考: http://blog.haohtml.com/archives/12473
Note: If you can’t or don’t want to use Nginx as your web server, have a look at the Advanced Setup Tips
section.
Site Configuration
Download an example site config:
[shell]cd /home/git/gitlab
cp lib/support/nginx/gitlab /usr/local/nginx/conf/gitlab
vim /usr/local/nginx/conf/nginx.conf[/shell]
在server段中添加 **include gitlab; **一行
修改配置文件gitlab,注意日志路径
[shell]vim /usr/local/nginx/conf/gitlab[/shell]
Make sure to edit the config file to match your setup:
# *YOUR_SERVER_FQDN* to the fully-qualified # domain name of your host serving GitLab. Also, replace # the ‘listen’ line with the following: # listen 80 default_server; # e.g., listen 192.168.1.1:80;
测试nginx配置是否正确
[shell]/usr/local/nginx/sbin/nginx -t[/shell]
重启Nginx
[shell]/usr/local/nginx/sbin/nginx -s reload[/shell]
Done! Visit YOUR_SERVER for your first GitLab login. The setup has created an admin account for you. You can use it to log in:
[email protected] 5iveL!fe
Important Note: Please go over to your profile page and immediately change the password, so nobody can access your GitLab by using this login information later on.
注意关闭防火墙
[shell]service iptables stop[/shell]
参考官方文档:
注意nginx的运行用户权限问题.gitlab使用的是git:git用户,而nginx运行使用的www:www用户.这种情况会导致一些权限问题,可能会出现nginx 502错误,这里为了方便,要修改一下nginx的运行用户修改为 git,重启nginx就可以了.根据自己的自行设置权限.