Apache Gems包服务器

1.

这个想法有好几天了,在网上搜来搜去,也没找到多少有用的东西,不过今天晚上加班,还是弄到基本可用的程度了。  首先需要明确一点是,所谓的RubyGem服务器其实是一个非常普通的http服务器。在公司里那台公用服务器上,自动化组的人用ruby发布包里自带的gem_server.bat运行了一个脚本,提供gem服务。打开这个bat文件看看,其实是个Windows批处理脚本和ruby脚本混合的东西,它开头一条语句将处理流程跳转到最后,运行ruby.exe来执行自身,中间则是一段一段的html代码和ruby代码,最主要的是最后一段ruby代码,通过WEBRick包提供的功能,在本地开设了一个http服务,并动态处理远程连接的http请求。其中最重要的是yaml请求,远程客户端请求yaml文件,其实它是一个对服务器上所有的gem包的索引,有了这个索引文件,客户端知道服务器上有效的gem包版本和具体路径,然后同样是通过http协议下载需要的gem包,并安装到本地。  有了这些基础,接下来的就好办了。Apache随便哪里都能弄到,基本配置也非常简单,就是改一下端口,设置几个别名,把gem服务器常用的几个目录添加上。一般需要/、/gems/、/doc_root/、/yaml这4个路径,其中/gems/和/doc_root/就是ruby在文件系统目录的直接映射,/和/yaml要通过脚本刷新,脚本不用自己写,只要拿gem_server.bat改一下就行了,原本它是直接生成字符串返回给http客户端,这里就改成把生成的字符串写入到文件就行了。试了试gem install命令,可以用,解决!  最后再来啰嗦一下,为什么要用Apache来作为Gems服务器。因为那个gem_server.bat用ruby来启http服务器,却有非常严重的内存泄漏问题,只要客户端连接稍微多一点,内存占用就直线飚升,随随便便就能到1.5G,所以,就是不能用它!

 

 

2.

单机部署centos 5.2-64bit
1
服务器安装
只有全新部署的情况下,需要进行服务器安装。
1.1
安装 ruby enterprise
1.
安装需要的系统软件
yum install gcc gcc-g++ zlib zlib-devel openssl openssl-devel readline readline-devel mysql-devel
2.
解压安装包
tar xvzf ruby-enterprise-1.8.7-20090928.tar.gz
3.
执行安装程序,安装程序会同时安装 ruby enterprise Passenger
cd ruby-enterprise-1.8.7-20090928
./installer
在安装过程中出现选择安装路径时,请直接按回车选择默认路径
4. 配置环境变量
cd /opt
ln -s ruby-enterprise-1.8.7-20090928 ruby-enterprise
编辑 /etc/profile ,加入
export PATH=/opt/ruby-enterprise/bin:$PATH
执行下面命令,将环境变量导出:
source /etc/profile
1.2
安装 Passenger
安装 Passenger apache 模块:
yum install httpd-devel
passenger-install-apache2-module
ruby 环境不成功,该命令不能执行)
1.3
安装 gem
gem uninstall rails actionmailer activeresource actionpack activerecord activesupport
gem install rails -v2.2.2 --no-rdoc --no-ri
gem install rubyzip hpricot --no-rdoc --no-ri
1.4 配置 apache
编辑 /etc/httpd/conf/httpd.conf ,在文件最后加入以下内容,其中 VirtualHost 里面的几个 IP 设成部署机器的 IP 地址
LoadModule passenger_module /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
PassengerRoot /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5
PassengerRuby /opt/ruby-enterprise/bin/ruby
<VirtualHost *:8080>
ServerName 192.168.1.41
DocumentRoot /opt/websites
<Directory "/opt/websites">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RailsBaseURI /cms
RailsBaseURI /dhs
RailsBaseURI /wp
RailsBaseURI /hms
ProxyPass /dhs !
ProxyPass /cms !
ProxyPass /wp !
ProxyPass /hms !
ProxyPass / http://192.168.1.41/dhs/
ProxyPassReverse / http://192.168.1.41/dhs/
</VirtualHost>
配置完成后重启 apache
service httpd restart
注意:解决 apache 启动失败
需要执行下面语句及关闭 selinux
chcon -R -h -t httpd_sys_content_t /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/
1.5
安装 haproxy 作为 load balancer
1.5.1
安装
tar xvzf haproxy-1.2.18.tar.gz
cd haproxy-1.2.18
make TARGET=linux26
mkdir /etc/haproxy
cp examples/haproxy.cfg /etc/haproxy/
cp examples/haproxy.init /etc/init.d/haproxy
cp haproxy /usr/sbin/
chmod a+x /etc/init.d/haproxy
useradd -M -d /www/wwwroot -s /sbin/nologin www
1.5.2
配置
编辑 /etc/haproxy/haproxy.cfg ,修改成如下内容 : listen server IP 地址与端口改为前面配置的 apache 服务器的监听地址
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 10000
#uid 99
#gid 99
daemon
user www
group www
defaults
log global
mode http
option httplog
option dontlognull
retries 3
redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen hia 0.0.0.0:80
balance roundrobin
server s1 192.168.1.41:8080 weight 1 check
1.6
配置自动启动 haproxy mysql apache
命令分别如下
chkconfig --add haproxy
chkconfig --level 345 httpd on
chkconfig --level 345 mysqld on
chkconfig --level 345 haproxy on
1.7
创建 mysql 用户
创建 mysql root 密码:
mysqladmin -uroot password 123456
登陆 mysql
mysql -uroot -p
输入密码
mysql 命令行建立部署用户
grant all on . to deploy@localhost identified by '123456';
1.8 创建部署专用用户
useradd capistrano
passwd capistrano
输入密码
apache 用户加入 capistrano
gpasswd -a apache capistrano
允许组成员访问 /home/ capistrano
chmod g+rx capistrano
验证权限 ll
drwxr-x--- 3 capistrano capistrano 4096 Nov 16 15:37 capistrano
1.9
创建部署链接
cd /opt/websites
ln -s /home/capistrano/dhs/current/public dhs
ln -s /home/capistrano/cms/current/public cms
ln -s /home/capistrano/wp/current/public wp
ln -s /home/capistrano/hms/current/public hms
2
安装 ' 部署工作站 '
2.1
安装 ruby 环境
参照 1.1 安装 ruby
2.2
安装 capistrano
gem install capistrano --no-rdoc --no-ri
2.3
修改部署配置
2.3.1
导出部署工具
cd /home/pkg/
svn co http://192.168.1.21/Sikara/server/deploy
2.3.2 Dhs
库的导入
编辑 /home/pkg/deploy/dhs/config/deploy.rb ,将下列配置修改:
role :web, "192.168.1.41" #
配置 WEB 服务器 IP
role :app, "192.168.1.41" #
配置应用服务器 IP
role :db, "192.168.1.41", :primary => true #
配置数据库服务器 IP
set :user, "capistrano" #
服务器部署专用用户
注意:检查部署过程中运行 cap 是否出现错误报告,类似如下:
·          
o     
  •  
    •  
      • [err :: 192.168.1.41] cms_production already exists
进入 /home/pkg/deploy/dhs 。设置数据库, web 服务的用户名密码:
cap deploy:setup
注意:配置过程中,需要填写部署的数据库的用户名,密码及数据库访问地址,参考下面输入
Enter MySQL database username: deploy
Enter MySQL database password:
Enter MySQL database host: localhost
创建数据库:
cap deploy:create_db
2.3.3 Hms
wp cms 库的导入
参考 2.3.1 ,同样修改对应目录下的 config/deploy.rb ,并执行后续步骤
3
部署
3.1
部署 DHS
3.1.1
数据备份
3.1.1.1
数据库备份
3.1.1.2
图片及数据备份
检查服务器每个应用相应 /releases 目录下的代码日期,并备份最新的代码目录
3.1.2
执行部署
cd /home/pkg/
进入 dhs
把部署机的代码部署到服务器上
cap deploy -s revision=11499
执行数据库迁移
cap deploy:migrations

 

 

3.

我一直在更新服务器宝石手为我太久,但我一直犹豫,因为对任何事情更加自动化,只要我的系统更新了http://gems.rubyforge.orgRubyforge has been down more than once when I really needed to update something, and I don't want to create an automated dependency on a third-party service RubyForge的已下跌超过一次,当我真正需要更新的东西,我不想上创建一个第三方自动依存服务

 

So before I automate things, I needed a way to point to my own gem server.所以,我自动的东西,我需要一种方法来指向自己的服务器上的宝石。 Which thankfully, it turns out, that it's not all that hard to do so (it's harder than it has to be, and man oh man is the gem cache a pain in the rear).其中谢天谢地,事实证明,它不是所有的努力这样做(它的难度比过去要,人啊,人是宝石缓存在后面的痛苦)。 This all assumes that you already had rubygems installed on the boxes that you are moving over to point to your own server.这一切都假定你已经对你的方块移动到指向您自己的服务器上安装的rubygems。 (This also assumes that you use a Linux/Unix server, I'm sure all this works on a Windows server, but I haven't tested one and honestly don't care). (这还假定您使用的Linux / Unix服务器,我敢肯定,这一切在Windows服务器上工作,但我没有测试之一,真的不关心)。

Setting up your server您的服务器设置

  1. You need a web server.你需要一个Web服务器。 (yes I know you can run gem_server, but get a real one). (是的,我知道你可以运行gem_server,但得到一个真实的)。 You are on your own for that one.你是你自己的那种。 You also need a rubygems install on that box.您还需要一个对那个盒子的rubygems安装。 You are also on your own for bootstrapping rubygems on that box and any other ones.你是你自己也该为引导和任何其他的盒子的rubygems。
  2. Decide where you will put your gems (say in a “mycoolgems” directory off the docroot for your webserver)决定在那里你会放在一个“mycoolgems”关闭您的网络服务器docroot将目录中的宝石(说)
  3. $ mkdir [docroot]/mycoolgems/gems
  4. Copy your .gem files that you want to host to $ [docroot]/mycoolgems/gems复制你的。宝石文件,您要接待$ [docroot]/mycoolgems/gems
  5. Rubygems installed a "index_gem_repository.rb" ruby script in your path. RubyGems的安装了一个"index_gem_repository.rb"你的Ruby脚本的路径研究。 (well probably in your path, it's in /usr/bin on my systems). (以及可能在您的路径,它是在/ usr /在我的系统斌)。 You want to run this to generate a yaml-based index of your gems.您想运行此产生你的宝石的yaml的索引。 (appropriately named “yaml” – and a compressed yaml.Z) eg index_gem_repository.rb -d [docroot]/mycoolgems (适当命名的“YAML的” -与一个压缩yaml.Z)例如index_gem_repository.rb -d [docroot]/mycoolgems

Pointing your systems to your own server指着你的系统,以自己的服务器

Setting up the server is the easy part.设置服务器是容易的部分。 The harder part is pointing all your boxes to your own server.较难的部分是指所有的箱子到您自己的服务器。 And only your own server.而且,只有你自己的服务器。 You'd think that one neat thing about the 0.9.2 rubygems release is that it includes a “gem sources” command to theoretically add and remove gem sources that your boxes would look at, but you'd be wrong.你会认为,一个关于释放整洁的rubygems 0.9.2的是,它包含一个“宝石来源”命令来添加和删除理论上宝石的来源,你的箱子会看,但你就错了。 Because you can't get rid of the base source of http://gems.rubyforge.org without modifying the sources gem or the sources distribution on your own box.因为你不能得到的,而不需要修改源宝石或者你自己框源基地分布http://gems.rubyforge.org源清除。 You can theoretically modify [lib/ruby]/gems/1.8/gems/sources-0.0.1/lib/sources.rb and change:理论上,你可以修改[lib/ruby]/gems/1.8/gems/sources-0.0.1/lib/sources.rb和变化:

 module Gem @sources = ["http://gems.rubyforge.org"] def self.sources @sources end end 

to


@sources = ["http://yourserver.yourdomain"]

However, that customization is likely going to get blown away the next time you update rubygems with a gem update --system – because the sources gem is built by the rubygems update.不过,这可能是自定义会得到吹走你的下一次更新的rubygems与gem update --system -因为sources是更新宝石所建的rubygems。 So what do you do?所以,你怎么办? Build your own gem update.构建自己的宝石更新。

  1. Download the RubyGems source下载RubyGems的源
  2. Edit pkgs/sources/lib/sources.rb to point to your own server编辑pkgs/sources/lib/sources.rb指向自己的服务器
  3. Rebuild the gem by issuing a rake package – which will build the rubygems update gem with your source changes (in pkg/ – in my case pkg/rubygems-update-0.9.2.gem )重建的宝石发出一rake package -这将建立创业板的rubygems更新与来源的变化( pkg/ -在我的情况pkg/rubygems-update-0.9.2.gem
  4. Copy this gem to your gem server's gems directories (and rebuild the yaml index as appropriate)复制到您的这个宝石宝石服务器的宝石目录(和重建适当的YAML指数)
  5. On your other servers – clear out [lib/ruby]/gems/1.8/cache在您的其他服务器-清除[lib/ruby]/gems/1.8/cache
  6. Remove the [lib/ruby]/gems/1.8/source_cache删除[lib/ruby]/gems/1.8/source_cache
  7. Run gem update --system --source http://yourserver.yourdomain运行gem update --system --source http://yourserver.yourdomain
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值