值得再去一次的地方, 吃的喝的都免费

离4月19日度假归来已经4天, 但是一回到家,就伴随着耳鸣、咳嗽,流鼻涕、全身乏力, 一直到今天还是如此;-(, 相当难受!

虽然归来已经几天,但是想到在那宛如天堂的地方, 都会不由自主的发自内心的笑…

我们这次的目的地是马尔代夫卡尼岛(参考:

http://baike.baidu.com/view/481080.htm

), 行程为6日4晚, 意思就是两天在飞机, 4天在岛上。

我们4月14日启程, 刚开始不顺利, 早上我闹钟不醒, 我没有洗漱就出门, 接着是我的Parter 忘记带了护照, 还好有磁悬浮, 最终我们顺利赶到机场, 乘坐新加坡航空飞6个小时到新加坡,然后等7个小时, 再从新加坡飞4个小时到达马尔代夫马累机场,然后坐30分钟的船, 晚上10点(北京时间4月15日凌晨1点)到达卡尼岛。

因为到达岛上已经晚上10点多, 我们放好行李,就直奔岛上的酒吧喝酒了, 在海边,享受海风, 端着酒,抽着烟, 就这样开始我们的卡尼岛度假了…

一早起来, 去吃完丰盛的早餐,然后去参加台湾姑娘G.O关于岛上 活动的说明会, 岛上的很多活动都是免费的, 当然包括吃的。我们今天的计划是去浮潜, 参加测试后, 工作人员发给我们工具, 然后坐船离岛10分钟的路程, 带好潜水用具,就到海里看鱼了。

由于是第一次潜水,还不是很熟悉, 而且海浪比较大, 一不小心,我的相机掉到海里了;(, 有些郁闷, 不过遨游在海里, 谁会介意这些小事?看着海中哪些以前只有电视看到的漂亮的鱼, 你会觉得爽呆了…

图片

浮潜45分钟后,我们就返回岛上了, 我们到游泳池占了两个位置, 点了饮料(当然都是免费的), 就开始边游泳,边看晒太阳,看着远处的美景。岛上以欧美人比较多,特别是法国人,其次有来自中国大陆,台湾、香港,泰国,韩国、日本等国家,也许欧美人享受习惯了, 他们或许都是以生活为主, 感觉这就是他们的生活。他们是不介意阳光爆晒的。晚上7:30开饭, 有意大利菜,法国菜,泰国菜,中国菜,很多点心。

接着晚上9:30,是岛上每天都举行的主题晚会,一直到11点多,一天的行程结束了。

16日

因为前一天已经玩的太累, 这天主要是环岛游,划船,帆船,游泳池晒太阳为主。晚上还是酒吧…

17日

今天就要搬去水上屋,所以一大早起来,就直接在游泳池等了,下午2点钟才搬过去。水上屋有专门的保安,一进去才知道那才是整个岛的精华所在,我震撼了。吃的、住的都比外面高一个级别啊。 水上屋才有免费的WIFI,吧台精致的点心,各种饮料等等。屋下面,可以直接游泳,看鱼,或者看远方的美景。一切是那么的和谐。需要注意的是14岁以下的小孩是不可以住水上屋的。 晚上还可以看到魔鬼鱼。屋内也准备了香槟、咖啡,放着CD,早餐有服务员送来,终于感受到了什么叫做被服务了,原来这才是生活啊。 至少我再一次被震撼了,即使住怎么样的5星级酒店都感觉不如卡尼岛的水上屋啊, 因为那种风景是一般的酒店没有的。

18日

因为今天离岛时间,但是要等到晚上8:25分, 所以今天我们的计划还是浮潜, 因为今天涨潮,又看到了之前没有看到的鱼,收获颇丰啊。

图片

晚上8:25分,在卡尼岛G.O的热情欢送下,我们去了马尔代夫机场。 晚上11:25的航班, 飞了4个小时,到达新加坡机场,候机2个小时, 再飞6个小时,北京时间4月19日15点钟, 到达上海浦东国际机场,旅程结束。

推荐

水上屋

tips:

那里是岛上的精华,记得保安说过,之前有一个法国人,包了岛上的全部水上屋,住了两个星期。

西餐

岛上的西餐厅,需要提前一天预定, 但是那是免费的

浮潜

浮潜可以看到很多漂亮的鱼,还有珊瑚,那时其他地方没有的。且也是免费的。

其他

如果到那个地方, 就不要带伞去了,那里就是去晒太阳的。如果不会讲英文,岛上有讲中文的G.O, 他们大部分来自台湾。好像大陆有一个。

不要在岛上买东西了,一个打火机就两美金,其他东西贵到什么程度呢?

其实文中叙述的,都不能道出在那边的感受的十分之一, 而且很重要的一点,那里中国人很少, 你不会看到不和谐的事情发生。

–EOF–

转载请注明:韦旭红的点点滴滴 » 马尔代夫-卡尼岛(Kani)

_.bindAll(this, 'render');
			this.model.bind('change', this.render);

以上这两行代码主要为了当model改变时, view执行render, 那_.bindAll有什么用呢?

看这里:http://stackoverflow.com/questions/6079055/why-do-bindall-in-backbone-js-views

其中有一段是这样的:

Without _.bindAll( this, 'render' ) when model changes this in render will be pointing to the model, not to the view, so we won't have neither this.el nor this.$ or any other view's properties available.

当model被change时, this指向model, 但是我们要执行render, 那么就需要_.bindAll(this, ‘render’), 使model也有这个render的方法?

请达人解答?

  • 新版本这样就可以

this.model.bind(‘change’, this.render, this);

Screen Shot 2011-10-14 at 1.55.50 PM.png

Screen Shot 2011-10-14 at 2.06.54 PM.png

Screen Shot 2011-10-14 at 2.18.03 PM.png

Screen Shot 2011-10-14 at 3.31.51 PM.png

Screen Shot 2011-10-14 at 3.33.11 PM.png

Screen Shot 2011-10-17 at 5.20.27 PM.png

Screen Shot 2011-10-18 at 3.37.23 PM.png

转载请注明:韦旭红的点点滴滴 » 关于backbone _.bindAll

% mkdir -p ~/Library/Application Support/Textmate/Bundles
% cd ~/Library/Application Support/Textmate/Bundles
% git clone git://github.com/lautis/ruby-on-rails-tmbundle.git "Ruby on Rails.tmbundle"
% git clone git://github.com/lautis/ruby-tmbundle.git "Ruby.tmbundle"
% osascript -e 'tell app "TextMate" to reload bundles'

转载请注明:韦旭红的点点滴滴 » APIdock in Textmate

gem install passenger

yum install apr-devel
yum install apr-util-devel
yum install httpd-devel
passenger-install-apache2-module

复杂以下文件到httpd.conf

LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.2-p290-module/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/rvm/gems/ruby-1.9.2-p290-module/gems/passenger-3.0.9
   PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.2-p290-module/ruby
#For PAIFAN 后台
<VirtualHost *:80>
 ServerName padmin.qdigit.cn
 RailsEnv production
 #RailsEnv development 
 DocumentRoot /var/www/html/admin.insta/public
 ErrorLog /var/www/html/admin.insta/log/redmine.error.log
  <Directory /var/www/html/admin.insta/public>
  AllowOverride all
  #Options -MultiViews           
  Options Indexes -MultiViews
 </Directory>
</VirtualHost>

参考: http://www.modrails.com/install.html

转载请注明:韦旭红的点点滴滴 » 安装passenger for rails3

在了解 Moutable之前, 先看这个视频:

http://railscasts.com/episodes/277-mountable-engines

了解Mountable Engines与Full Engines的区别, 看这篇文章:

http://stackoverflow.com/questions/6118905/rails-3-1-engine-vs-mountable-app

当我们使用:

rails plugin new uhoh --mountable

我们可以把这个创建好的plugin变成一个gem来使用。

比如我们可以先创建一个rails app

rails new with_engine -T -O -J

编辑Gemfile, 添加以下一行:

gem 'uhoh', :path => '/Users/weston/Downloads/277-mountable-engines/uhoh-after/' #刚才创建的mountable 路径

执行

bundle install 

vim config/routs.rb

添加以下一行:

mount Uhoh::Engine => "/uhoh", :as => "uhoh_engine"

这样我们就可以使用这个engines了…

转载请注明:韦旭红的点点滴滴 » rails 3.1 Mountable Engines 使用方法

可以参考:

http://stackoverflow.com/questions/1531514/observers-vs-callbacks

其中有一段是这样的:

class Model < ActiveRecord::Base
  before_update :disallow_bob

  def disallow_bob
  return false if model.name == "bob"
  end
end

class ModelObserver < ActiveRecord::Observer
  def before_update(model)
    return false if model.name == "mary"
  end
end

m = Model.create(:name => "whatever")

m.update_attributes(:name => "bob")
=> false -- name will still be "whatever" in database

m.update_attributes(:name => "mary")
=> true -- name will be "mary" in database

Observers may only observe, they may not intervene.

转载请注明:韦旭红的点点滴滴 » 关于Rails使用Callback和Observer的区别

来源:http://jimdrannbauer.com/2011/01/29/rails-3-rspec-cucumber-jquery-devise-mongoid-and-compass/

Want to build a Rails 3 app with this stuff?

Git
RSpec
Cucumber w/ Capybara
Mongoid
Devise
CanCan
jQuery
Compass
Blueprintcss
Haml
Sass
Capistrano
Passenger
Factory Girl
Shoulda
metric_fu
Here’s how.

Just A Checklist

This article is mostly written for myself so I don’t have to remember where I found all of the information. There’s nothing particularly difficult about anything here. I just like the idea of having it all in one place. I figured it might be helpful to others, so… uh… here it is.

Having said that, this is not a tutorial. I don’t explain how to do Behavior Driven Development, how to use CanCan, or why to use any of this stuff. It’s just a checklist… a detailed checklist. It would probably make a good Rails Template.

Prerequisites

The installation of MongoDB and Git are beyond the scope…

Initialize the app

In your shell:

mkdir awesome-app
cd awesome-app
git init
rails new . -T -J -O

Create the empty directory first so that you can init an empty git repo. The -T option excludes the Test/Unit files so that we can use RSpec instead. The -J option excludes the prototype.js files so that we can use jQuery instead. The -O option excludes ActiveRecord (O is for ORM) so that we can use Mongoid instead.

Commit it:

git add .
git commit -m "initial commit"
Bundle the Gems

Here’s the first place you need to modify files. In Gemfile:

source 'http://rubygems.org'
gem 'rails',    '3.0.3'
gem 'mongoid',  '2.0.0.rc.6'
gem 'bson_ext', '~> 1.2'
gem 'devise'
gem 'cancan'
gem 'jquery-rails'
gem 'passenger'
gem 'capistrano'
gem "compass", ">= 0.10.6"
gem 'haml'
group :development, :test do
  gem 'capybara'
  gem 'cucumber'
  gem 'cucumber-rails'
  gem 'database_cleaner'
  gem 'rspec'
  gem 'rspec-rails'
  gem 'shoulda'
  gem 'factory_girl_rails'
  gem 'autotest'
  gem 'launchy'
  gem 'faker'
  gem 'ruby-debug19'
  gem 'haml-rails'
  gem 'metric_fu'
end

Then, back in your shell:

bundle install

Commit it:

git add .
git commit -m "Added Gems"
Mongoid

Mongoid is an ORM for MongoDB. I’ll assume you have it installed already. Dig it:

# Ignore this message if you see it since you're
# running the command it's asking for right now:

# Mongoid config not found. Create a config file at: config/mongoid.yml
# to generate one run: rails generate mongoid:config
rails g mongoid:config

After running the mongoid generator, your app is configured to use Mongoid instead of ActiveRecord. When you generate a model, Rails will generate a Mongoid Document.

Let’s edit some files and get it set up.

In config/mongoid.yml:

defaults: &defaults
  host: localhost
  # mongoid defaults for configurable settings
  autocreate_indexes: false
  allow_dynamic_fields: true
  include_root_in_json: false
  parameterize_keys: true
  persist_in_safe_mode: false
  raise_not_found_error: true
  reconnect_time: 3
development:
  <<: *defaults
  database: awesome_app_development
test: &TEST
  <<: *defaults
  database: awesome_app_test
cucumber:
  <<: *TEST
# set these environment variables on your prod server
production:
  host: <%= ENV['MONGOID_HOST'] %>
  port: <%= ENV['MONGOID_PORT'] %>
  username: <%= ENV['MONGOID_USERNAME'] %>
  password: <%= ENV['MONGOID_PASSWORD'] %>
  database: <%= ENV['MONGOID_DATABASE'] %>

There are 2 things to notice here. First, the configurable settings can be excluded. Even though Mongoid will default to the above options, leave them so that you don’t have to look at the documentation. Second, we added an environment for Cucumber which just points back to the test environment.

Commit it:

git add .
git commit -m "Added Mongoid"
RSpec

Now, we use the rails generator to install RSpec. Shell:

rails g rspec:install
Next, in spec/spec_helper.rb:

RSpec.configure do |config|
  config.mock_with :rspec

  require 'database_cleaner'

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.orm = "mongoid"
  end

  config.before(:each) do
    DatabaseCleaner.clean
  end
end

This is all you need in your RSpec configuration to use it with Mongoid. MongoDB doesn’t do transactions so we need to truncate the database between tests instead of rolling back. DatabaseCleaner helps with that.

Commit it:

git add .
git commit -m "Added RSpec"

Cucumber

Next, we use the rails generator again to install Cucumber. Shell:

rails g cucumber:install --capybara --rspec --skip-database

The –capybara option sets up Capybara instead of Webrat. The –rspec option enables RSpec matchers for your step definitions.

The Cucumber generator will bark at you about a missing database.yml file without the –skip-database option because we skipped the ORM when we created the app.

Like RSpec, some configuration is necessary to make Cucumber play nice with Mongoid. Add this file, features/support/database_cleaner.rb:

require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid"
Before { DatabaseCleaner.clean }

This does the same thing for Cucumber that it does for RSpec: truncates your data between scenarios.

Commit it:

git add .
git commit -m "Added Cucumber"

Devise

Devise is used for authentication.

Shell it:

rails g devise:install
Devise needs a few things in place so that it can provide it’s functionality and it’ll let you know it when the installation is done:

===============================================================================

Some setup you must do manually if you haven't yet:

  1. Setup default url options for your specific environment. Here is an
     example of development environment:

       config.action_mailer.default_url_options = { :host => 'localhost:3000' }

     This is a required Rails configuration. In production it must be the
     actual host of your application

  2. Ensure you have defined root_url to *something* in your config/routes.rb.
     For example:

       root :to => "home#index"

  3. Ensure you have flash messages in app/views/layouts/application.html.erb.
     For example:

       

<%= notice %>

<%= alert %>

===============================================================================

For now, all you need to do are steps 1 and 2 above. We’ll handle step 3 when we get into the Haml/Sass/Compass stuff later.

In config/environments/development.rb, add this:

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

In config/routes.rb, add this:

root :to => "home#index"

Finally, Devise needs a model to hold login credentials. Let’s call it User. In the shell:

rails g mongoid:devise User

Take a look in app/models/user.rb. Notice that it generated a Mongoid Document.

Finish up by adding this to routes.rb:


devise_for :users
Commit it:

git add .
git commit -m "Added Devise"

CanCan

CanCan does role-based user authorization.


rails g cancan:ability
That’s it.

Commit it:


git add .
git commit -m "Added CanCan"

jQuery

We used the -J option when we created the app so that we could use jQuery instead of Prototype. In your shell, run the jQuery generator:


rails g jquery:install --ui

This’ll do 3 main things: remove the existing protoypejs-based javascript files (which, in our case, aren’t there anyway), drop in the latest jQuery, and drop in the jQuery version of the Rails Unobtrusive Javascript (UJS) Adapter. Since jQueryUI is pretty cool too, we drop that in too with the –ui option.

In order to make the :defaults argument to javascript_include_tag load the .js files in the right order, we need to modify config/application.rb. Look for:


config.action_view.javascript_expansions[:defaults] = %w()
and change it to:

config.action_view.javascript_expansions[:defaults] =
  %w(jquery.min jquery-ui.min rails)

Notice that we load the minified versions which were downloaded by the generator.

Commit it:


git add .
git commit -m "Added jQuery"
Compass/Haml/Sass/Blueprintcss

Haml is a template langauge like erb. When we added “gem ‘haml’” to the Gemfile, we made Rails recognize that files with the .haml extension contain Haml markup. Sass is a superset of css3 that helps keep your stylesheets clean. Blueprintcss is a css framework that provides easy to use reset, grid, and typographical styles. Compass ties all this together and provides a way to integrate it into your app.

Run this to install Compass into your app using Blueprintcss:


compass init rails . --using blueprint/semantic

Compass will ask you a few questions. Just say yes to both of them.


Compass recommends that you keep your stylesheets in app/stylesheets
  instead of the Sass default location of public/stylesheets/sass.
  Is this OK? (Y/n) Y

Compass recommends that you keep your compiled css in public/stylesheets/compiled/
  instead the Sass default of public/stylesheets/.
  However, if you're exclusively using Sass, then public/stylesheets/ is recommended.
  Emit compiled stylesheets to public/stylesheets/compiled/? (Y/n) Y

After that, it’ll drop a bunch of files into the app and finish up with some instructions. We’ve already done the first suggestion, added Compass to the Gemfile. The second suggestion gives us the opportunity to put together our layout.

Create app/views/layout/application.html.haml and place this inside:



!!! XML
!!!
%html
  %head
    %title Awesome App
    = javascript_include_tag :defaults
    = csrf_meta_tag
    = stylesheet_link_tag :all
    = stylesheet_link_tag 'compiled/screen.css', :media => 'screen, projection'
    = stylesheet_link_tag 'compiled/print.css',  :media => 'print'
    /[if lt IE 8]
      = stylesheet_link_tag 'compiled/ie.css', :media => 'screen, projection'

  %body.bp.two-col

    #container

      #header
        %h1 Awesome App Header

      #sidebar
        %div item 1
        %div item 2
        %div item 3
        %div item 4

      #content

        %p.notice= notice
        %p.error= alert
        %p.success= notice

        = yield

      #footer
        %h3 Awesome App Footer

There are a few things to notice in there. First, it’s Haml. Second, we’ve included the stylesheet info from the compass command output in the head. Third, we’re using the built-in Blueprintcss 2-column layout. Finally, we’ve added the notice and alert elements that Devise asked for earlier. There’s also a success element in there to show off some of the coloring that Blueprintcss gives you.

If you try to look at it now, it won’t work. Sit tight, we’re close.

Making Compass Just Work

The Compass documentation seems to lack a simple explanation of how to see if things just work. Here it is:

Create app/stylesheets/partials/_application.scss, and place this inside:


#container {
  @include showgrid;
}

Use this file to get started adding your own styles. The showgrid mixin is useful for debugging your Blueprintcss grid. Delete it or comment it out when you’re done.

Then, add this to app/stylesheets/screen.scss:

// Add the application styles.
@import “partials/application”;
This makes sure that your own styles are available when you get around to adding them.

Commit it:

git add .
git commit -m “Added Compass”
Last Steps Before Starting the App

Delete public/index.html:

rm public/index.html
Earlier, Devise instructed us to setup the root route in routes.rb. The problem is the route we added won’t actually work until we have a home controller with an index action.

Shell it:

rails g controller home index
Notice that the views generated use Haml. That works because we added the ‘haml-rails’ gem to the Gemfile.

Then, so that we can see Devise in action:

rails g controller vip index
In app/controllers/vip_controller.rb, add:

before_filter :authenticate_user!
Commit it:

git add .
git commit -m “Added Home and Vip controllers and views”
Start It Up

passenger start
Now go to: http://localhost:3000

Nice! See the grid? Clean.

How about this one? http://localhost:3000/vip/index

Go ahead. Mess with the login stuff. It’ll just kinda work.

One More Thing, metric_fu

Add this to your Rakefile:

require ‘metric_fu’
MetricFu::Configuration.run do |config|
config.rcov[:test_files] = [‘spec/**/*_spec.rb’]
config.rcov[:rcov_opts] << “-Ispec” # Needed to find spec_helper
end
Get your metrics by running this:

rake metrics:all
Commit it:

git add .
git commit -m “Added metric_fu”
Conclusion

Okay, so it doesn’t really do anything… yet. That’s okay. You’re smart. Make.

There were a few things in the list at the top that I didn’t go into more detail about (Capistrano, Passenger, Factory Girl, and Shoulda). That’s because they’re ready to go; inclusion in the Gemfile was enough. Just start using ‘em.

Links

Here’s a list of links to the documentation and articles I used to pull this together:

http://relishapp.com/rspec/rspec-rails

http://github.com/aslakhellesoy/cucumber-rails/blob/master/README.rdoc

http://github.com/thoughtbot/shoulda

http://github.com/thoughtbot/factory_girl_rails

http://mongoid.org/docs/installation

http://mongoid.org/docs/integration

http://mongoid.org/docs/extensions

http://github.com/plataformatec/devise

https://github.com/ryanb/cancan

http://www.tonyamoyal.com/2010/07/28/rails-authentication-with-devise-and-cancan-customizing-devise-controllers/

https://github.com/indirect/jquery-rails

http://haml-lang.com/

http://sass-lang.com/

http://compass-style.org/

http://blueprintcss.org/

https://github.com/joshuaclayton/blueprint-css/wiki

转载请注明:韦旭红的点点滴滴 » Rails 3, RSpec, Cucumber, jQuery, Devise, Mongoid, and Compass(转)

source 'http://rubygems.org'

# --------------------
#   Rails
# --------------------
# gem 'rails',                     '~> 3.0.0'
gem 'rails',                     :git => 'git://github.com/rails/rails.git', :branch => '3-0-stable'
# gem 'rails',                     :path => '/Users/fred/Downloads/Repos/Rails/rails-master'

# --------------------
#   Database
# --------------------
gem 'mysql2',                    :git => 'git://github.com/brianmario/mysql2.git'
gem 'datamappify',               '>= 0.2.1'
gem 'by_star',                   '~> 0.9.0'
# gem 'slim_scrooge',              '~> 1.0.10', :group => :production
# gem 'meta_where',                '>= 0.9.3'

# --------------------
#   Resources
# --------------------
gem 'inherited_resources',       '~> 1.1.2'
gem 'inherited_resources_views'
gem 'devise',                    '~> 1.1.2'
gem 'cancan',                    '~> 1.3.0'
gem 'carrierwave',               '~> 0.5.0'

# --------------------
#   Presentation
# --------------------
gem 'haml',                      '~> 3.0.18'
gem 'compass'
gem 'simple_form',               '~> 1.2.0'
gem 'simple-navigation',         '~> 2.7.0'
gem 'will_paginate',             '~> 3.0.pre'

# --------------------
#   Assets
# --------------------
gem 'rails_config'
gem 'rdiscount',                 '>= 1.6.5'
gem 'sanitize'
gem 'rubyzip',                   :require => 'zip/zip'
gem 'csv-mapper',                '>= 0.5.0'
gem 'ffaker',                    '>= 0.4.0'

# --------------------
#   Server/Deployment
# --------------------
gem 'dalli'
gem 'thin'
gem 'capistrano-ext'
gem 'deployer',                  :git => 'git://github.com/meskyanichi/deployer.git'
gem 'hoptoad_notifier'
gem 'newrelic_rpm'

group :development do
  gem 'bullet',                  '~> 2.0.0.rc1'
  gem 'hpricot',                 '>= 0.8.2'
  gem 'ruby_parser',             '>= 2.0.4'
end

group :development, :test do
  gem 'rspec-rails',             '~> 2.0.0.beta.22'
  gem 'steak',                   :git => 'git://github.com/cavalle/steak.git'
  gem 'capybara',                :git => 'git://github.com/jnicklas/capybara.git'
  gem 'delorean'
  gem 'database_cleaner'
  gem 'launchy'
  gem 'parallel_tests',          :git => 'git://github.com/grosser/parallel_tests.git'
  # gem 'parallel_tests',          :path => '/Users/fred/Downloads/Repos/Rails/fredwu-parallel_tests'
end

也可以参考:http://thoughtrails.com/episodes/24-popular-and-useful-plugins-for-rails3

转载请注明:韦旭红的点点滴滴 » 常用gem

来自:http://blog.prosight.me/index.php/2009/11/485

如果使用git的人数较少,可以使用下面的步骤快速部署一个git服务器环境。
1. 生成 SSH 公钥
每个需要使用git服务器的工程师,自己需要生成一个ssh公钥
进入自己的~/.ssh目录,看有没有用 文件名 和 文件名.pub 来命名的一对文件,这个 文件名 通常是 id_dsa 或者 id_rsa。 .pub 文件是公钥,另一个文件是密钥。假如没有这些文件(或者干脆连 .ssh 目录都没有),你可以用 ssh-keygen 的程序来建立它们,该程序在 Linux/Mac 系统由 SSH 包提供, 在 Windows 上则包含在 MSysGit 包里:

$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/schacon/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/schacon/.ssh/id_rsa.
Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.
The key fingerprint is:
43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local

它先要求你确认保存公钥的位置(.ssh/id_rsa),然后它会让你重复一个密码两次,如果不想在使用公钥的时候输入密码,可以留空。
现在,所有做过这一步的用户都得把它们的公钥给你或者 Git 服务器的管理者(假设 SSH 服务被设定为使用公钥机制)。他们只需要复制 .pub 文件的内容然后 e-

$ cat ~/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSU
GPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3
Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XA
t3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/En
mZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbx
NrRFi9wrf+M7Q== schacon@agadorlaptop.local
  1. 架设服务器
    首先,创建一个 ‘git’ 用户并为其创建一个 .ssh 目录,在用户主目录下:
$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh

接下来,把开发者的 SSH 公钥添加到这个用户的 authorized_keys 文件中。假设你通过 e-mail 收到了几个公钥并存到了临时文件里。只要把它们加入 authorized_keys 文件

$ cat /tmp/id_rsa.john.pub >> ~/.ssh/authorized_keys
$ cat /tmp/id_rsa.josie.pub >> ~/.ssh/authorized_keys
$ cat /tmp/id_rsa.jessica.pub >> ~/.ssh/authorized_keys

现在可以使用 –bare 选项运行 git init 来设定一个空仓库,这会初始化一个不包含工作目录的仓库。

$ cd /opt/git
$ mkdir project.git
$ cd project.git
$ git --bare init

这时,开发人员就可以把它加为远程仓库,推送一个分支,从而把第一个版本的工程上传到仓库里了。值得注意的是,每次添加一个新项目都需要通过 shell 登入主机并创建一个纯仓库。我们不妨以 gitserver 作为 git 用户和仓库所在的主机名。如果你在网络内部运行该主机,并且在 DNS 中设定 gitserver 指向该主机,那么以下这些命令都是可用的:

# 在一个工程师的电脑上

$ cd myproject
$ git init
$ git add .
$ git commit -m 'initial commit'
$ git remote add origin git@gitserver:/opt/git/project.git
$ git push origin master

这样,其他人的克隆和推送也一样变得很简单:

$ git clone git@gitserver:/opt/git/project.git
$ vim README
$ git commit -am 'fix for the README file'
$ git push origin master

用这个方法可以很快捷的为少数几个开发者架设一个可读写的 Git 服务。
作为一个额外的防范措施,你可以用 Git 自带的 git-shell 简单工具来把 git 用户的活动限制在仅与 Git 相关。把它设为 git 用户登入的 shell,那么该用户就不能拥有主机正常的 shell 访问权。为了实现这一点,需要指明用户的登入shell 是 git-shell ,而不是 bash 或者 csh。你可能得编辑 /etc/passwd 文件

$ sudo vim /etc/passwd

在文件末尾,你应该能找到类似这样的行:

git:x:1000:1000::/home/git:/bin/sh

把 bin/sh 改为 /usr/bin/git-shell (或者用 which git-shell 查看它的位置)。该行修改后的样子如下:

git:x:1000:1000::/home/git:/usr/bin/git-shell
现在 git 用户只能用 SSH 连接来推送和获取 Git 仓库,而不能直接使用主机 shell。尝试登录的话,你会看到下面这样的拒绝信息:

$ ssh git@gitserver

fatal: What do you think I am? A shell? (你以为我是个啥?shell吗?)
Connection to gitserver closed. (gitserver 连接已断开。)

转载请注明:韦旭红的点点滴滴 » 小组级git服务器搭建(转)