我正在使用 PuPHPet/Puppet/Vagrant 使用 nginx 和 postgresql 设置 VM。我希望能够使用 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',
}
这是我在虚拟机中的 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