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月25日 星期一
2011年4月20日 星期三
rails + rubber + github + amazon ec2 free tier step by step
Reference:
Rubber wiki : https://github.com/wr0ngway/rubber/wiki/
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
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
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:
Step 8: set ssh-agent (optional : for deploy from github)
eval `ssh-agent -s`
ssh-add
Reference:
Step 9: deploy (Finally Gook Luck :p )
cap rubber:create_staging
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/
- 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日 星期一
2010年6月30日 星期三
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
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
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/
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
關於 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
2010年6月21日 星期一
capistrano path rake fail
http://blog.zerobearing.com/2009/04/27/capistrano-rake-command-not-found/
http://stackoverflow.com/questions/588934/using-ruby-enterprise-edition-gems-are-not-installed-where-i-would-expect
http://forum.slicehost.com/comments.php?DiscussionID=3657
http://stackoverflow.com/questions/257616/sudo-changes-path-why
http://groups.google.com/group/emm-ruby/browse_thread/thread/d0c685bbd096823a#msg_effa7d6ad42c541c
http://www.f15ijp.com/2009/11/30/sudo-no-tty-present-and-no-askpass-program-specified/
/etc/ssh/sshd_config:
PermitUserEnvironment yes
/etc/init.d/sshd restart
~/.ssh/environment
PATH=/opt/ruby-enterprise-1.8.7-2010.02/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
http://formatinternet.wordpress.com/2009/07/06/sudo-rake-command-not-found/
~/.bashrc
alias sudo='sudo env PATH=$PATH'
sudo ln -s `which rake` /usr/local/bin/
#sudo: no tty present and no askpass program specified error
the /etc/sudoers file.
#commend sudo visudo
Defaults visiblepw
http://stackoverflow.com/questions/588934/using-ruby-enterprise-edition-gems-are-not-installed-where-i-would-expect
http://forum.slicehost.com/comments.php?DiscussionID=3657
http://stackoverflow.com/questions/257616/sudo-changes-path-why
http://groups.google.com/group/emm-ruby/browse_thread/thread/d0c685bbd096823a#msg_effa7d6ad42c541c
http://www.f15ijp.com/2009/11/30/sudo-no-tty-present-and-no-askpass-program-specified/
/etc/ssh/sshd_config:
PermitUserEnvironment yes
/etc/init.d/sshd restart
~/.ssh/environment
PATH=/opt/ruby-enterprise-1.8.7-2010.02/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
http://formatinternet.wordpress.com/2009/07/06/sudo-rake-command-not-found/
~/.bashrc
alias sudo='sudo env PATH=$PATH'
sudo ln -s `which rake` /usr/local/bin/
#sudo: no tty present and no askpass program specified error
the /etc/sudoers file.
#commend sudo visudo
Defaults visiblepw
2010年6月13日 星期日
delayed_job capistrano production fail
主要參考
http://railscasts.com/episodes/171-delayed-job
http://www.magnionlabs.com/2009/2/28/background-job-processing-in-rails-with-delayed_job
不知道哪邊弄錯了用capistrano deploy 想啟動delayed_job 卻好像都沒反應
後來終於看到 有script/delayed_job run的指令 這個動作才可以讓你看到你錯在哪, start 只會無聲無息
http://railscasts.com/episodes/171-delayed-job
http://www.magnionlabs.com/2009/2/28/background-job-processing-in-rails-with-delayed_job
不知道哪邊弄錯了用capistrano deploy 想啟動delayed_job 卻好像都沒反應
後來終於看到 有script/delayed_job run的指令 這個動作才可以讓你看到你錯在哪, start 只會無聲無息
2010年6月10日 星期四
rmagic cannot open shared object file: No such file or directory
libMagickCore.so.* cannot open shared object file: No such file or directory
http://github.com/jnstq/rails-nginx-passenger-ubuntu
To get rid of this error i executed
ldconfig /usr/local/lib
http://github.com/jnstq/rails-nginx-passenger-ubuntu
To get rid of this error i executed
ldconfig /usr/local/lib
2010年6月3日 星期四
nginx passenger config
nginx, worker_processes, and passenger_max_pool_size
Production Rails Tuning with Passenger: PassengerMaxProcesses
超小型web server 設定
How to save MUCH RAM when running rails (linode/slicehost) and mod_rails passenger
Production Rails Tuning with Passenger: PassengerMaxProcesses
worker_processes 4; <= Setting the number of Nginx workers to the number of CPU cores should be sufficient.
http {
passenger_max_pool_size 20; # memory 256M should be 2, 2G should be 30, max_pool 不要設太大, 不要讓它吃到swap, free -ml ; vmstat 2 都可以看到現在memory 的情況
passenger_max_instances_per_app 15; #每種ap 能用到最多的instance, 所以如果跑兩個app 就會再少一點
# PassengerPoolIdleTime
# Recommended to be avg time per page * 2
# In Google Analytics... (Avg time on site / Avg page views) * 2
# Default: 300
passenger_pool_idle_time 144
}
超小型web server 設定
How to save MUCH RAM when running rails (linode/slicehost) and mod_rails passenger
2010年5月7日 星期五
2010年4月20日 星期二
[Ptt][心得] Restful下遇到params[:id]含有.的解法
在restful的前提下, 遇到class的to_param是字串, 而剛好某筆
紀錄的to_param欄位含有.
一般情形下會發生錯誤, 因為restful會把.後的東西當成format
這時的解法, 變成要在routes.rb中的xxx.resources加上參數
ex:
紀錄的to_param欄位含有.
一般情形下會發生錯誤, 因為restful會把.後的東西當成format
這時的解法, 變成要在routes.rb中的xxx.resources加上參數
ex:
2010年4月16日 星期五
2010年4月15日 星期四
2010年4月6日 星期二
2010年3月10日 星期三
respond_to jsonp
respond_to recognizes • JSON.
render :json => @person.to_json automatically sets the content type and takes a :callback option to specify a client-side function to call using the rendered JSON as an argument. #4185 [Scott Raymond, eventualbuddha]
render :json => @person.to_json automatically sets the content type and takes a :callback option to specify a client-side function to call using the rendered JSON as an argument. #4185 [Scott Raymond, eventualbuddha]
訂閱:
文章 (Atom)