vagrant postgresql和外部db gui

时间:2013-09-13 00:01:56

标签: postgresql vagrant puppet

我正在使用PuPHPet / Puppet / Vagrant来设置一个带有nginx和postgresql的虚拟机。我希望能够通过GUI连接到postgresql数据库。我不知道设置它的必要步骤。

我想我需要在本地计算机上将端口5432转发到5432,然后编辑pg_hba.conf以允许外部连接,但我不知道需要什么。

这是我目前的Vagrantfile(没有端口转发)

Vagrant.configure("2") do |config|
  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"

  config.vm.network :private_network, ip: "10.10.10.10"
    config.ssh.forward_agent = true

  config.vm.provider :virtualbox do |v|
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    v.customize ["modifyvm", :id, "--memory", 1024]
    v.customize ["modifyvm", :id, "--name", "NGINX_PostgreSQL"]
  end


  config.vm.synced_folder "./", "/var/www", id: "vagrant-root" 
  config.vm.provision :shell, :inline =>
    "if [[ ! -f /apt-get-run ]]; then sudo apt-get update && sudo touch /apt-get-run; fi"

  config.vm.provision :puppet do |puppet|
    puppet.manifests_path = "vagrant/manifests"
    puppet.module_path = "vagrant/modules"
    puppet.options = ['--verbose']
  end
end

这是我的default.pp文件

group { 'puppet': ensure => present }
Exec { path => [ '/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/' ] }
File { owner => 0, group => 0, mode => 0644 }

class {'apt':
  always_apt_update => true,
}

Class['::apt::update'] -> Package <|
    title != 'python-software-properties'
and title != 'software-properties-common'
|>

    apt::key { '4F4EA0AAE5267A6C': }

apt::ppa { 'ppa:ondrej/php5-oldstable':
  require => Apt::Key['4F4EA0AAE5267A6C']
}

class { 'puphpet::dotfiles': }

package { [
    'build-essential',
    'vim',
    'curl',
    'git-core'
  ]:
  ensure  => 'installed',
}

class { 'nginx': }


nginx::resource::vhost { 'mylaravel.com':
  ensure       => present,
  server_name  => [
    'mylaravel.com'  ],
  listen_port  => 80,
  index_files  => [
    'index.html',
    'index.htm',
    'index.php'
  ],
  www_root     => '/var/www/public',
  try_files    => ['$uri', '$uri/', '/index.php?$args'],
}

$path_translated = 'PATH_TRANSLATED $document_root$fastcgi_path_info'
$script_filename = 'SCRIPT_FILENAME $document_root$fastcgi_script_name'

nginx::resource::location { 'mylaravel.com-php':
  ensure              => 'present',
  vhost               => 'mylaravel.com',
  location            => '~ \.php$',
  proxy               => undef,
  try_files           => ['$uri', '$uri/', '/index.php?$args'],
  www_root            => '/var/www/public',
  location_cfg_append => {
    'fastcgi_split_path_info' => '^(.+\.php)(/.+)$',
    'fastcgi_param'           => 'PATH_INFO $fastcgi_path_info',
    'fastcgi_param '          => $path_translated,
    'fastcgi_param  '         => $script_filename,
    'fastcgi_param   '           => 'APP_ENV dev',
    'fastcgi_param    '           => 'APP_DBG true',
    'fastcgi_pass'            => 'unix:/var/run/php5-fpm.sock',
    'fastcgi_index'           => 'index.php',
    'include'                 => 'fastcgi_params'
  },
  notify              => Class['nginx::service'],
}

class { 'php':
  package             => 'php5-fpm',
  service             => 'php5-fpm',
  service_autorestart => false,
  config_file         => '/etc/php5/fpm/php.ini',
  module_prefix       => ''
}

php::module {
  [
    'php5-pgsql',
    'php5-cli',
    'php5-curl',
    'php5-intl',
    'php5-mcrypt',
    'php-apc',
  ]:
  service => 'php5-fpm',
}

service { 'php5-fpm':
  ensure     => running,
  enable     => true,
  hasrestart => true,
  hasstatus  => true,
  require    => Package['php5-fpm'],
}

class { 'php::devel':
  require => Class['php'],
}


class { 'xdebug':
  service => 'nginx',
}

class { 'composer':
  require => Package['php5-fpm', 'curl'],
}

puphpet::ini { 'xdebug':
  value   => [
    'xdebug.default_enable = 1',
    'xdebug.remote_autostart = 0',
    'xdebug.remote_connect_back = 1',
    'xdebug.remote_enable = 1',
    'xdebug.remote_handler = "dbgp"',
    'xdebug.remote_port = 9000'
  ],
  ini     => '/etc/php5/conf.d/zzz_xdebug.ini',
  notify  => Service['php5-fpm'],
  require => Class['php'],
}

puphpet::ini { 'php':
  value   => [
    'date.timezone = "America/Chicago"'
  ],
  ini     => '/etc/php5/conf.d/zzz_php.ini',
  notify  => Service['php5-fpm'],
  require => Class['php'],
}

puphpet::ini { 'custom':
  value   => [
    'display_errors = On',
    'error_reporting = -1'
  ],
  ini     => '/etc/php5/conf.d/zzz_custom.ini',
  notify  => Service['php5-fpm'],
  require => Class['php'],
}


class { 'postgresql':
  charset => 'UTF8',
  locale  => 'en_US.UTF-8',
}->
class { 'postgresql::server':
  config_hash => {
    postgres_password => 'root',
  },
}

postgresql::db { 'appDB':
  user     => 'dadams',
  password => 'mypassword',
  grant    => 'ALL',
}

这是我在VM中的pg_hba.conf文件

# This file is managed by Puppet. DO NOT EDIT.

# Rule Name: local access as postgres user
# Description: none
# Order: 001
local   all     postgres                ident

# Rule Name: local access to database with same name
# Description: none
# Order: 002
local   all     all             ident

# Rule Name: deny access to postgresql user
# Description: none
# Order: 003
host    all     postgres        0.0.0.0/0       reject

# Rule Name: allow access to all users
# Description: none
# Order: 100
host    all     all     127.0.0.1/32    md5

# Rule Name: allow access to ipv6 localhost
# Description: none
# Order: 101
host    all     all     ::1/128 md5

2 个答案:

答案 0 :(得分:2)

大多数GUI都允许您通过SSH隧道进行连接。这是做你想做的最好的方式。

答案 1 :(得分:1)

Vagrantfile中添加以下端口转发规则并执行vagrant reload,看看是否可以连接到postgresql。

config.vm.network :forwarded_port, guest: 5432, host:5432

  

注意:您可能仍需要将postgresql.conf listen_addresses(绑定)更改为*(所有)接口,并通过修改pg_hba.conf文件中的主机记录来允许来自某些网络的客户端连接。

示例允许无条件地从网络10.1.1.0/24连接

host    all             all             10.1.1.0/24                 trust

我认为在您的使用案例中,启用第二个网络接口(公共网络)将使生活更轻松,避免大量端口转发和网络问题。