postgresql - Vagrant 无法正常工作

标签 postgresql ubuntu-12.04 chef-infra vagrant

我有一个使用 chef 来帮助安装的 vagrant 文件:

Vagrant.configure(2) do |config|
  config.vm.box = 'opscode-ubuntu-12.04_chef-11.4.0'
  config.vm.box_url = 'https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_chef-11.4.0.box'
  config.vm.network :forwarded_port, guest: 3000, host: 3000

  config.vm.provider(:virtualbox) do |vb|
    vb.customize [
      "modifyvm", :id,
      "--memory", "1024",
      "--cpus",   "4"
    ]
  end

  config.vm.provision :shell, inline: %Q{
    sudo apt-get install -y postgresql-client
  }

  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["cookbooks"]
    chef.add_recipe :apt
    chef.add_recipe 'postgresql::server'
    chef.add_recipe 'build-essential'
    chef.add_recipe 'rvm::vagrant'
    chef.add_recipe 'rvm::system'
    chef.add_recipe 'git'
    chef.json = {
      :postgresql => {
    :version => '9.3'
      },
      "postgresql" => {
        "password" => {
          "postgres" => "kshgfi3ret3hihjfbkivtbo3ity835"
        }
      },
      "database" => {
        "create" => ["aisisplatform"]
      },
      :git   => {
        :prefix => "/usr/local"
      },
      :rvm => {
        'rubies' => [ 'ruby-2.1.0' ],
        'default_ruby' => 'ruby-2.1.0',
        'vagrant' => {
          :system_chef_solo => '/usr/bin/chef-solo'
        }
      },
    }
  end
end

这有几个问题:

  • vagrant up 启动过程中,我收到如下警告:

    /tmp/vagrant-chef-1/chef-solo-1/cookbooks/rvm/libraries/rvm_chef_user_environment.rb:32: 警告:从顶层访问类变量

  • 下一个问题是事情不能正常工作,有时 vm 通过 psql 命令看到 PostgreSQL,有时它不知道它是什么并声明它不是安装。当它确实看到它时,它声明 psql: FATAL: role "vagrant"does not exist

  • 最后一个问题是,当虚拟机启动时,有超过 200 个常规和安全更新。我希望在第一次设置 vm 时通过 vagrant up 处理这个问题。我试过这样做:

    config.vm.provision :shell, inline: %Q{ sudo apt-get 更新 sudo apt-get upgrade -y

但是当脚本运行时,我得到TON 关于stdn 等等的错误。那么,我该怎么做才能解决这些问题?我的 vagrant 文件有什么问题?

最佳答案

我修改了 vagrant 文件以使用 omnibus 和 berkshelf 插件。前者将确保 Chef 处于所需的版本,而后者则使 Recipe 保持最新。

我还注意到“类变量访问”警告,其根本原因可能隐藏在 rvm 说明书中。我没有看得更深,因为我的 Vagrant 运行没有错误地完成了。

例子

$ tree
.
├── Berksfile
└── Vagrantfile

伯克斯文件

site :opscode

cookbook "apt"
cookbook "postgresql"
cookbook "build-essential"
cookbook "rvm", :github => "fnichol/chef-rvm"
cookbook "git"

Vagrant 文件

Vagrant.require_plugin "vagrant-omnibus"
Vagrant.require_plugin "vagrant-berkshelf"

Vagrant.configure(2) do |config|

  # Box config
  config.vm.box = 'precise64'
  config.vm.box_url = 'http://files.vagrantup.com/precise64.box'

  # Plugin config
  config.omnibus.chef_version = :latest
  config.berkshelf.enabled = true

  # Network config
  config.vm.network :forwarded_port, guest: 3000, host: 3000

  # Virtual config
  config.vm.provider(:virtualbox) do |vb|
    vb.customize [
      "modifyvm", :id,
      "--memory", "1024",
      "--cpus",   "4"
    ]
  end

  # Provisioner config
  config.vm.provision :chef_solo do |chef|
    chef.add_recipe 'apt'
    chef.add_recipe 'postgresql::client'
    chef.add_recipe 'postgresql::server'
    chef.add_recipe 'build-essential'
    chef.add_recipe 'rvm::system'
    chef.add_recipe 'git'
    chef.json = {
      :postgresql => {
        :version => '9.3'
      },
      "postgresql" => {
        "password" => {
          "postgres" => "kshgfi3ret3hihjfbkivtbo3ity835"
        }
      },
      "database" => {
        "create" => ["aisisplatform"]
      },
      :git   => {
        :prefix => "/usr/local"
      },
      :rvm => {
        'rubies' => [ 'ruby-2.1.0' ],
        'default_ruby' => 'ruby-2.1.0',
        'vagrant' => {
          :system_chef_solo => '/usr/bin/chef-solo'
        }
      },
    }
  end
end

注意事项:

  • 可以使用标准的 Ubuntu 镜像。综合插件将自动安装 Chef 11.10
  • “rvm::vagrant”配方因不必要而被删除。 Chef 是使用综合安装程序安装的,因此将拥有自己的嵌入式 ruby​​ 版本
  • 使用“postgresql::client”配方代替 shell 供应器。

关于postgresql - Vagrant 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21790846/

相关文章:

sql - 查找所有带有希伯来名字的记录

apache - 使用简单的名称访问局域网上的本地网络服务器,例如 http ://example. intranet.com

windows - 我可以将 knife.rb 作为参数传递给 knife 命令吗?

ruby - Chef Recipe 中的无效多字节字符 (US-ASCII)

sql - 您可以/如何在不破坏 RI 的情况下添加引用圈?

python - "settings.DATABASES is improperly configured"与 django 1.6

java - Postgresql:在同一事务中读取未提交的数据

MySQL 作业无法启动

mysql - 从 Workbench 连接到 MySQL

chef-infra - Chef Solo 获取用户输入