`
jjzxcc
  • 浏览: 2694 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Environment setting document

 
阅读更多

This install guideline attempts to help you to deploy Shapado to your server from beginning to end.

Those software will be installed in the following order:
Git, Curl, RVM, Ruby, Rails, Mongodb, Install Shapado, Passenger, Nginx and Capistrano

Install Git
1. Retrieving necessary libraries

$sudo apt-get build-dep git-core git-doc  

2. Download git-1.7.X.tar.gz

3. Untar Git

$tar zxvf git-1.7.X.tar.gz

4. Change into the Git directory

$cd git-1.7.X.tar.gz

5. Configure it

$./configure --prefix=$HOME

6. Make it and install it

$make && sudo make install

 

Probable Error:

$make && sudo make install
/bin/sh:  curl-config: not found
       CC daemon.o
In file included from cache.h:4:0,
                        from daemon.c:1:
git-compat-util.h:168:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
make: *** [daemon.o] Error 1

 

Solution:

$sudo apt-get install libssl-dev

 

Install Curl

1. Downloads curl-7.21.X.tar.gz

2. Untar Curl

$tar zxvf curl-7.21.X.tar.gz

 

3. Change into the Curl directory

$cd curl-7.21.X

 

4. Make it and install it

$make && sudo make install 

 

Probable Error:

$make && sudo make install
error while loading shared libraries: libcurl.so.3: cannot open shared object file: No such file or directory

 

Solution:

$sudo ln -s /usr/local/lib/libcurl.so.4 /usr/lib/libcurl.so.4

 

Install RVM
1. Download and run the RVM installation script
Installing the latest release version in git:

$curl -L https://get.rvm.io | bash -s stable

 

Installing a specific version:

$curl -L https://get.rvm.io | bash -s -- --version latest

 
2. Load RVM into your shell sessions as a function
Throughout these instructions, you may replace .bash_profile with the appropriate startup script for your bash-compatible shell. For other shells you may need to modify these commands.

Single-User:

The rvm function will be automatically configured for every user on the system if you install as single user. Read the output of installer to check which files were modified.

Multi-User:

The rvm function will be automatically configured for every user on the system if you install with sudo. This is accomplished by loading /etc/profile.d/rvm.sh on login. Most Linux distributions default to parsing /etc/profile which contains the logic to load all files residing in the /etc/profile.d/ directory. Once you have added the users you want to be able to use RVM to the rvm grou p, those users MUST log out and back in to gain rvm group membership because group memberships are only evaluated by the operating system at initial login time. Zsh not always sources /etc/profile so you might need to add this in /etc/**/zprofile:

source /etc/profile

 

3. Reload shell configuration & test

Close out your current shell or terminal session and open a new one (preferred). You may load RVM with the following command:

$ source ~/.rvm/scripts/rvm

 

If installation and configuration were successful, RVM should now load whenever you open a new shell. This can be tested by executing the following command which should output 'rvm is a function' as shown below.

$ type rvm | head -1
rvm is a function

 
Finally, see if there are any dependency requirements for your operating system by running:

$ rvm notes

 

NOTE: Whenever you upgrade RVM in the future, you should always run 'rvm notes' as this is usually where you will find details on any major changes and/or additional requirements to ensure your installation stays working.

Install Ruby
1. Install a version of Ruby (eg 1.9.2):

$rvm install 1.9.3


2. Use the newly installed Ruby:

$rvm use 1.9.3

 

Optionally, you can set a version of Ruby to use as the default for new shells. Note that this overrides the 'system' ruby:

$rvm use 1.9.3 --default


Install Rails

$gem install rails

 

Probable Error:

Error:File not found:lib

 

Solution:

(1)$gem install rails --no-ri --no-rdoc
(2)$gem uninstall rails
   $gem install rdoc-data
   $rdoc-data --install
   $gem rdoc --all --overwrite
   $rdoc-data
   $gem install rails

 

Install Mongodb
1. To use the packages, add the following line to /etc/apt/sources.list

deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen

 

2. Add the 10gen GPG key.The public gpg key used for signing these packages follows. It should be possible to import the key into apt's public keyring with a command like this:

$sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

 

3. Update the sources

$sudo apt-get update

 

4. Install desired package

$sudo apt-get install mongodb-10gen

 

Probable Error:

$mongo
Error: couldn't connect to server 127.0.0.1 shell/mongo.js:79
exception: connect failed

 

Solution:

$mongod or $mongod --dbpath /var/log/mongodb

 

Reference:http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages

Install Shapado
== Dependencies

- git >= 1.5
- ruby >= 1.9.2
- rubygems >= 1.3.7
- mongodb >= 1.7
- ruby on rails 3

== Install Dependencies

$gem install bundler

== Getting Started

1. Download the sources:

 $git clone git://gitorious.org/shapado/shapado.git

 $cd shapado/

 

2. Configure the application

 

$cp config/shapado.yml.sample config/shapado.yml
$cp config/mongoid.yml.sample config/mongoid.yml
$cp config/auth_providers.yml.sample config/auth_providers.yml

 

    edit shapado.yml

3. Install dependencies

 

$bundle install


4. Load default data

$rake bootstrap RAILS_ENV=development

 

5. Add default subdomain to /etc/hosts, for example:

"0.0.0.0 localhost.lan group1.localhost.lan group2.localhost.lan"

 

6. Start the server

$rails server -e development

 

Probable Error:
1. $rake bootstrap RAILS_ENV=development
Error: Could not find nokogiri-1.4.4 in any of the sources
Solution:
$sudo apt-get install libxml2-dev libxslt-dev

2. Error:
/home/expedia/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:4: warning: already initialized constant MAJOR
/home/expedia/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:5: warning: already initialized constant MINOR
/home/expedia/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:6: warning: already initialized constant BUILD
.
.
.
/home/expedia/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake.rb:65: warning: already initialized constant RakeFileUtils
Solution:
1. Please verify the rake installation with gem list | grep 'rake'. You will likely to see rake (0.9.2 ruby). I have no idea what ruby means, but it seems a duplication of rake that is installed @global.
2. Remove the duplicated version with gem uninstall rake. Please say Y for both 2 questions. Verify again with gem list | grep 'rake' and this time the output is rake (0.9.2). That’s it, this has fixed the issue. I speculate this is a bug with RVM.

3. Error: undefined method `exitstatus' for nil:NilClass
Solution: sudo apt-get install openjdk-6-jdk


Install Passenger
$gem install passenger

Install Nginx

1. Run the Phusion Passenger installer for Nginx:
$sudo passenger-install-nginx-module or
$sudo /usr/local/rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.8/bin/passenger-install-nginx-module

Probable Error:
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/libm.so: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make[1]: *** [objs/nginx] Error 1
make[1]: Leaving directory `/tmp/root-passenger-26428/nginx-1.0.6'
make: *** [build] Error 2
Solution:
$sudo apt-get install gcc-4.4 g++-4.4 libstdc++6-4.4-dev
$rvmsudo CC=gcc-4.4 passenger-install-nginx-module

2. Modify Nginx configuration(/opt/nginx/conf/nginx.conf)
Add our server configuration

   server {
        listen 80;
        server_name domain.com;
        root /where/your/app/public; # <--- be sure to point to 'public'!
        passenger_enabled on;  # passenger_enabled must be on.
        rails_env development; # Shapado app must use development env.
      }
Or
  server {
    listen       80;
    server_name  domain.com;

    location / {
      root /where/your/app/public; # <--- be sure to point to 'public'!   
      index  index.html index.htm;
      passenger_enabled on; # passenger_enabled must be on.
      rails_env development; # Shapado app must use development env.
    }
  }

3. Run Nginx
Shut down all of nginx processes
$sudo killall -9 nginx

Start nginx
$sudo /opt/nginx/sbin/nginx

Install Capistrano

1. Install capistrano
$gem install capistrano

2. With the gem installed lets “capify” our project. Make sure your in your current project directory and run the following command.
$capify .
This should create a couple of files but the one we are interested in is deploy.rb. This file holds all of the details that cap needs to deploy the application to our server. It also gives us a place to write any extra tasks that might need to be performed on our application.

3. Modify config/deploy.rb

3.1 Git Setup
By convention, Capistrano uses Subversion. So, I need to change my configuration to use git. The set :scm, :git does this. The repository information sets up where my git repository lives. In this case, I’m just using a bare git repository accessing it over SSH. You can also access your repository using the git and http protocols if you have that setup. The branch just says to deploy off of the master branch.
Sample:
set :scm, :git
set :repository, "git@github.com:weij/shapado.git"
set :branch, "master"
set :deploy_via, :remote_cache

3.2 Passenger Setup
The only thing that comes into play with Passenger is restarting the Rails application after a deployment is done. Passenger has an easy way to do this which is just to create a file called restart.txt in the Rails tmp directory. When it sees that, the Rails application process will be recycled automatically.

Doing this requires just a bit of Capistrano customization. We need to override the deploy:restart task and have it run a small shell script for us. In this case we are running run “touch #{current_path}/tmp/restart.txt” to accomplish this task.
Sample:
namespace :deploy do
  desc "Restarting mod_rails with restart.txt"
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "touch #{current_path}/tmp/restart.txt"
end

We can also override the start and stop tasks because those don’t really do anything in the mod_rails scenario like they would with mongrel or other deployments.
Sample:
[:start, :stop].each do |t|
    desc "#{t} task is a no-op with mod_rails"
    task t, :roles => :app do ; end
  end
end

3.3 The Whole Thing
Putting everything together in my deploy.rb looks like the following:

set :user, 'me'
set :password, "my_password"
set :domain, 'me.com'
set :application, 'myapp'
set :branch, "#{branch}" # OR WHATEVER BRANCH YOU WANT TO USE

set :rake, "GEM_PATH=/home/#{user}/webapps/#{application}/gems:/home/#{user}/webapps/#{application}/gems/bin /home/#{user}/webapps/#{application}/bin/rake"
set :repository, "#{user}@#{domain}:/home/#{user}/git/#{my_repo}"
set :scm, :git
set :deploy_via, :checkout
set :scm_command, "/home/#{user}/bin/git" # PATH TO YOUR GIT COMMAND LINE
set :scm_password, "#{password}"
set :scm_passphrase, "#{password}"
set :local_scm_command, "git"
set :use_sudo, false
set :scm_verbose, true
set :git_shallow_clone, 1
set :deploy_to, "/home/#{user}/webapps/#{application}/#{application}"
set :group_writable, false
default_run_options[:pty] = true
ssh_options[:forward_agent] = true

role :app, domain
role :web, domain
role :db, domain, :primary => true

namespace :deploy do
 task :start do ; end
 task :stop do ; end
 task :restart, :roles => :app, :except => { :no_release => true } do
   run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
 end
end

after "deploy:update", "deploy:cleanup" # OTHER WISE OLD RELEASES WILL NOT BE DELETED EVEN THOUGH KEEP IS SET

4. Ask Capistrano to create set of folders for deployments in the remote machine
$cap deploy:setup
This will login to the server and create all the folders. This is where our rails application will be set up on our server. Note how we don’t have to enter a password. SSH keys are great when dealing with cap because entering a password for each deployment gets old quickly.

5. Specify your dependencies with Capistrano
$cap deploy:check
Cap will go ahead and make sure your server has correct permissions to deploy your application. It will also check for any needed software such as source control managers. Once this is done and works then we are ready to deploy our application.

6. Deploy your application
$cap deploy
This will install the application on the server in the deploy_to path. It will also create a number of symlinks. Its a great way of deploying an application because if something goes wrong it will roll back to the last version.

7. Visite your domain.

Reference:
1. http://tech.wangyaodi.com/2010/07/30/study-notes-passenger-capistrano-nginx-rails-2-3-4-ubuntu-9-04-10-steps/
2. http://hhhj.iteye.com/blog/484546
3. http://www.liangwenke.com/blog/8
4. http://rtmatheson.com/2011/07/setting-up-nginx-to-work-with-rails-capistrano-and-ssl/
5. http://www.theboohers.org/development/april-2011-server-setup-with-rails-ubuntu-nginx-rvm-capistrano-git/
6. http://www.zorched.net/2008/06/17/capistrano-deploy-with-git-and-passenger/

分享到:
评论

相关推荐

    Notepad++ 6.5.5

    Enable word-completion in ANSI document under CJK environment. Add wildcard capacity for file name argument in command line. Add new command line argument "-r" for opening files recursively (with ...

    SNAP_Mobile_Game_Compliance_Testing_Guide_v1_2_en

    - **Pre-Development Testing**: This phase involves setting up the testing environment and ensuring that all necessary tools and resources are available. - **Development Testing**: During this phase, ...

    Realtek_WPS_user_guide.pdf

    8xxx-SOC, the instructions of setting up a Wi-Fi network for different scenarios, and the recommended system configuration. 1.2 Scope This document is aimed to the engineers who have basic knowledge ...

    Android_Learning_Notes_Part 1.pdf

    Understanding the architecture of Android and setting up the development environment with the Android SDK and Eclipse IDE are crucial steps for any developer looking to create applications for Android...

    ios application programming guide

    2. **Development Environment Setup**: Setting up Xcode, the official IDE for iOS development, along with other necessary tools and configurations. 3. **Swift Programming Language**: An overview of ...

    AN12900 Secure Over-the-Air Prototype for Linux Using CAAM and Mender

    - **Installing and Configuring Mender Server**: Detailed steps on setting up the Mender server, including configuring the Docker Compose environment and integrating the necessary microservices. ...

    Professional.MFC.with.VC6

    Setting Drawing Parameters Control-based Views The Rich Text Edit Control Character Formatting Paragraph Formatting Serializing a Rich Edit Control Uncommon Controls Checked List Boxes ...

    BSD.Hack.B00V3DWD80

    Rather than spending hours with a dry technical document learning what switches go with a command, you'll learn concrete, practical uses for that command.The book begins with hacks to customize the ...

    Microsoft Codeview and Utilities User's Guide

    Information in this document is subject to change without notice and does not represent a commitment on the part of Microsoft Corporation. The software described in this document is furnished under a ...

    Packt.QlikView Server and Publisher

    2. **Document Repository**: The document repository stores all QlikView documents, including applications and reports. This centralized storage ensures easy access and management of BI content. 3. **...

    i.MX Linux® Reference Manual

    Based on the given information from the "i.MX Linux® Reference Manual," we can extract several key topics and concepts that are essential for understanding the Linux environment tailored for ...

    网络管理-信息化-P企业研发项目管理信息化研究.pdf

    Quantitative project management involves setting clear metrics and KPIs (Key Performance Indicators) to monitor progress, enabling better control over project timelines and budgets. This approach ...

    iPhone.for.Work

    The book identifies and explains some of the best applications that cater to professional needs, including tools for project management, communication, and document handling. - **Third-Party Software...

Global site tag (gtag.js) - Google Analytics