如何在Ubuntu Server 11.10上安装Gitorious

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介:

Git是一个分布式的版本控制系统,用于Linux内核的管理。在推出后,Git也逐渐被用于其他项目,同样也取得了很大的成功。GitHub则是基于Git版本控制系统的,它提供基于互联网的项目托管服务,但GitHub并不开源,所以我在网上找到了替代GitHub的开源项目托管系统:Gitorious。

安装Gitorious并不是一件轻松的事,所以就写了这篇文章,一则可以帮助那些准备安装Gitorious的兄弟,二则也给自己做个备忘。

一、安装第三方的相关依赖包:

  • Apache
     
      
    1. sudo apt-get install -y build-essential apache2 apache2-threaded-dev libapache2-mod-xsendfile 
  • MySQL
     
      
    1. sudo apt-get install -y mysql-server mysql-client
    注意:在安装MySQL时,您将会被提示创建MySQL的root用户密码
  • PHPMyAdmin(可选)
     
      
    1. sudo apt-get install -y phpmyadmin
    设置时选择apache2、并使用dbconfig-common来配置数据库,并会被提示创建PHPMyAdmin管理员用户密码。
  • Git
     
      
    1. sudo apt-get install -y git-core git-doc 
  • 其它依赖包
     
      
    1. 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
  • Ruby 和 RubyGems
     
      
    1. sudo apt-get install -y ruby ruby-dev rubygems libruby libdbd-mysql-ruby libmysql-ruby 
    2. sudo REALLY_GEM_UPDATE_SYSTEM=1 gem update --system
    3. sudo gem install --no-ri --no-rdoc rake
    4. sudo gem install --no-ri --no-rdoc daemons
    5. sudo gem install -b --no-ri --no-rdoc rmagick
    6. sudo gem install -b --no-ri --no-rdoc stompserver
    7. sudo gem install -b --no-ri --no-rdoc passenger
    8. sudo gem install -b --no-ri --no-rdoc bundler
  • Sphinx(俄国人贡献的开源搜索包)
     
      
    1. sudo apt-get install -y sphinxsearch

二、下载Gitorious源代码,在这里将Gitorious放置在/var/www/gitoriou:

 
  1. cd /var/www
  2. sudo chown firehare:firehare /var/www
  3. git clone git://gitorious.org/gitorious/mainline.git gitorious
  4. cd gitorious
  5. git submodule init
  6. git submodule update
  7. 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目录中:

 
  1. cd /var/www/gitorious/doc/templates/ubuntu 
  2. sudo cp git-daemon git-ultrasphinx git-poller stomp /etc/init.d 
  3. sudo cp gitorious-logrotate /etc/logrotate.d/gitorious
  4. sudo chmod 755 git-daemon git-ultrasphinx git-poller stomp

然后将服务配置成开机启动

 
  1. sudo update-rc.d stomp defaults
  2. sudo update-rc.d git-daemon defaults
  3. sudo update-rc.d git-ultrasphinx defaults
  4. sudo update-rc.d git-poller defaults

最后由于git-daemon git-ultrasphinx git-poller stomp脚本中的RUBY_HOME路径指向"/opt/ruby-enterprise",为了方便起见,不一一修改启动脚本,将创建一个链接:

 
  1. sudo ln -s /usr/ /opt/ruby-enterprise 

四、配置Apache

  • 安装Passenger
     
      
    1. sudo /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11/bin/passenger-install-apache2-module 
  • 配置Passenger
     
      
    1. sudo vi /etc/apache2/mods-available/passenger.load
    然后在新建的passenger.load文件中输入以下文字:
     
      
    1. # Did you verify this matches the values from 
    2. # the 'sudo /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11/bin/passenger-install-apache2-module' command ? 
    3. LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11/ext/apache2/mod_passenger.so 
    4. PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11 
    5. PassengerRuby /usr/bin/ruby1.8
  • 启用Apache模块
     
      
    1. sudo a2enmod passenger
    2. sudo a2enmod rewrite
    3. sudo a2enmod ssl
    4. sudo /etc/init.d/apache2 restart
  • 创建Gitorious站点文件
     
      
    1. sudo vi /etc/apache2/sites-available/gitorious
    然后在新建的Gitorious站点文件中输入以下文字:
     
      
    1. <VirtualHost *:80> 
    2.   ServerName git.meranko.net 
    3.   DocumentRoot /var/www/gitorious/public 
    4.   
    5.   # Enable X-SendFile for gitorious repo archiving to work 
    6.   XSendFile on 
    7.   
    8.   # Possible values include: debug, info, notice, warn, error, crit, 
    9.   # alert, emerg. 
    10.   LogLevel warn 
    11.   # 
    12.   # The following directives define some format nicknames for use with 
    13.   # a CustomLog directive (see below). 
    14.   # 
    15.   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 
    16.   LogFormat "%h %l %u %t \"%r\" %>s %b" common 
    17.   LogFormat "%{Referer}i -> %U" referer 
    18.   LogFormat "%{User-agent}i" agent 
    19.   
    20.   CustomLog /var/log/apache2/gitorious_access.log combined 
    21.   TransferLog /var/log/apache2/gitorious_access.log 
    22.   ErrorLog /var/log/apache2/gitorious_error.log 
    23. </VirtualHost> 
  • 创建Gitorious SSL站点文件
     
      
    1. sudo vi /etc/apache2/sites-available/gitorious-ssl
    然后在新建的Gitorious站点文件中输入以下文字:
     
      
    1. <IfModule mod_ssl.c> 
    2. <VirtualHost _default_:443> 
    3.   SSLEngine on 
    4.   SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem 
    5.   SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key 
    6.   BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0 
    7.   DocumentRoot /var/www/gitorious/public 
    8.   
    9.   # Possible values include: debug, info, notice, warn, error, crit, 
    10.   # alert, emerg. 
    11.   LogLevel warn 
    12.   # 
    13.   # The following directives define some format nicknames for use with 
    14.   # a CustomLog directive (see below). 
    15.   # 
    16.   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 
    17.   LogFormat "%h %l %u %t \"%r\" %>s %b" common 
    18.   LogFormat "%{Referer}i -> %U" referer 
    19.   LogFormat "%{User-agent}i" agent 
    20.   
    21.   CustomLog /var/log/apache2/gitorious_ssl_access.log combined 
    22.   TransferLog /var/log/apache2/gitorious_ssl_access.log 
    23.   ErrorLog /var/log/apache2/gitorious_ssl_error.log 
    24.   
    25. </VirtualHost> 
    26. </IfModule> 
  • 启用Gitorious和Gitorious SSL网站
     
      
    1. sudo a2dissite default
    2. sudo a2dissite default-ssl
    3. sudo a2ensite gitorious
    4. sudo a2ensite gitorious-ssl
    5. sudo /etc/init.d/apache2 restart

五、设置MySQL用户

 
  1. mysql -u root -p 
  2. Enter password: (输入你在安装包时确定的Mysql根用户密码)
  3. mysql> GRANT ALL PRIVILEGES ON *.* TO 'gitorious'@'localhost' IDENTIFIED BY '<输入密码>' WITH GRANT OPTION; 
  4. mysql> FLUSH PRIVILEGES; 

六、配置Gitorious

  • 首先确保所有gems版本的正确(安装时会询问你的sudo密码)
     
      
    1. cd /var/www/gitorious/ 
    2. bundle install 
    3. bundle pack 
  • 再创建git系统用户
     
      
    1. sudo adduser --system --home /var/www/gitorious/ --no-create-home --group --shell /bin/bash git 
    2. sudo chown -R git:git /var/www/gitorious
  • 然后创建一些Gitorious运行所需的东西
     
      
    1. sudo su - git
    2. mkdir .ssh
    3. touch .ssh/authorized_keys
    4. chmod 700 .ssh
    5. chmod 600 .ssh/authorized_keys
    6. mkdir tmp/pids
    7. mkdir repositories
    8. mkdir tarballs
    9. mkdir tmp/tarballs-work
    10. chmod ug+rwx repositories
  • 生成Gitorious的配置文件(注意:当前用户为git)
     
      
    1. cp config/database.sample.yml config/database.yml 
    2. cp config/gitorious.sample.yml config/gitorious.yml 
    3. cp config/broker.yml.example config/broker.yml 
  • 在Gitorious的database.yml配置文件中的production段中确保正确的数据库用户名和名字(注意:当前用户为git)
  • 在Gitorious的gitorious.yml配置文件中,要注意以下内容:
    • 确保在production而非test中修改
    • repository_base_path应该是/var/www/gitorious/repositories
    • cookie_secret应该设为多于30个字符的字符串,为了方便起见,你可以使用下列命令,然后将其输出复制到这里。
     
      
    1. apg -m 64
  • gitorious_client_port应该设为80
  • gitorious_host应该设置成客户可以使用的主机名(否则Cookie会出错
  • archive_cache_dir应该设为/var/www/gitorious/tarballs
  • archive_work_dir应该设为/var/www/gitorious/tmp/tarballs-work
  • exception_notification_emails:你的邮箱
  • hide_http_clone_urls应该设为true(它们需要额外的安装工作)
  • is_gitorious_dot_org应该设false
  • public_mode应该设为false

七、创建Gitorious数据库

  • 因为在RubyGems 1.6.0+ 并且 Rails < 2.3.11时存在BUG,本来可以在config/boot.rb文件的顶部添加下列语句来解决,但由于该文件注释要求不要改变,所以就只好麻烦点,添加到Rakefile文件和config/environment.rb文件的require(File.join(File.dirname(__FILE__), 'config', 'boot'))语句上方即可:
     
      
    1. require 'thread' 
  • 接下来的工作,我们让rake来做:
     
      
    1. export RAILS_ENV=production 
    2. bundle exec rake db:create  RAILS_ENV=production
    3. bundle exec rake db:migrate RAILS_ENV=production
  • 配置Sphinx搜索守护程序,将address设为localhost
     
      
    1. vi /var/www/gitorious/config/ultrasphinx/default.base 
    2. # Daemon options 
    3. searchd 
    4.   # What interface the search daemon should listen on and where to store its logs 
    5.   address = localhost
    6. port = 3312 
    7.   ....... 
  •  然后继续用rake来为我们配置:
     
      
    1. bundle exec rake ultrasphinx:bootstrap RAILS_ENV=production
    注意:本人在安装在这一步时出现一个错误,提示如下,详见第12行,于是本人查了一下数据库,打开文件/var/www/gitorious/config/ultrasphinx/production.conf,找到base_tags.name语句,将其改成tags,即可通过
 
  1. (in /var/www/gitorious) 
  2. Rebuilding configurations for production environment 
  3. Available models are Comment, Repository, MergeRequest, and Project 
  4. Generating SQL 
  5. $ indexer --config '/var/www/gitorious/config/ultrasphinx/production.conf' --all 
  6. Sphinx 0.9.9-release (r2117) 
  7. Copyright (c) 2001-2009, Andrew Aksyonoff 
  8.  
  9. using config file '/var/www/gitorious/config/ultrasphinx/production.conf'... 
  10. WARNING: key 'address' is deprecated in /var/www/gitorious/config/ultrasphinx/production.conf line 10; use 'listen' instead
  11. indexing index 'main'... 
  12. ERROR: index 'main': sql_range_query: Unknown column 'base_tags.name' in 'field list' (DSN=mysql://gitorious:***@localhost:3306/gitorious_production). 
  13. total 0 docs, 0 bytes 
  14. total 0.005 sec, 0 bytes/sec, 0.00 docs/sec 
  15. total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg 
  16. total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg 
  17. Sphinx 0.9.9-release (r2117) 
  18. Copyright (c) 2001-2009, Andrew Aksyonoff 
  19.  
  20. using config file '/var/www/gitorious/config/ultrasphinx/production.conf'... 
  21. WARNING: key 'address' is deprecated in /var/www/gitorious/config/ultrasphinx/production.conf line 10; use 'listen' instead
  22. listening on 127.0.0.1:3312 
  23. WARNING: index 'main': preload: failed to open /var/www/gitorious/db/sphinx//sphinx_index_main.sph: No such file or directory; NOT SERVING 
  24. FATAL: no valid indexes to serve 
  25. Failed to start 
  26. Done 
  27. Please restart your application containers 
创建Sphinx Cronjob
 
  1. crontab -e * * * * * cd /var/www/gitorious && /usr/bin/bundle exec 
  • 创建管理员用户
 
  1. env RAILS_ENV=production ruby1.8 script/create_admin

 八、重启机器后你就可以在Ubuntu 11.10上完成Gitorious的安装了!OK!打完收功!!



本文转自 firehare 51CTO博客,原文链接:http://blog.51cto.com/firehare/733695,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
16天前
|
Ubuntu Linux Python
Linux(15)Ubuntu安装ninja构建工具
Linux(15)Ubuntu安装ninja构建工具
62 0
|
23小时前
|
Ubuntu Python
Ubuntu 安装Python3.8
Ubuntu 安装Python3.8
6 0
|
2天前
|
Ubuntu 应用服务中间件 nginx
ubuntu编译安装nginx及安装nginx_upstream_check_module模块
以上是编译安装Nginx和安装 `nginx_upstream_check_module`模块的基本步骤。根据你的需求和环境,你可能需要进一步配置Nginx以满足特定的要求。
15 3
|
4天前
|
资源调度 JavaScript Ubuntu
Yarn介绍及快速安装Debian/Ubuntu Linux
现在,你已经成功安装了Yarn,可以在你的JavaScript项目中使用它来管理依赖。
39 3
|
4天前
|
Ubuntu
Ubuntu20.04安装SNMP服务
至此,你已经成功在Ubuntu 20.04上安装了SNMP服务。你可以使用SNMP工具来监视和管理你的系统,或者将其集成到网络管理系统中。
19 3
|
8天前
|
Ubuntu 关系型数据库 MySQL
Ubuntu 20.04 + mysql8 安装以及配置大小写不敏感
Ubuntu 20.04 + mysql8 安装以及配置大小写不敏感
|
8天前
|
缓存 Ubuntu 数据库
ubuntu无法使用apt命令时怎么安装库
无论哪种方法,一旦成功安装了所需的库文件,你应该能够在Ubuntu系统上正常使用它们。如果问题仍然存在,可能需要进一步检查系统的包管理配置和依赖关系问题。
26 0
|
9天前
|
Ubuntu Shell 网络安全
【专栏】如何在 Ubuntu 22.04 上安装 KubeSphere?
【4月更文挑战第28天】在Ubuntu 22.04上安装KubeSphere的指南:确保系统至少有4GB内存和2核CPU,安装Docker和docker-compose。下载安装脚本`curl -sSL https://kubesphere.io/install.sh | bash`,根据提示选择安装选项,等待完成。安装后,通过访问控制台验证安装效果。解决可能出现的错误、网络问题和性能问题,利用KubeSphere提升容器管理效率。本文为顺利安装和使用提供参考。
|
11天前
|
Ubuntu Linux 网络安全
|
11天前
|
Ubuntu 关系型数据库 数据库