2011年4月25日 星期一

RuntimeError: !!! Missing the mysql2 gem

Rails 3 install mysql2 gem fail

production:
adapter: mysql2
encoding: utf8
reconnect: false
database: blog
pool: 5
username: root
password:
socket: /var/run/mysqld/mysqld.sock


Change the adapter, and find your socket file

2011年4月20日 星期三

rails + rubber + github + amazon ec2 free tier step by step

Reference:
Rubber wiki : https://github.com/wr0ngway/rubber/wiki/

How to deploy a Rails app to EC2 in less than an hour using Rubber
http://ginzametrics.com/deploy-rails-app-to-ec2-with-rubber.html


Step 1: Amazon Registration
http://www.amazon.com/gp/aws/registration/registration-form.html

  • reference: http://www.inside.com.tw/2010/11/02/amazon-aws-1


Step 2: Check
You could check your amazon account status here, your billing
https://aws-portal.amazon.com/gp/aws/developer/account/index.html

Amazon service console
https://console.aws.amazon.com/ec2/home

Amazon Security Credentials, you could get your keys here
https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key


Step 3: Get your key pair
https://console.aws.amazon.com/ec2/home?region=us-east-1#s=KeyPairs
You will download a private key here like : keyname.pem


Step 4: Install rubber in your project
sudo gem install rubber
rails generate vulcanize complete_passenger_mysql


Step 5: Generate your public key in ~/.ec2
Change keyname.pem to keyname
chmod 400 keyname
ssh-keygen -y -f keyname > exviewkey.pub



Step 6: Edit your config/rubber/rubber.yml

1)
cloud_providers → aws → access_key
cloud_providers → aws → secret_access_key
cloud_providers → aws → account
cloud_providers → aws → keyname
cloud_providers → aws → keyname_file_location

access_key: ABCDEFGHIJKLMNOPQRST
secret_access_key: ABCDEFGHIJKLMNOPQRSTUVWXY1234567890+zabc
account: 123456789012 #account original would show like 1234-5678-9012
key_name: exviewkey #the name of private key you download
key_file: "#{Dir[(File.expand_path('~') rescue '/root') + '/.ec2/*' + cloud_providers.aws.key_name].first}"


2) Change the server timezone, and domain
timezone: US/Pacific
domain: webiste.com


3) Change your image type
image_type: t1.micro
image_id: 'ami-3e02f257'


It is my image type, you could find more in
  • http://uec-images.ubuntu.com/releases/10.10/release/
  • http://uec-images.ubuntu.com/releases/10.04/release/
  • http://aws.amazon.com/amis/Linux?browse=1
  • http://cloud.ubuntu.com/ami/
Reference:
  • http://groups.google.com/group/rubber-ec2/browse_thread/thread/dfff07e016a28896

4) Change the app_user, app_name
app_user: www-data
app_name: websitename


Step 7: Edit deploy.rb
ssh_options[:forward_agent] = true #optional : for deploy from github
set :repository, "git@github.com:yourname/projectname.git"
set :scm, "git"
set :deploy_via, :remote_cache
set :branch, 'master'


Reference:
  • http://groups.google.com/group/rubber-ec2/browse_thread/thread/bdf75bebb38eec2a/23fac77708767390?lnk=gst&q=github#23fac77708767390


Step 8: set ssh-agent (optional : for deploy from github)
eval `ssh-agent -s`
ssh-add


Reference:
  • http://groups.google.com/group/rubber-ec2/browse_thread/thread/73e50e32264768f6/ee1b4f497d621797?lnk=gst&q=github#ee1b4f497d621797
  • http://www.josephj.com/article/understand-ssh-key/


Step 9: deploy (Finally Gook Luck :p )
cap rubber:create_staging






2010年12月13日 星期一

fb comment

http://developers.facebook.com/docs/reference/plugins/comments

Unique ID 填了反而不行用 是怎樣 = =

2010年6月30日 星期三

rails 設定多個 smtp account 寄信

Using multiple SMTP accounts with Rails & ActionMailer

可利用此技巧, 達到多SMTP 寄信的目的

2010年6月24日 星期四

haproxy nginx passenger munin

step1: nginx need stub_status_module
compile with [--with-http_stub_status_module]

step2: install munin
sudo apt-get install munin munin-node

 
#/etc/munin/munin.conf
#This will tell munin to connect to munin-node at 127.0.0.1 on the same machine.
[foo.net]
address 127.0.0.1
use_node_name yes


#Edit the file /etc/munin/munin-node.conf and change # Which port to bind to set
host 127.0.0.1

#Make sure that this is present in the file

allow ^127\.0\.0\.1$



http://github.com/barttenbrinke/munin-plugins-rails
http://www.alfajango.com/blog/how-to-monitor-your-railspassenger-app-with-munin/
http://github.com/jnstq/munin-nginx-ubuntu

 
#haproxy setting
reqisetbe ^Host:\ munin.foo.net foomunin

#nginx config
server {
listen 6166;
server_name munin.foo.net;
root /home/foo/deploy/shared/directory/munin;
}


#/etc/munin/plugin-conf.d/munin-node
[foo_*]
env.log_file '/home/foo/app/production.log'
user foo
command /opt/ruby-enterprise-1.8.7-2010.02/bin/ruby %c
env.graph_category Foo



2010年6月22日 星期二

rails ip 辨識國家

how-to-know-user-location-with-rails
github geoip
Super fast IP to lat/lng in Rails

下載點 http://geolite.maxmind.com/download/geoip/database/

haproxy rails ip

haproxy不能正確記錄客戶端的IP
關於 rails 的扔remote_ip
http://kkito.cn/index.php/blog/getArticle/102/rails%E4%B8%AD%E5%BA%94%E6%B3%A8%E6%84%8F%E5%8F%AF%E8%83%BD%E5%AE%A2%E6%88%B7%E7%AB%AFip%E5%9C%B0%E5%9D%80%E6%98%AF%E4%BC%AA%E8%A3%85%E7%9A%84