elephant puppets deployment automation for postgresql · elephant puppets deployment automation for...

36
Elephant Puppets Deployment automation for PostgreSQL CCBYSA-NC http://www.flickr.com/photos/urgetopunt/7876067126/ Steve Singer [email protected]

Upload: ngothuy

Post on 28-Jul-2018

252 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Elephant PuppetsDeployment automation for

PostgreSQL

CCBYSA-NC http://www.flickr.com/photos/urgetopunt/7876067126/

Steve [email protected]

Page 2: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Who is Steve?

● Slony maintainer● Database Developer @ Afilias (Toronto)

http://www.flickr.com/photos/obis/2639893609/

Page 3: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Registrars

DNSLookup

Page 4: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

100+ of Databases

http://www.flickr.com/photos/getbutterfly/6317955134

Page 5: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Our Big Migration

Page 6: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Deployment Automation

http://www.nasa.gov/mission_pages/station/multimedia/gallery/iss034e037352.html

Page 7: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Goals of Automation: Database servers 'look' the same

http://www.flickr.com/photos/oskay/265900118

Page 8: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Consistency between QA, Staging, Production

http://www.flickr.com/photos/tempest/130084735

Page 9: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Reduce Manual Commands

Page 10: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Puppethttp://puppetlabs.com

Page 11: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Puppet Architecture

Puppetmaster

Server

Puppet agent

Server

Puppet agent

Server

Puppet agent

Page 12: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Puppet Terminology

class pgsqlpuppetmaster catalog

class slony

Node definition

Page 13: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Puppet Class

class postgresql { package { 'postgresql-server' : ensure => installed, provider => 'yum' }}

resource

Resource Type

Page 14: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Declartive

file { '/tmp/hello_world.txt' : content => 'Welcome to Ottawa', owner => 'pgcon', mode => 0644}

/tmp/hello_world.txt

Welcome to Ottawa

Page 15: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Puppet At Afilias

PuppetMaster

LDAP(ENC)

Page 16: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Goals for Databases

● Deploy Binaries● Manage pg_hba.conf and postgresq.conf● Manage postgres unix users● Handle init db● Manage Crontabs● Manage slons and slonik preambles

Page 17: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

PostgreSQL Module

https://github.com/puppetlabs/puppet-postgresql

● Pre-existing module for managing postgresql● Manages installing, start/stopping postgresql● We don't actually use it

Page 18: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

pgsql_cluster resource

define pgsql_cluster ($clustername,$port,$datadir, $conf_template,$listen_address,$pguser, $pghba_template,$service_name,$pguser_password,$encoding){...}

• One instance per database $datadir• Performs initdb• Deploys postgresql.conf• Deploys pg_hba.conf• Creates standard database users

Page 19: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

postgresql.conf.erb#------------------------------------------------------------------------------# RESOURCE USAGE (except WAL)#------------------------------------------------------------------------------

# - Memory -

shared_buffers = <%= shared_buffers %> # min 128kB # (change requires restart)

Templates

Page 20: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

postgresql.conf#------------------------------------------------------------------------------# RESOURCE USAGE (except WAL)#------------------------------------------------------------------------------

# - Memory -

shared_buffers = 300MB # min 128kB # (change requires restart)

Templates

Page 21: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

postgresql.conf

$shared_buffers= '300MB'$conf_template='dba/postgresql.91.conf.erb'

file { "${pg_datadir}/postgresql.conf" : owner => "$pguser", group => postgres, mode => 644, require => Exec["${name}_initdb_${name}"], content => template("$conf_template"), }• $

Page 22: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

listen_addresses and facter

Puppet master Database Server

Puppet agent

facterFacts$::ipaddress_eth0

listen_address= '<%= scope.lookupvar('::ipaddress_eth0') %>'

Page 23: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Hiera 101 Separate Code From Data

http://commons.wikimedia.org/wiki/File:Lower_Antelope_Canyon_478.jpgBy Uploaded by Meckimac [GFDL (http://www.gnu.org/copyleft/fdl.html) or CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/)], via Wikimedia Commons

Page 24: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Hiera 101: Lookup Values

class db_server { $application='postgres' $product='ORG' $port = hiera('postgres_port') . .}

Page 25: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Hiera 101: Define a Hierarchy

--:hierarchy:-domains/%{domain}/%{fqdn}/%{application}-domains/%{domain}/%{application}/-environment_type/%{environment_type}/%{application}-complexes/%{product}/%{application}

Page 26: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Hiera 101: Hierarchy

domains/tor.afilias-int.info/db1.tor.afilias-int.info postgres.yaml db2.tor.afilias-int.info

postgres.yamlenvironment_type /QA postgres.yaml PRODUCTION postgres.yamlproducts ORG postgres.yaml INFO postgres.yaml

Page 27: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Hiera 101: postgres.yaml

postgres_port: 5432

postgres_pgversion: '9.2.4'

postgres_unixuser: postgres

postgres_db_list: pgcon : ssinger pgeu : jwieck

Page 28: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

conf template server type

postgresql.90.small.conf.erb

postgresql.91.small.conf.erb

postgresql.92.small.conf.erb

postgresql.90.oltp.conf.erb

postgresql.91.oltp.conf.erb

postgresql.92.oltp.conf.erb

postgresql.90.batch.conf.erb

postgresql.91.batch.conf.erb

postgresql.92.batch.conf.erb

Page 29: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Switch Based Configpostgresql.90.conf.erb

postgresql.92.conf.erb

shared_buffers = <%= shared buffers %>max_connections = <%= max_connections %>

postgresql.91.conf.erb

shared_buffers = <%= shared buffers %>max_connections = <%= max_connections %>

shared_buffers = <%= shared buffers %>max_connections = <%= max_connections %>

Page 30: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Crontabs

cron { “backup_${name}” : command => “ /opt/dbs/scripts/backup.sh $clustername”, user => 'postgres', hour => '0', minute => '0', ensure => 'present'}

Page 31: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Slony

cluster name = mydbclusternode 9181 admin conninfo = 'host=db1.on1 user=slony'node 9182 admin conninfo = 'host=db2.on1 user=slony'

set add table ( id =1 , fully qualified name = 'public.foo' );

Page 32: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Slony: Slonik preambles

cluster name=<%= clustername %>;# A slonik preamble that defines# the 'node xxx admin conninfo...' data# and an associated DEFINE for each# node in the cluster#<% slon_conf.each do | node_id, values | %><% port=values['port'] if port==nil or port=='' port=complex_port end %>node <%= node_id %> admin conninfo='host=<%= values['host'] %> ......define CONNINFO_<%= node_id %> 'host=<%= values['host'] %> .....<% end %>

/opt/configs/$clustername/slonik.preamble : slonik_preamble.erb

Page 33: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Slony Settings

# YAML for the slons running on a particular serverpostgres_slons: - 9181

# YAML map of connection data to all slonspostgres_slon_nodes: '9181': 'host': 'db1.on1.afilias-int.info' 'port' : '5432' '9192': 'host': 'db2.tx1.afilias-int.info' 'port' : '5432'

Page 34: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Puppeteiring Challenges

● Removing classes no longer installed● Managing passwords

By Nicole Gordine (Own work) [CC-BY-3.0 (http://creativecommons.org/licenses/by/3.0)], via Wikimedia Commons

Page 35: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Next Steps

● Manage database login users● Automating PostgreSQL restarts

CCBYSA http://puppet.wikia.com/wiki/The_Big_Little_Circus?file=Hannibal-Snapdragon.jpg

Page 36: Elephant Puppets Deployment automation for PostgreSQL · Elephant Puppets Deployment automation for ... Deployment Automation ... Puppet Architecture Puppetmaster Server Puppet agent

Questions?

CCBYSA http://commons.wikimedia.org/wiki/File:Wayang_kulit_elephant_01B.jpg

http://[email protected]