5月 10, 2012

在Amazon ec2上用ubuntu11 建立 rails server(apache2+passenger)

在Amazon ec2上用ubuntu11 建立 rails server(apache2+passenger)

改root密碼

sudo su passwd

換預設編輯器

/usr/bin/select-editor

換port

vim /etc/ssh/sshd_config

1.Port 7533 2. PasswordAuthentication yes

/etc/init.d/ssh restart

調整server時間

dpkg-reconfigure tzdata # 將時區設回台灣 ntpdate time.stdtime.gov.tw

安裝系統套件

sudo apt-get update sudo apt-get upgrade sudo apt-get install git sudo apt-get install mysql-server libmysqlclient15-dev sudo apt-get install curl sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline6-dev sudo apt-get install libbuilder-ruby

安裝ruby

sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev libv8-dev autoconf libc6-dev xclip ncurses-dev automake

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz

tar xvf ruby-1.9.3-p194.tar.gz ./configure make make install

安裝rails

gem install rails --no-rdoc --no-ri gem install mysql --no-rdoc --no-ri gem install passenger --no-rdoc --no-ri sudo apt-get install nodejs Install CURL with SSL sudo apt-get install libcurl4-openssl-dev

Install Apache

sudo apt-get install apache2 sudo apt-get install apache2-prefork-dev

Install Passenger on Apache

passenger-install-apache2-module 把passenger掛到Apache裡 sudo vim /etc/apache2/mods-enabled/mod_rails.conf 貼上Passenger輸出的路徑

example: LoadModule passengermodule /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.12/ext/apache2/modpassenger.so PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.12 PassengerRuby /usr/local/bin/ruby

設定visualhost vim /etc/apache2/sites-enabled/release.conf

<VirtualHost *:80> ServerName 114.34.169.207 DocumentRoot /home/joehwang/project/appwed/public <Directory /home/joehwang/project/appwed/public > AllowOverride all Options -MultiViews </Directory> </VirtualHost>

安裝Imagemagick

sudo apt-get remove imagemagick sudo apt-get install libperl-dev gcc libjpeg62-dev libbz2-dev libtiff4-dev libwmf-dev libz-dev libpng12-dev libx11-dev libxt-dev libxext-dev libxml2-dev libfreetype6-dev liblcms1-dev libexif-dev perl libjasper-dev libltdl3-dev graphviz gs-gpl pkg-config

下載編譯 wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz tar zxvf ImageMagick.tar.gz cd ImageMagick-* ./configure make sudo make install gem install rmagick

安裝memcache

sudo apt-get install memcached libmemcache-dev libsasl2-dev gem install memcached gem install memcache-client

讓alpha server和production server可以使用key互相登入

alpha -> production免key 在alpha server中

ssh-keygen -t rsa

如此便產生公鑰和私鑰 把公鑰 xxx.pub 傳到 production server

scp -P 7533-i /.key/登入ec2的金鑰.pem /home/joehwang/.ssh/id_rsa.pub 帳號@遠端ip:

在production server中

把xxx.pub移到~/.ssh資料夾

mv xxx.pub ~/.ssh/

並把xxx.pub內容附加到authorized_keys

cat ~/.ssh/xxx.pub >> ~/.ssh/authorized_keys

如此使用ssh://帳號@ip -p 埠號,便可直接登入 其他帳號也要直接連入,一樣把alpha的pub檔內容,附加到該帳號的authorized_keys就行了

沒有留言: