安装vagrant-aws插件

1
$ vagrant plugin install vagrant-aws

配置vagrant

1
2
3
4
$ mkdir aws
$ cd aws
$ vagrant init
$ vi Vagrantfile

修改配置文件Vagrantfile, 添加下列内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
config.vm.define :osapp01d do |osapp01d|

  osapp01d.vm.provider :aws do |aws, override|

    aws.access_key_id = 您的aws access key id
    aws.secret_access_key = 您的aws secret access key

    aws.instance_type = 您的EC2 instance类型
    aws.ami = "ami-9ffa709e" #cent-os 6.4 64位
    aws.region = "ap-northeast-1" #东京主机
    aws.security_groups = 您的security group id
    aws.subnet_id = 您的subnet id
    aws.tags = {
      'Name' => "osapp01d"
    }
    aws.elastic_ip = true #为EC2 instance绑定静态IP

    override.ssh.username = "root"
    aws.keypair_name = 您的key pair name
    override.ssh.private_key_path = .pem私钥的位置

    override.vm.box = "dummy"
    override.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"

    override.vm.synced_folder "./", "/vagrant", disabled: true
  end
end

参数的含义和赋值请参考这里
请把相关参数替换成您的实际值

PS:关于各linux发行版的默认user

For Amazon Linux, the default user name is ec2-user. For RHEL5, the user name is often root but might be ec2-user. For Ubuntu, the user name is ubuntu. For SUSE Linux, the user name is root. Otherwise, check with your AMI provider.

创建 EC2 instance 并启动

1
vagrant up --provider=aws osapp01d

如果您使用的是gnome-terminal, 请注意要设置为以登录shell方式运行命令(Run command as login shell)
Edit > Profile Preferences > Title and Command > Run command as a login shell

登录EC2 instance, 添加vagrant用户

1
vagrant ssh osapp01d

以下代码在EC2 inscatnce里执行

1
2
3
$ groupadd admin
$ useradd -g admin vagrant
$ passwd vagrant

设置vagrant用户的密码

1
$ visudo

在最末添加一行:

%admin ALL=(ALL:ALL) ALL

如需使用同步文件夹,需将Defaults requiretty这行注释掉
保存退出

向EC2 instance安装cookbooks

1
2
3
4
5

$ mkdir Cookbooks
$ cd Cookbooks
$ knife solo prepare vagrant@xx.xx.xx.xx(您的EC2 instance的public ip)
$ knife solo cook vagrant@xx.xx.xx.xx(您的EC2 instance的public ip) nodes/osapp01d,json

关于文件夹同步

如果您希望使用同步文件夹,
请将Vagrantfile里的override.vm.synced_folder "./", "/vagrant", disabled: true注释掉
并且重启EC2 instance

1
vagrant reload osapp01d

请注意这一步要在EC2 instance创建完成后,
并且您已经将Defaults requiretty注释掉后才可执行.
否则会发生问题vagrant无法正常启动, 详情见这里

在ActiveAdmin下自定义filter

rails4之后,之前的`model`里加入`search_methods :filter_name`的做法已经失效,需修改为:``` ruby class PromoCode (ids) { with_tags(ids) } def self. …… Continue reading

Mac上搭建Phonegap环境

Published on October 02, 2014

Rails遗留程序里最常犯的错误(译)

Published on July 23, 2014