一.系统环境
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
二.创建用户
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)
二.安装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 image 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放到
在本地我在把git的配置推送到服务器上。
本文出自 “8055082” 博客,谢绝转载!
Ubuntu 12.04.4 LTS 部署cap,布布扣,bubuko.com
原文地址:http://8065082.blog.51cto.com/8055082/1540124