一.系统环境

jim@mode:~$ cat /etc/issue

Ubuntu 12.04.4 LTS \n \l

jim@mode:~$ uname -ra

Linux mode 3.11.0-15-generic#25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

二.拓扑图

wKiom1PtvtDirpHhAAGztfKmhUw853.jpg

三.创建用户

jim@mode:~$ sudo adduser deploy

[sudo] password for jim: 

perl: warning: Setting locale failed.

perl: warning: Please check that your locale settings:

        LANGUAGE = "zh_CN:zh",

        LC_ALL = (unset),

        LC_PAPER = "zh_CN",

        LC_ADDRESS = "zh_CN",

        LC_MONETARY = "zh_CN",

        LC_NUMERIC = "zh_CN",

        LC_TELEPHONE = "zh_CN",

        LC_IDENTIFICATION = "zh_CN",

        LC_MEASUREMENT = "zh_CN",

        LC_TIME = "zh_CN",

        LC_NAME = "zh_CN",

        LANG = "zh_CN.UTF-8"

    are supported and installed on your system.

perl: warning: Falling back to the standard locale ("C").

Adding user `deploy' ...

Adding new group `deploy' (1002) ...

Adding new user `deploy' (1002) with group `deploy' ...

Creating home directory `/home/deploy' ...

Copying files from `/etc/skel' ...

Enter new UNIX password: 

Retype new UNIX password: 

passwd: password updated successfully

Changing the user information for deploy

Enter the new value, or press ENTER for the default

        Full Name []: 

        Room Number []: 

        Work Phone []: 

        Home Phone []: 

        Other []: 

Is the information correct? [Y/n] Y

deploy@mode:~$ echo $LANG

zh_CN.UTF-8

解决上面的问题:

export LANG=en

export LANGUAG

export LC_ALL=

echo $LANG    

deploy@mode:~$ echo $LANG                 

en_US.UTF-8

给用户deploy sudo 组的权限

jim@mode:~$ sudo usermod -a -G sudo deploy

查看deploy用户

jim@mode:~$ id deploy 

uid=1002(deploy) gid=1002(deploy) groups=1002(deploy),27(sudo)



二.安装

安装相关包,包括git包等。

sudo apt-get install wget vim build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf automake libtool p_w_picpathmagick libpcre3-dev  bison  libc6-dev ncurses-dev


安装RVM

         接下来,我们在用户zlz下面安装rvm。随便普及一下相关的基础知识。

什么是RVM

rvm是一个命令行工具,可以提供一个便捷的多版本ruby环境的管理和切换。

在服务器上用一个普通用户安装rvm,然后用rvm来安装ruby gemset。用rvm是必须得,因为服务器上不可能只部署一个项目,且项目使用的版本都不一样。

         因此我们在一普通用户下安装让rvm,即是:在用户下安装。

切换到用户deploy下。


jim@mode:~$ su - deploy 

Password: 

安装

deploy@mode:~$ \curl -sSL https://get.rvm.io | bash -s stable

Downloading https://github.com/wayneeseguin/rvm/archive/stable.tar.gz


Installing RVM to /home/deploy/.rvm/

    Adding rvm PATH line to /home/deploy/.profile /home/deploy/.bashrc /home/deploy/.zshrc.

    Adding rvm loading line to /home/deploy/.bash_profile /home/deploy/.zlogin.

Installation of RVM in /home/deploy/.rvm/ is almost complete:


  * To start using RVM you need to run `source /home/deploy/.rvm/scripts/rvm`

    in all your open shell windows, in rare cases you need to reopen all shell windows.


# deploy,

#

#   Thank you for using RVM!

#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!

#

# ~Wayne, Michal & team.


In case of problems: http://rvm.io/help and https://twitter.com/rvm_io

deploy@mode:~$ source /home/deploy/.rvm/scripts/rvm

deploy@mode:~$ rvm -v

rvm 1.25.28 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]


查看环境变量

deploy@mode:~$ echo $PATH

/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/deploy/.rvm/bin


安装一个ruby版本

deploy@mode:~$ rvm install 1.9.3

Searching for binary rubies, this might take some time.

Found remote file https://rvm.io/binaries/ubuntu/12.04/x86_64/ruby-1.9.3-p547.tar.bz2

Checking requirements for ubuntu.

Installing requirements for ubuntu.

Updating systemdeploy password required for 'apt-get --quiet --yes update': 

deploy password required for 'apt-get --quiet --yes update': 

............

Installing required packages: gawk, libsqlite3-dev, sqlite3, libgdbm-dev, pkg-config, libffi-dev..........

Requirements installation successful.

ruby-1.9.3-p547 - #configure

ruby-1.9.3-p547 - #download

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100 11.3M  100 11.3M    0     0   208k      0  0:00:55  0:00:55 --:--:--  159k

ruby-1.9.3-p547 - #validate archive

ruby-1.9.3-p547 - #extract

ruby-1.9.3-p547 - #validate binary

ruby-1.9.3-p547 - #setup

ruby-1.9.3-p547 - #gemset created /home/deploy/.rvm/gems/ruby-1.9.3-p547@global

ruby-1.9.3-p547 - #importing gemset /home/deploy/.rvm/gemsets/global.gems....................................

ruby-1.9.3-p547 - #generating global wrappers........

ruby-1.9.3-p547 - #gemset created /home/deploy/.rvm/gems/ruby-1.9.3-p547

ruby-1.9.3-p547 - #importing gemsetfile /home/deploy/.rvm/gemsets/default.gems evaluated to empty gem list

ruby-1.9.3-p547 - #generating default wrappers........


查看rvm版本

deploy@mode:~$ rvm -v

rvm 1.25.28 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

查看环境变量

deploy@mode:~$ echo $PATH

/home/deploy/.rvm/gems/ruby-1.9.3-p547/bin:/home/deploy/.rvm/gems/ruby-1.9.3-p547@global/bin:/home/deploy/.rvm/rubies/ruby-1.9.3-p547/bin:/home/deploy/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games


设置默认的Ruby 版本

deploy@mode:~$ rvm 1.9.3 --default

查看ruby版本

deploy@mode:~$ ruby -v

ruby 1.9.3p547 (2014-05-14 revision 45962) [x86_64-linux]


使用 rvm list known 命令列出所有已知的版本

deploy@mode:~$ rvm list known

# MRI Rubies

[ruby-]1.8.6[-p420]

[ruby-]1.8.7[-head] # security released on head

[ruby-]1.9.1[-p431]

[ruby-]1.9.2[-head] # security released on head

[ruby-]1.9.3[-p547]

[ruby-]2.0.0-p451

[ruby-]2.0.0[-p481]

[ruby-]2.1.1

[ruby-]2.1[.2]

[ruby-]2.1-head

ruby-head


# GoRuby

goruby


# Topaz

topaz


# TheCodeShop - MRI experimental patches

tcs


# jamesgolick - All around gangster

jamesgolick


# Minimalistic ruby implementation - ISO 30170:2012

mruby[-head]


# JRuby

jruby-1.6.8

jruby[-1.7.13]

jruby-head


# Rubinius

rbx-1.3.3

rbx-2.0.0

rbx-2.1.1

rbx[-2.2.10]

rbx-head


# Ruby Enterprise Edition

ree-1.8.6

ree[-1.8.7][-2012.02]


# Kiji

kiji


# MagLev

maglev[-head]

maglev-1.0.0


# Mac OS X Snow Leopard Or Newer

macruby-0.10

macruby-0.11

macruby[-0.12]

macruby-nightly

macruby-head


# Opal

opal


# IronRuby

ironruby[-1.1.3]

ironruby-head


    因为需要我们去git服务器上去拉取代码,所有需要我们为用户deploy生成一个公钥,然后把公钥放到git代码服务器上。

我们可以通俗的理解为:

这个过程就如:

         自己买了一把锁和钥匙,之后,把自己的锁给别人,然后自己再拿着钥匙去开送给别人的锁。


为用户deploy生产密钥对

deploy@mode:~$ ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key (/home/deploy/.ssh/id_dsa): 

Created directory '/home/deploy/.ssh'.

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /home/deploy/.ssh/id_dsa.

Your public key has been saved in /home/deploy/.ssh/id_dsa.pub.

The key fingerprint is:

f4:44:37:44:6e:a8:0a:9d:f1:a3:ab:69:3b:4f:14:21 deploy@mode

The key's randomart p_w_picpath is:

+--[ DSA 1024]----+

|    E .   .o=    |

|     . . . + .   |

|      o . o o    |

|     . * + .     |

|    . + S .      |

|     o o .       |

|      +          |

|    oo .         |

|   .+=o          |

+-----------------+

查看生成的密码对:

deploy@mode:~$ ll .ssh/

total 16

drwx------ 2 deploy deploy 4096 Aug 14 16:33 ./

drwxr-xr-x 4 deploy deploy 4096 Aug 14 16:33 ../

-rw------- 1 deploy deploy  672 Aug 14 16:33 id_dsa       ----->私钥

-rw-r--r-- 1 deploy deploy  601 Aug 14 16:33 id_dsa.pub   ----->公钥

然后再把id_dsa.pub   ----->公钥通过git上传到服务器上。

deploy@mode:~$ cat .ssh/id_dsa.pub 

ssh-dss AAAAB3NzaC1kc3MAAACBAP+mmHlbxXZ7V+ZWz0OMQDJWqdkEZuo0sI6boiJrkY/bqXE9X3/fQfi5xrJ48108KpeO5xeART1QXOx1Fvt6cuV/Z2OKpjqt1h84F9Y/k1V/COjVpatknV/x3LRn4GUrqL/kIecICPxch/pryH8HnWHJAzcLFdiQrE8a7K1zf2M9AAAAFQD3lrvPReIpa+ajJz1RDxvVoVyGJwAAAIEAy0HVhDKxvTQSpPa1ooW0Gskq3pbzcbtZCzbNvK273Y23QwxVsSyqg1l4Sb4rbOeih09IHziMAztCvKu94u+wLriUk/9hef9LRHdPZvzl1iFifCc+2GreJzhMUODUhHSXMynvDh4CCHslPJqsQcapjkjTGlqzX9zhNI0iOKmXrFMAAACAFMNPYab6Y1Bk+ocmZ6s2Fu/OAKsOfYfjB3/MdqZ1gDY1hH/DyeIdVqJCx5Tpy+Fr1r9OnNxxW3INY3TikbqziyYwaU6smYx77VKWespobZNAptdeIRa630bLZZMSZiZLfUFRtQD7qmB+0DvYb+OzeC7/ZkmPBiJY0lDeB/aG77g= deploy@mode


把用户deploy加入到gitolite.conf里面。

@rails_team = @vincent_all zhanghuaxuan yangshukun zhanghuaxuanvm yangshukun2 wurain chenyuanheng yuanxiaofei xiaomacrm jim newuser yangshukun3 apps deploy


repo xmnewcrm

RW+= @rails_team @deploy

R= @developer

这样,就能拉取git服务器上的 xmnewcrm代码了

deploy.pub放到

wKioL1PsnNqyAn7pAAD7DKtN7T0712.jpg


在本地我在把git的配置推送到服务器上。

wKioL1PtnuXAVx-LAACxI0ibKnI909.jpg

推送

wKioL1Ptnx3CwienAAJWDuDUhEA545.jpg

然后再把公钥复制到git服务器211.157.136.58上

vincent@xiaoma-web-01:~$ sudo vim .ssh/authorized_keys2

ssh-dss AAAAB3NzaC1kc3MAAACBAP+mmHlbxXZ7V+ZWz0OMQDJWqdkEZuo0sI6boiJrkY/bqXE9X3/fQfi5xrJ48108KpeO5xeART1QXOx1Fvt6cuV/Z2OKpjqt1h84F9Y/k1V/COjVpatknV/x3LRn4GUrqL/kIecICPxch/pryH8HnWHJAzcLFdiQrE8a7K1zf2M9AAAAFQD3lrvPReIpa+ajJz1RDxvVoVyGJwAAAIEAy0HVhDKxvTQSpPa1ooW0Gskq3pbzcbtZCzbNvK273Y23QwxVsSyqg1l4Sb4rbOeih09IHziMAztCvKu94u+wLriUk/9hef9LRHdPZvzl1iFifCc+2GreJzhMUODUhHSXMynvDh4CCHslPJqsQcapjkjTGlqzX9zhNI0iOKmXrFMAAACAFMNPYab6Y1Bk+ocmZ6s2Fu/OAKsOfYfjB3/MdqZ1gDY1hH/DyeIdVqJCx5Tpy+Fr1r9OnNxxW3INY3TikbqziyYwaU6smYx77VKWespobZNAptdeIRa630bLZZMSZiZLfUFRtQD7qmB+0DvYb+OzeC7/ZkmPBiJY0lDeB/aG77g= deploy@mode


在部署服务器192.168.1.97上的deploy用户下从git服务器211.157.136.58上拉取代码

deploy@mode:~$ git clone git@git.xiaoma.com:xmnewcrm

Cloning into 'xmnewcrm'...

The authenticity of host 'git.xiaoma.com (211.157.136.59)' can't be established.

ECDSA key fingerprint is e6:62:af:0e:01:02:e2:52:9a:db:6a:4b:46:93:50:35.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'git.xiaoma.com,211.157.136.59' (ECDSA) to the list of known hosts.

remote: Counting objects: 4095, done.

remote: Compressing objects: 100% (3308/3308), done.

remote: Total 4095 (delta 2465), reused 1633 (delta 671)

Receiving objects: 100% (4095/4095), 16.24 MiB | 331 KiB/s, done.

Resolving deltas: 100% (2465/2465), done.



gemset的使用

                     rvm不仅可以提供一个多ruby版本共存的环境,还可以根据项目管理不同的gemset。

gemset可以理解为是一个独立的虚拟gem环境,每一个gemset都是相互独立的。

比如你有两个项目,一个是rails 2.3 一个是 rails 3,gemset可以帮你便捷的建立两套gem开发环境,并且方便的切换。

gemset是附加在ruby语言版本下面的,例如你用了1.9.2, 建立了一个叫rails3的gemset,当切换到1.8.7的时候,rails3这个gemset并不存在。


 程序的运行环境  就我需要用到的插件都在 xmnewcrm 

创建一个名为xmnewcrm 的新 gemset

deploy@mode:~/xmnewcrm$ rvm gemset create xmnewcrm

ruby-1.9.3-p547 - #gemset created /home/deploy/.rvm/gems/ruby-1.9.3-p547@xmnewcrm

ruby-1.9.3-p547 - #generating xmnewcrm wrappers........


切换运行环境

deploy@mode:~/xmnewcrm$ rvm ruby-1.9.3@xmnewcrm

deploy@mode:~/xmnewcrm$ rvm gemset list


gemsets for ruby-1.9.3-p547 (found in /home/deploy/.rvm/gems/ruby-1.9.3-p547)

   (default)

   global

=> xmnewcrm


查看一下

deploy@mode:~/xmnewcrm$ ls

app      config     db   Gemfile       lib  public    README.rdoc  test                     用户信息.xls

Capfile  config.ru  doc  Gemfile.lock  log  Rakefile  script       员工信息_2014-07-29.xls


Gemfile定义你的应用依赖哪些第三方包,bundle根据该配置去寻找这些包。


deploy@mode:~/xmnewcrm$ vim Gemfile

# source 'https://rubygems.org'

source 'http://ruby.taobao.org/'


ruby '1.9.3'

gem 'rails', '3.2.15'


#gem 'activerecord-mysql-adapter'


gem 'activerecord-mysql2-adapter'

# Bundle edge Rails instead:

# gem 'rails', :git => 'git://github.com/rails/rails.git'


#gem 'mysql2'

#gem 'sqlite3'


gem 'spreadsheet','~> 0.6.5.4'


group :developments do

  gem 'sqlite3'

end

# Gems used only for assets and not required

# in production environments by default.

group :assets do

  gem 'sass-rails',   '~> 3.2.3'

  gem 'coffee-rails', '~> 3.2.1'


  # See https://github.com/sstephenson/execjs#readme for more supported runtimes

  gem 'therubyracer', :platforms => :ruby


  gem 'uglifier', '>= 1.0.3'

end


gem 'jquery-rails'

#gem 'tinymce-rails'


# To use ActiveModel has_secure_password

# gem 'bcrypt-ruby', '~> 3.0.0'


# To use Jbuilder templates for JSON

#       gem 'jbuilder'


# Use unicorn as the app server

gem 'unicorn'


# Deploy with Capistrano

gem 'capistrano', '3.0.1'

gem 'capistrano-bundler', '1.0.0'

gem 'capistrano-rails', '1.1.0'

gem 'capistrano-rvm', '0.0.3'

# To use debugger

# gem 'debugger'


# production server

#gem 'puma', '~> 2.6.0'


#gem "mysql2", "~> 0.3.14"


gem 'devise', '~> 3.2.2'


gem 'devise-encryptable'


gem 'cancan', '~> 1.6.10'


gem 'will_paginate', '~> 3.0.5'

# ios push message

# gem 'grocer'  

#gem 'capistrano3-puma'#, :git => 'git://github.com/rainytooo/capistrano-puma.git', :branch => 'fix-bundle'

#gem 'capistrano', '~> 3.1.0'

#gem 'capistrano-rails', '~> 1.1.0'

#gem 'capistrano-rvm', '~> 0.0.3'

#gem 'rvm1-capistrano3', :require => false, :github => 'florian-winddle/rvm1-capistrano3'


gem 'passenger', '4.0.37'


gem 'haml-rails'


group :test ,:development do

  gem 'pry'

  gem 'thin'

end


安装mysql数据库,注意如果部署账号和被部署账号不在一个服务器上,就不用再部署账号上安装数据库。

deploy@mode:~/xmnewcrm$ apt-get install mysql-server mysql-client

E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)

E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

deploy@mode:~/xmnewcrm$ sudo apt-get install mysql-server mysql-client  

[sudo] password for deploy: 

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following packages will be upgraded:

  mysql-client mysql-server

2 upgraded, 0 newly installed, 0 to remove and 71 not upgraded.

Need to get 22.6 kB of archives.

After this operation, 2,048 B of additional disk space will be used.

Get:1 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/main mysql-client all 5.5.38-0ubuntu0.12.04.1 [11.2 kB]

Get:2 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/main mysql-server all 5.5.38-0ubuntu0.12.04.1 [11.4 kB]

Fetched 22.6 kB in 1s (14.0 kB/s)       

(Reading database ... 61893 files and directories currently installed.)

Preparing to replace mysql-client 5.5.35-0ubuntu0.12.04.2 (using .../mysql-client_5.5.38-0ubuntu0.12.04.1_all.deb) ...

Unpacking replacement mysql-client ...

Preparing to replace mysql-server 5.5.35-0ubuntu0.12.04.2 (using .../mysql-server_5.5.38-0ubuntu0.12.04.1_all.deb) ...

Unpacking replacement mysql-server ...

Setting up mysql-client (5.5.38-0ubuntu0.12.04.1) ...

Setting up mysql-server (5.5.38-0ubuntu0.12.04.1) ...

deploy@mode:~/xmnewcrm$ mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 36

Server version: 5.5.35-0ubuntu0.12.04.2 (Ubuntu)


Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> quit

Bye


下面这步一定要做

deploy@mode:~/xmnewcrm$ bundle install                                

Fetching source index from http://ruby.taobao.org/

Resolving dependencies..........................

Using rake 10.1.1

Using i18n 0.6.9

Using multi_json 1.9.0

Using activesupport 3.2.15

Using builder 3.0.4

Using activemodel 3.2.15

Using erubis 2.7.0

Using journey 1.0.4

Using rack 1.4.5

Using rack-cache 1.2

Using rack-test 0.6.2

Using hike 1.2.3

Using tilt 1.4.1

Using sprockets 2.2.2

Using actionpack 3.2.15

Using mime-types 1.25.1

Using polyglot 0.3.4

Using treetop 1.4.15

Using mail 2.5.4

Using actionmailer 3.2.15

Using arel 3.0.3

Using tzinfo 0.3.38

Using activerecord 3.2.15


Gem::Ext::BuildError: ERROR: Failed to build gem native extension.


    /home/deploy/.rvm/rubies/ruby-1.9.3-p547/bin/ruby extconf.rb 

checking for ruby/thread.h... no

checking for rb_thread_blocking_region()... yes

checking for rb_wait_for_single_fd()... yes

checking for rb_hash_dup()... yes

checking for rb_intern3()... yes

checking for mysql_query() in -lmysqlclient... no

checking for main() in -lm... yes

checking for mysql_query() in -lmysqlclient... no

checking for main() in -lz... yes

checking for mysql_query() in -lmysqlclient... no

checking for main() in -lsocket... no

checking for mysql_query() in -lmysqlclient... no

checking for main() in -lnsl... yes

checking for mysql_query() in -lmysqlclient... no

checking for main() in -lmygcc... no

checking for mysql_query() in -lmysqlclient... no

*** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of

necessary libraries and/or headers.  Check the mkmf.log file for more

details.  You may need configuration options.


Provided configuration options:

        --with-opt-dir

        --without-opt-dir

        --with-opt-include

        --without-opt-include=${opt-dir}/include

        --with-opt-lib

        --without-opt-lib=${opt-dir}/lib

        --with-make-prog

        --without-make-prog

        --srcdir=.

        --curdir

        --ruby=/home/deploy/.rvm/rubies/ruby-1.9.3-p547/bin/ruby

        --with-mysql-dir

        --without-mysql-dir

        --with-mysql-include

        --without-mysql-include=${mysql-dir}/include

        --with-mysql-lib

        --without-mysql-lib=${mysql-dir}/lib

        --with-mysql-config

        --without-mysql-config

        --with-mysql-dir

        --without-mysql-dir

        --with-mysql-include

        --without-mysql-include=${mysql-dir}/include

        --with-mysql-lib

        --without-mysql-lib=${mysql-dir}/lib

        --with-mysqlclientlib

        --without-mysqlclientlib

        --with-mlib

        --without-mlib

        --with-mysqlclientlib

        --without-mysqlclientlib

        --with-zlib

        --without-zlib

        --with-mysqlclientlib

        --without-mysqlclientlib

        --with-socketlib

        --without-socketlib

        --with-mysqlclientlib

        --without-mysqlclientlib

        --with-nsllib

        --without-nsllib

        --with-mysqlclientlib

        --without-mysqlclientlib

        --with-mygcclib

        --without-mygcclib

        --with-mysqlclientlib

        --without-mysqlclientlib


extconf failed, exit code 1


Gem files will remain installed in /home/deploy/.rvm/gems/ruby-1.9.3-p547@xmnewcrm/gems/mysql2-0.3.16 for inspection.

Results logged to /home/deploy/.rvm/gems/ruby-1.9.3-p547@xmnewcrm/extensions/x86_64-linux/1.9.1/mysql2-0.3.16/gem_make.out

An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue.

Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling.

那么我们该如何解决它呢?其实是ruby与mysql直接的关联问题,解决办法:如下

deploy@mode:~/xmnewcrm$ sudo apt-get install libmysql-ruby libmysqlclient-dev

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following extra packages will be installed:

  libmysqlclient18 libreadline5 libruby1.8 mysql-common ruby ruby-mysql ruby1.8

Suggested packages:

  ri ruby-dev ruby1.8-examples ri1.8

The following NEW packages will be installed:

  libmysql-ruby libmysqlclient-dev libreadline5 libruby1.8 ruby ruby-mysql ruby1.8

The following packages will be upgraded:

  libmysqlclient18 mysql-common

2 upgraded, 7 newly installed, 0 to remove and 69 not upgraded.

Need to get 4,416 kB of archives.

After this operation, 13.1 MB of additional disk space will be used.

Do you want to continue [Y/n]? Y

Get:1 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/main mysql-common all 5.5.38-0ubuntu0.12.04.1 [13.2 kB]

Get:2 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/main libmysqlclient18 amd64 5.5.38-0ubuntu0.12.04.1 [949 kB]

Get:3 http://cn.archive.ubuntu.com/ubuntu/ precise/main libreadline5 amd64 5.2-11 [128 kB]                                         

Get:4 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/main libruby1.8 amd64 1.8.7.352-2ubuntu1.4 [1,797 kB]                   

Get:5 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/main ruby1.8 amd64 1.8.7.352-2ubuntu1.4 [33.8 kB]                       

Get:6 http://cn.archive.ubuntu.com/ubuntu/ precise/main ruby all 4.8 [5,054 B]                                                     

Get:7 http://cn.archive.ubuntu.com/ubuntu/ precise/universe ruby-mysql amd64 2.8.2+gem2deb-1build1 [86.1 kB]                       

Get:8 http://cn.archive.ubuntu.com/ubuntu/ precise/universe libmysql-ruby all 2.8.2+gem2deb-1build1 [2,480 B]                      

Get:9 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/main libmysqlclient-dev amd64 5.5.38-0ubuntu0.12.04.1 [1,402 kB]        

Fetched 4,416 kB in 1min 15s (58.5 kB/s)                                                                                           

(Reading database ... 61893 files and directories currently installed.)

Preparing to replace mysql-common 5.5.35-0ubuntu0.12.04.2 (using .../mysql-common_5.5.38-0ubuntu0.12.04.1_all.deb) ...

Unpacking replacement mysql-common ...

Preparing to replace libmysqlclient18 5.5.35-0ubuntu0.12.04.2 (using .../libmysqlclient18_5.5.38-0ubuntu0.12.04.1_amd64.deb) ...

Unpacking replacement libmysqlclient18 ...

Selecting previously unselected package libreadline5.

Unpacking libreadline5 (from .../libreadline5_5.2-11_amd64.deb) ...

Selecting previously unselected package libruby1.8.

Unpacking libruby1.8 (from .../libruby1.8_1.8.7.352-2ubuntu1.4_amd64.deb) ...

Selecting previously unselected package ruby1.8.

Unpacking ruby1.8 (from .../ruby1.8_1.8.7.352-2ubuntu1.4_amd64.deb) ...

Selecting previously unselected package ruby.

Unpacking ruby (from .../apt/archives/ruby_4.8_all.deb) ...

Selecting previously unselected package ruby-mysql.

Unpacking ruby-mysql (from .../ruby-mysql_2.8.2+gem2deb-1build1_amd64.deb) ...

Selecting previously unselected package libmysql-ruby.

Unpacking libmysql-ruby (from .../libmysql-ruby_2.8.2+gem2deb-1build1_all.deb) ...

Selecting previously unselected package libmysqlclient-dev.

Unpacking libmysqlclient-dev (from .../libmysqlclient-dev_5.5.38-0ubuntu0.12.04.1_amd64.deb) ...

Processing triggers for man-db ...

Setting up mysql-common (5.5.38-0ubuntu0.12.04.1) ...

Setting up libmysqlclient18 (5.5.38-0ubuntu0.12.04.1) ...

Setting up libreadline5 (5.2-11) ...

Setting up libruby1.8 (1.8.7.352-2ubuntu1.4) ...

Setting up ruby1.8 (1.8.7.352-2ubuntu1.4) ...

update-alternatives: using /usr/bin/ruby1.8 to provide /usr/bin/ruby (ruby) in auto mode.

Setting up ruby (4.8) ...

Setting up ruby-mysql (2.8.2+gem2deb-1build1) ...

Setting up libmysql-ruby (2.8.2+gem2deb-1build1) ...

Setting up libmysqlclient-dev (5.5.38-0ubuntu0.12.04.1) ...

Processing triggers for libc-bin ...

ldconfig deferred processing now taking place


然后再bundle install

deploy@mode:~/xmnewcrm$ bundle install

Fetching source index from http://ruby.taobao.org/

Resolving dependencies..........................

Using rake 10.1.1

Using i18n 0.6.9

Using multi_json 1.9.0

Using activesupport 3.2.15

Using builder 3.0.4

Using activemodel 3.2.15

Using erubis 2.7.0

Using journey 1.0.4

Using rack 1.4.5

Using rack-cache 1.2

Using rack-test 0.6.2

Using hike 1.2.3

Using tilt 1.4.1

Using sprockets 2.2.2

Using actionpack 3.2.15

Using mime-types 1.25.1

Using polyglot 0.3.4

Using treetop 1.4.15

Using mail 2.5.4

Using actionmailer 3.2.15

Using arel 3.0.3

Using tzinfo 0.3.38

Using activerecord 3.2.15

Installing mysql2 0.3.16 (was 0.3.15)

Installing activerecord-mysql2-adapter 0.0.3

Installing activeresource 3.2.15

Installing atomic 1.1.15

Installing bcrypt 3.1.7

Installing bcrypt-ruby 3.1.5

Using bundler 1.6.2

Installing cancan 1.6.10

Installing net-ssh 2.8.0

Installing net-scp 1.1.2

Installing tins 1.0.0

Installing term-ansicolor 1.3.0

Installing sshkit 1.3.0

Installing capistrano 3.0.1

Installing capistrano-bundler 1.0.0

Installing capistrano-rails 1.1.0

Installing capistrano-rvm 0.0.3

Installing coderay 1.1.0

Installing coffee-script-source 1.7.0

Installing execjs 2.0.2

Installing coffee-script 2.2.0

Installing rack-ssl 1.3.3

Installing json 1.8.1

Installing rdoc 3.12.2

Installing thor 0.18.1

Installing railties 3.2.15

Installing coffee-rails 3.2.2

Installing daemon_controller 1.2.0

Installing daemons 1.1.9

Installing orm_adapter 0.5.0

Installing thread_safe 0.2.0

Installing warden 1.2.3

Installing devise 3.2.3

Installing devise-encryptable 0.1.2

Installing eventmachine 1.0.3

Installing haml 4.0.5

Installing haml-rails 0.4

Installing jquery-rails 3.1.0

Installing kgio 2.9.2

Installing libv8 3.16.14.3

Installing method_source 0.8.2

Installing passenger 4.0.37

Installing slop 3.5.0

Installing pry 0.10.0

Installing rails 3.2.15

Installing raindrops 0.13.0

Installing ref 1.0.5

Installing ruby-ole 1.2.11.7

Installing sass 3.2.14

Installing sass-rails 3.2.6

Installing spreadsheet 0.6.5.9

Installing sqlite3 1.3.9

Installing therubyracer 0.12.1

Installing thin 1.6.2

Installing uglifier 2.4.0

Installing unicorn 4.8.2

Installing will_paginate 3.0.5

Your bundle is complete!

Gems in the group production were not installed.

Use `bundle show [gemname]` to see where a bundled gem is installed.

Post-install message from bcrypt-ruby:


#######################################################


The bcrypt-ruby gem has changed its name to just bcrypt.  Instead of

installing `bcrypt-ruby`, you should install `bcrypt`.  Please update your

dependencies accordingly.


#######################################################


Post-install message from capistrano:

If you're updating Capistrano from 2.x.x, we recommend you to read the upgrade guide: http://www.capistranorb.com/documentation/upgrading/

Post-install message from rdoc:

Depending on your version of ruby, you may need to install ruby rdoc/ri data:


<= 1.8.6 : unsupported

 = 1.8.7 : gem install rdoc-data; rdoc-data --install

 = 1.9.1 : gem install rdoc-data; rdoc-data --install

>= 1.9.2 : nothing to do! Yay!

Post-install message from haml:


HEADS UP! Haml 4.0 has many improvements, but also has changes that may break

your application:


* Support for Ruby 1.8.6 dropped

* Support for Rails 2 dropped

* Sass filter now always outputs <style> tags

* Data attributes are now hyphenated, not underscored

* html2haml utility moved to the html2haml gem

* Textile and Maruku filters moved to the haml-contrib gem


For more info see:


http://rubydoc.info/github/haml/haml/file/CHANGELOG.md

好了,成功了。





被部署的服务器上的操作

创建用户apps

jim@mode:~$ sudo adduser apps

perl: warning: Setting locale failed.

perl: warning: Please check that your locale settings:

        LANGUAGE = "zh_CN:zh",

        LC_ALL = (unset),

        LC_PAPER = "zh_CN",

        LC_ADDRESS = "zh_CN",

        LC_MONETARY = "zh_CN",

        LC_NUMERIC = "zh_CN",

        LC_TELEPHONE = "zh_CN",

        LC_IDENTIFICATION = "zh_CN",

        LC_MEASUREMENT = "zh_CN",

        LC_TIME = "zh_CN",

        LC_NAME = "zh_CN",

        LANG = "zh_CN.UTF-8"

    are supported and installed on your system.

perl: warning: Falling back to the standard locale ("C").

Adding user `apps' ...

Adding new group `apps' (1001) ...

Adding new user `apps' (1001) with group `apps' ...

Creating home directory `/home/apps' ...

Copying files from `/etc/skel' ...

Enter new UNIX password: 

Retype new UNIX password: 

passwd: password updated successfully

Changing the user information for apps

Enter the new value, or press ENTER for the default

        Full Name []: 

        Room Number []: 

        Work Phone []: 

        Home Phone []: 

        Other []: 

Is the information correct? [Y/n] Y



切换到用户apps下

jim@mode:~$ su - apps

Password: 

为用户apps生成密钥对

apps@mode:~$ ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key (/home/apps/.ssh/id_dsa): 

Created directory '/home/apps/.ssh'.

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /home/apps/.ssh/id_dsa.

Your public key has been saved in /home/apps/.ssh/id_dsa.pub.

The key fingerprint is:

1f:b0:4d:6b:1a:01:f7:ab:ca:36:44:e7:2d:ad:58:a6 apps@mode

The key's randomart p_w_picpath is:

+--[ DSA 1024]----+

|      . .        |

|       o .       |

|        o o      |

|      . .* o     |

|     . oSo*      |

|      . =*o.     |

|     . =oo.      |

|     .E..        |

|     .o.         |

+-----------------+

查看密钥对:

apps@mode:~$ ll .ssh/

total 16

drwx------ 2 apps apps 4096 Aug 15 00:20 ./

drwxr-xr-x 3 apps apps 4096 Aug 15 00:20 ../

-rw------- 1 apps apps  672 Aug 15 00:20 id_dsa

-rw-r--r-- 1 apps apps  599 Aug 15 00:20 id_dsa.pub

apps@mode:~$ cat .ssh/id_dsa.pub 

ssh-dss AAAAB3NzaC1kc3MAAACBAOfZf6SxtKcjkJX9T4gW30W01ZRF+VUFxgNlJXyvjf4WPdPi5eU3MtDV64c+cX6aZimAQ1nl/soi5QVe23JRYVOVl9ejCWiIk8zCMLIarT8DzPWKPnZ8ZwBRfbjnEWvEXr03lmHRL/H8mV2xVDH/jinKbvTi3sAYQUW6vJQ917pHAAAAFQDNIEWrUmHWW9otVZNQrM6Y0NlBIwAAAIB8Jx4FPRan64vrCMuVNZuu2DXJr0afnw5m22fwG0jVcQ0fvFzrbnDUhAr17IsIl0SHm6KBXBUcR2jOKtwU4Lvnb9kEf50u6YEUtmikMM99wEJ5PxkDj0f3btZGccfd3Oh2C/hb9U3CcCSVPehEGRhfb0KfFJAVryARwShodbSsaQAAAIEAz+HzqfEpwn815XTTeGoWwyxoAbZeK2pcqDZZpnAEnvahWGD+slJCZwuV0R55RQaASwd55yj65p8hoKcd/bRZsfQqLRtF2P2YTFigRVFJCkUkwqOpcUvKXcLTVllAC7ZbOkmjeIBBlKKTL/qn4syU/JymQwUnTYdZLroDc02uls8= apps@mode


      然后再把被部署的服务器的公钥放到git服务器上去,因为被部署服务器需要从git服务器上拉取代码。

同时还有把部署服务器的公钥分发到被部署的服务器,这样才能在被部署端通过ssh执行部署端的命令。


用户apps下查看,用户deploy没推送之前

apps@mode:~$ ll .ssh/

total 16

drwx------ 2 apps apps 4096 Aug 15 00:20 ./

drwxr-xr-x 3 apps apps 4096 Aug 15 00:20 ../

-rw------- 1 apps apps  672 Aug 15 00:20 id_dsa

-rw-r--r-- 1 apps apps  599 Aug 15 00:20 id_dsa.pub


用户apps下查看,用户deploy推送公钥之后

deploy@mode:~/.ssh$  ssh-copy-id -i id_dsa.pub apps@192.168.1.97 --->注意这个命令仅仅适用于发公钥。其实你也可以在apps用户下新建个authorized_keys文件,然后再把deploy的公钥编辑进去,然后一定要注意authorized_keys文件的权限-rw-------     600。

The authenticity of host '192.168.1.97 (192.168.1.97)' can't be established.

ECDSA key fingerprint is 17:d8:c3:a9:53:24:66:97:10:70:98:6c:f5:23:f0:d6.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.1.97' (ECDSA) to the list of known hosts.

apps@192.168.1.97's password: 

Now try logging into the machine, with "ssh 'apps@192.168.1.97'", and check in:


  ~/.ssh/authorized_keys


to make sure we haven't added extra keys that you weren't expecting.

apps@mode:~$ ll .ssh/

total 20

drwx------ 2 apps apps 4096 Aug 15 01:20 ./

drwxr-xr-x 4 apps apps 4096 Aug 15 01:20 ../

-rw------- 1 apps apps  601 Aug 15 01:20 authorized_keys

-rw------- 1 apps apps  672 Aug 15 00:20 id_dsa

-rw-r--r-- 1 apps apps  599 Aug 15 00:20 id_dsa.pub




如果你还不相信你的眼睛,你可以再验证一下,即是:在用户下deploy ssh 无密码登录到用户apps下。

deploy@mode:~/.ssh$ ssh apps@192.168.1.97

Welcome to Ubuntu 12.04.4 LTS (GNU/Linux 3.11.0-15-generic x86_64)


 * Documentation:  https://help.ubuntu.com/


  System information as of Fri Aug 15 01:26:38 CST 2014


  System load:  0.0                Processes:           217

  Usage of /:   13.1% of 12.64GB   Users logged in:     1

  Memory usage: 20%                IP address for eth0: 192.168.1.97

  Swap usage:   0%


  Graph this data and manage this system at:

    https://landscape.canonical.com/


New release '14.04.1 LTS' available.

Run 'do-release-upgrade' to upgrade to it.


apps@mode:~$ ifconfig 

eth0      Link encap:Ethernet  HWaddr 00:0c:29:ff:10:0a  

          inet addr:192.168.1.97  Bcast:192.168.255.255  Mask:255.255.0.0

          inet6 addr: fe80::20c:29ff:feff:100a/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:537866 errors:0 dropped:0 overruns:0 frame:0

          TX packets:46696 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:226240610 (226.2 MB)  TX bytes:4225542 (4.2 MB)


lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:65536  Metric:1

          RX packets:111 errors:0 dropped:0 overruns:0 frame:0

          TX packets:111 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:19056 (19.0 KB)  TX bytes:19056 (19.0 KB)

这回相信自己的眼睛了吧?