Git是一个分布式的版本控制系统,用于Linux内核的管理。在推出后,Git也逐渐被用于其他项目,同样也取得了很大的成功。GitHub则是基于Git版本控制系统的,它提供基于互联网的项目托管服务,但GitHub并不开源,所以我在网上找到了替代GitHub的开源项目托管系统:Gitorious。
安装Gitorious并不是一件轻松的事,所以就写了这篇文章,一则可以帮助那些准备安装Gitorious的兄弟,二则也给自己做个备忘。
一、安装第三方的相关依赖包:
- sudo apt-get install -y build-essential apache2 apache2-threaded-dev libapache2-mod-xsendfile
注意:在安装MySQL时,您将会被提示创建MySQL的root用户密码
- sudo apt-get install -y mysql-server mysql-client
设置时选择apache2、并使用dbconfig-common来配置数据库,并会被提示创建PHPMyAdmin管理员用户密码。
- sudo apt-get install -y phpmyadmin
- sudo apt-get install -y git-core git-doc
- sudo apt-get install -y libexpat1-dev libxslt1-dev libcurl4-openssl-dev sendmail apg geoip-bin libgeoip1 libgeoip-dev imagemagick libmagick++-dev libpcre3 libpcre3-dev zlib1g zlib1g-dev zip unzip libyaml-dev libonig-dev memcached aspell libaspell-dev aspell-en
- sudo apt-get install -y ruby ruby-dev rubygems libruby libdbd-mysql-ruby libmysql-ruby
- sudo REALLY_GEM_UPDATE_SYSTEM=1 gem update --system
- sudo gem install --no-ri --no-rdoc rake
- sudo gem install --no-ri --no-rdoc daemons
- sudo gem install -b --no-ri --no-rdoc rmagick
- sudo gem install -b --no-ri --no-rdoc stompserver
- sudo gem install -b --no-ri --no-rdoc passenger
- sudo gem install -b --no-ri --no-rdoc bundler
- sudo apt-get install -y sphinxsearch
二、下载Gitorious源代码,在这里将Gitorious放置在/var/www/gitoriou:
- cd /var/www
- sudo chown firehare:firehare /var/www
- git clone git://gitorious.org/gitorious/mainline.git gitorious
- cd gitorious
- git submodule init
- git submodule update
- sudo ln -s /var/www/gitorious/script/gitorious /usr/bin
第2条语句是为了方便处理,不用老是sudo,所以将/var/www目录的所有者从root改为你的用户名,在这里我使用的是我的用户名firehare。
三、配置初始化服务
在/var/www/gitorious/doc/templates/ubuntu目录中有相应的服务脚本模板。将这些脚本模板拷至/etc/init.d目录中:
- cd /var/www/gitorious/doc/templates/ubuntu
- sudo cp git-daemon git-ultrasphinx git-poller stomp /etc/init.d
- sudo cp gitorious-logrotate /etc/logrotate.d/gitorious
- sudo chmod 755 git-daemon git-ultrasphinx git-poller stomp
然后将服务配置成开机启动
- sudo update-rc.d stomp defaults
- sudo update-rc.d git-daemon defaults
- sudo update-rc.d git-ultrasphinx defaults
- sudo update-rc.d git-poller defaults
最后由于git-daemon git-ultrasphinx git-poller stomp脚本中的RUBY_HOME路径指向"/opt/ruby-enterprise",为了方便起见,不一一修改启动脚本,将创建一个链接:
- sudo ln -s /usr/ /opt/ruby-enterprise
四、配置Apache
- sudo /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11/bin/passenger-install-apache2-module
然后在新建的passenger.load文件中输入以下文字:
- sudo vi /etc/apache2/mods-available/passenger.load
- # Did you verify this matches the values from
- # the 'sudo /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11/bin/passenger-install-apache2-module' command ?
- LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
- PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11
- PassengerRuby /usr/bin/ruby1.8
- sudo a2enmod passenger
- sudo a2enmod rewrite
- sudo a2enmod ssl
- sudo /etc/init.d/apache2 restart
然后在新建的Gitorious站点文件中输入以下文字:
- sudo vi /etc/apache2/sites-available/gitorious
- <VirtualHost *:80>
- ServerName git.meranko.net
- DocumentRoot /var/www/gitorious/public
- # Enable X-SendFile for gitorious repo archiving to work
- XSendFile on
- # Possible values include: debug, info, notice, warn, error, crit,
- # alert, emerg.
- LogLevel warn
- #
- # The following directives define some format nicknames for use with
- # a CustomLog directive (see below).
- #
- LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
- LogFormat "%h %l %u %t \"%r\" %>s %b" common
- LogFormat "%{Referer}i -> %U" referer
- LogFormat "%{User-agent}i" agent
- CustomLog /var/log/apache2/gitorious_access.log combined
- TransferLog /var/log/apache2/gitorious_access.log
- ErrorLog /var/log/apache2/gitorious_error.log
- </VirtualHost>
然后在新建的Gitorious站点文件中输入以下文字:
- sudo vi /etc/apache2/sites-available/gitorious-ssl
- <IfModule mod_ssl.c>
- <VirtualHost _default_:443>
- SSLEngine on
- SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
- SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
- BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
- DocumentRoot /var/www/gitorious/public
- # Possible values include: debug, info, notice, warn, error, crit,
- # alert, emerg.
- LogLevel warn
- #
- # The following directives define some format nicknames for use with
- # a CustomLog directive (see below).
- #
- LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
- LogFormat "%h %l %u %t \"%r\" %>s %b" common
- LogFormat "%{Referer}i -> %U" referer
- LogFormat "%{User-agent}i" agent
- CustomLog /var/log/apache2/gitorious_ssl_access.log combined
- TransferLog /var/log/apache2/gitorious_ssl_access.log
- ErrorLog /var/log/apache2/gitorious_ssl_error.log
- </VirtualHost>
- </IfModule>
- sudo a2dissite default
- sudo a2dissite default-ssl
- sudo a2ensite gitorious
- sudo a2ensite gitorious-ssl
- sudo /etc/init.d/apache2 restart
五、设置MySQL用户
- mysql -u root -p
- Enter password: (输入你在安装包时确定的Mysql根用户密码)
- mysql> GRANT ALL PRIVILEGES ON *.* TO 'gitorious'@'localhost' IDENTIFIED BY '<输入密码>' WITH GRANT OPTION;
- mysql> FLUSH PRIVILEGES;
六、配置Gitorious
- cd /var/www/gitorious/
- bundle install
- bundle pack
- sudo adduser --system --home /var/www/gitorious/ --no-create-home --group --shell /bin/bash git
- sudo chown -R git:git /var/www/gitorious
- sudo su - git
- mkdir .ssh
- touch .ssh/authorized_keys
- chmod 700 .ssh
- chmod 600 .ssh/authorized_keys
- mkdir tmp/pids
- mkdir repositories
- mkdir tarballs
- mkdir tmp/tarballs-work
chmod
ug+rwx repositories
- cp config/database.sample.yml config/database.yml
- cp config/gitorious.sample.yml config/gitorious.yml
- cp config/broker.yml.example config/broker.yml
production段中
确保正确的数据库用户名和名字(注意:当前用户为git)production而非test中修改
- apg -m 64
七、创建Gitorious数据库
- require 'thread'
- export RAILS_ENV=production
- bundle exec rake db:create RAILS_ENV=production
- bundle exec rake db:migrate RAILS_ENV=production
- vi /var/www/gitorious/config/ultrasphinx/default.base
- # Daemon options
- searchd
- {
- # What interface the search daemon should listen on and where to store its logs
- address = localhost
- port = 3312
- .......
注意:本人在安装在这一步时出现一个错误,提示如下,详见第12行,于是本人查了一下数据库,打开文件/var/www/gitorious/config/ultrasphinx/production.conf,找到base_tags.name语句,将其改成tags,即可通过:
- bundle exec rake ultrasphinx:bootstrap RAILS_ENV=production
- (in /var/www/gitorious)
- Rebuilding configurations for production environment
- Available models are Comment, Repository, MergeRequest, and Project
- Generating SQL
- $ indexer --config '/var/www/gitorious/config/ultrasphinx/production.conf' --all
- Sphinx 0.9.9-release (r2117)
- Copyright (c) 2001-2009, Andrew Aksyonoff
- using config file '/var/www/gitorious/config/ultrasphinx/production.conf'...
- WARNING: key 'address' is deprecated in /var/www/gitorious/config/ultrasphinx/production.conf line 10; use 'listen' instead.
- indexing index 'main'...
- ERROR: index 'main': sql_range_query: Unknown column 'base_tags.name' in 'field list' (DSN=mysql://gitorious:***@localhost:3306/gitorious_production).
- total 0 docs, 0 bytes
- total 0.005 sec, 0 bytes/sec, 0.00 docs/sec
- total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
- total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
- Sphinx 0.9.9-release (r2117)
- Copyright (c) 2001-2009, Andrew Aksyonoff
- using config file '/var/www/gitorious/config/ultrasphinx/production.conf'...
- WARNING: key 'address' is deprecated in /var/www/gitorious/config/ultrasphinx/production.conf line 10; use 'listen' instead.
- listening on 127.0.0.1:3312
- WARNING: index 'main': preload: failed to open /var/www/gitorious/db/sphinx//sphinx_index_main.sph: No such file or directory; NOT SERVING
- FATAL: no valid indexes to serve
- Failed to start
- Done
- Please restart your application containers
- crontab -e * * * * * cd /var/www/gitorious && /usr/bin/bundle exec
- env RAILS_ENV=production ruby1.8 script/create_admin
八、重启机器后你就可以在Ubuntu 11.10上完成Gitorious的安装了!OK!打完收功!!