Created
February 22, 2021 12:37
-
-
Save ricekab/9ec8f494ca7ba93cd0c3ef7abd5b0b09 to your computer and use it in GitHub Desktop.
Postgres 11 Vagrantfile (centos7 base) - for development only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# All Vagrant configuration is done below. The "2" in Vagrant.configure | |
# configures the configuration version (we support older styles for | |
# backwards compatibility). Please don't change it unless you know what | |
# you're doing. | |
Vagrant.configure("2") do |config| | |
config.vm.box = "centos/7" | |
config.vm.network "forwarded_port", guest: 5432, host: 5432 | |
config.vm.provider "virtualbox" do |vb| | |
# Name as displayed in VirtualBox | |
vb.name = "vagrant_centos7_pgsql" | |
# Display the VirtualBox GUI when booting the machine | |
# vb.gui = true | |
# Customize the amount of memory on the VM: | |
vb.memory = "2048" | |
end | |
config.ssh.insert_key = false | |
config.vm.provision "shell", inline: <<-SHELL | |
echo "[ Updating system ]" | |
yum update -y | |
echo "[ Installing postgres ]" | |
#yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm | |
rpm -Uvh https://yum.postgresql.org/11/redhat/rhel-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm | |
yum -y install postgresql11-server postgresql11 | |
echo "[ Configuring and starting PostgreSQL ]" | |
/usr/pgsql-11/bin/postgresql-11-setup initdb | |
# Configure network access | |
echo "[ Configuring postgresql network access ]" | |
echo 'listen_addresses = '"'"'*'"'" >> /var/lib/pgsql/11/data/postgresql.conf | |
echo 'host all all 10.0.0.0/8 md5' >> /var/lib/pgsql/11/data/pg_hba.conf | |
echo 'host all all 192.168.0.0/16 md5' >> /var/lib/pgsql/11/data/pg_hba.conf | |
echo 'host all all 172.16.0.0/12 md5' >> /var/lib/pgsql/11/data/pg_hba.conf | |
# Alternatively, you can do 0.0.0.0/0 to accept from anywhere. | |
systemctl start postgresql-11 | |
systemctl enable postgresql-11 | |
echo "[ Creating vagrant user and database ]" | |
cd / | |
echo "CREATE ROLE vagrant CREATEDB CREATEROLE LOGIN PASSWORD 'vagrant'" | sudo -u postgres psql -a -f - | |
echo "CREATE DATABASE vagrant OWNER vagrant" | sudo -u postgres psql -a -f - | |
echo "ALTER USER postgres WITH PASSWORD 'POSTGRES'" | sudo -u postgres psql -a -f - | |
echo "[ Restarting postgresql ]" | |
systemctl restart postgresql-11 | |
echo "[ Done! ]" | |
SHELL | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment