Skip to content

Commit

Permalink
pgbackrest dans tous ses etats
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Portigliatti committed Jan 31, 2024
1 parent c94851f commit 83f114d
Show file tree
Hide file tree
Showing 12 changed files with 1,475 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fr/pgbackrest_dans_tous_ses_etats/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.vagrant/*
.vagrant/machines/pg1/libvirt/action_provision
.vagrant/machines/pg1/libvirt/action_provision
.vagrant/machines/pg1/libvirt/box_meta
.vagrant/machines/pg1/libvirt/action_provision
.vagrant/machines/pg1/libvirt/box_meta
.vagrant/machines/pg1/libvirt/created_networks
.vagrant/machines/pg1/libvirt/id
.vagrant/machines/pg1/libvirt/index_uuid
.vagrant/machines/pgbackrest1/libvirt/action_provision
.vagrant/machines/pgbackrest1/libvirt/box_meta
.vagrant/machines/pgbackrest1/libvirt/created_networks
.vagrant/machines/pgbackrest1/libvirt/id
.vagrant/machines/pgbackrest1/libvirt/index_uuid
49 changes: 49 additions & 0 deletions fr/pgbackrest_dans_tous_ses_etats/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
ifdef env
EXTRA_ARGS:=--env=$(env)
endif
ifdef provshell
EXTRA_ARGS:=$(EXTRA_ARGS) --shell=$(provshell)
endif

SHELL:=/bin/bash
.PHONY: help
help: ## Display callable targets.
@echo "Reference card for usual actions."
@echo "Here are available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := help

CURRENT_DIR=$(shell pwd)

.PHONY: all ## Up all VM and provision them.
all: up provision## Up all VM and provision them.

.PHONY: init ## Init ansible roles and collections.
init: ## Init ansible roles and collections.
$(MAKE) -C ../ansible.d init

.PHONY: up ## Up all VM. Also init ansible roles and collections.
up: ## Up all VM. Also init ansible roles and collections.
vagrant $(EXTRA_ARGS) up --no-provision

.PHONY: reset ## Reset all VM. Destroy them and create them.
reset: destroy all ## Reset all VM. Destroy them and create them.

.PHONY: provision ## Provision all VM. Also init ansible roles and collections.
provision: ## Provision all VM. Also init ansible roles and collections.
vagrant upload install_pg.sh install.sh pg1
vagrant upload install_pgbackrest.sh install.sh pgbackrest1
vagrant $(EXTRA_ARGS) provision
vagrant ssh -c 'bash install.sh' pg1
vagrant ssh -c 'bash install.sh' pgbackrest1



.PHONY: destroy ## Destroy all VM.
destroy: ## Destroy all VM.
vagrant $(EXTRA_ARGS) destroy --force

.PHONY: update ## Update all box.
update: ## Update all box.
vagrant $(EXTRA_ARGS) box update
15 changes: 15 additions & 0 deletions fr/pgbackrest_dans_tous_ses_etats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# TEST

1. Lancer `make all` (ou `make reset` pour reprendre tout de 0)

2. Faire le TP en se connectant aux machines `pg1` et `pgbackrest1` via `vagrant ssh`.

# Jour du workshop

1. Copier le fichier `install_pg.sh` sur les VM des stagiaires

2. Copier le fichier `install_pgbackrest.sh` sur la VM de repo pgbackrest

3. Lancer les deux scripts

4. Vous pouvez faire le TP.
101 changes: 101 additions & 0 deletions fr/pgbackrest_dans_tous_ses_etats/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# -*- 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.

require 'getoptlong'

opts = GetoptLong.new(
[ '--env', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--shell', GetoptLong::OPTIONAL_ARGUMENT ]
)

customParameter=''

opts.ordering=(GetoptLong::REQUIRE_ORDER) ### this line.

SHELL = false

opts.each do |opt, arg|
case opt
when '--env'
SOCLE_VERSION=arg
when '--shell'
SHELL=arg
end
end

#BOX_BASE = "generic/rocky8"
#BOX_BASE = "generic/rocky8"
#BOX_BASE = "almalinux/8"
BOX_BASE = "generic/rocky8"
#BOX_BASE = "generic/debian11"
#BOX_BASE = "generic/ubuntu2204"
#SOCLE_VERSION = "advanced"
LIMIT = "all"
#if BOX_BASE == "generic/rocky8" or BOX_BASE == "generic/centos8" then
# SHELL = true
#else
# SHELL = false
#end
n=1
Vagrant.configure("2") do |config|
# Configuration du primary
#config.ssh.private_key_path = "~/.ssh/id_rsa"
config.ssh.forward_agent = true
config.ssh.insert_key = false
config.vm.box = BOX_BASE

if BOX_BASE == "generic/ubuntu2204" then
config.vm.box_version = "4.1.20"
end
if BOX_BASE == "generic/rocky9" or BOX_BASE == "generic/rocky8" or BOX_BASE == "generic/centos8" or BOX_BASE == "almalinux/8" then
config.vm.provision "shell",
inline: "sudo yum install python3.9 nano git -y && sudo systemctl stop firewalld && sudo systemctl disable firewalld && sudo yum update -y"
end

(1..n).each do |pg_host_cpt|
pg_hostname="pg#{pg_host_cpt}"
config.vm.define pg_hostname do |host_config|
host_config.vm.hostname = pg_hostname
host_config.vm.network :private_network, ip: "192.168.90.1#{pg_host_cpt}"


#if SOCLE_VERSION == "essential" then
# host_config.vm.synced_folder "/tmp/share/essential", "/pgbackups",
# type: "nfs",
# nfs_version: 4,
# nfs_udp: false #
#end
# Libvirt settings
host_config.vm.provider "libvirt" do |hv|
# VM Shape
hv.cpus = "1"
hv.memory = "1024"
end
end
end


pgbackrest_repo_hostname="pgbackrest1"
config.vm.define pgbackrest_repo_hostname do |host_config|
host_config.vm.hostname = pgbackrest_repo_hostname
host_config.vm.network :private_network, ip: "192.168.90.32"

# Libvirt settings
host_config.vm.provider "libvirt" do |hv|
# VM Shape
hv.cpus = "1"
hv.memory = "1024"
end
# host_config.vm.provision "ansible" do |ansible|
# ansible.limit = LIMIT
# ansible.playbook = "../ansible.d/playbooks/#{SOCLE_VERSION}.yml"
# ansible.inventory_path = "../ansible.d/environments/#{SOCLE_VERSION}/inventory"
# ansible.compatibility_mode = "2.0"
# end
end
end # Vagrant.configure("2") do |config|
13 changes: 13 additions & 0 deletions fr/pgbackrest_dans_tous_ses_etats/install_pg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sudo yum install python3.9 nano git -y && sudo yum update -y
sudo dnf install epel-release -y
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql16-server
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
sudo systemctl enable postgresql-16
sudo systemctl start postgresql-16
sudo yum update -y
sudo yum install postgresql-contrib -y
sudo -iu postgres ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa <<<y >/dev/null 2>&1
sudo setenforce 0
sudo -u postgres ssh-keygen -t rsa -N '' -f /var/lib/pgsql/.ssh/id_rsa
104 changes: 104 additions & 0 deletions fr/pgbackrest_dans_tous_ses_etats/install_pgbackrest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
sudo yum install python3.9 nano git -y && sudo yum update -y
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install pgbackrest -y
sudo touch /etc/pgbackrest.conf
cat<<EOF | sudo tee "/etc/pgbackrest.conf"
[global]
repo1-path=/var/lib/pgbackrest
repo1-retention-full=2
repo1-retention-diff=7
process-max=2
log-level-console=info
log-level-file=debug
# compression extrême et lente
compress-type=gz
compress-level=9
[global:archive-push]
# archivage uniquement : compression la plus rapide possible
compress-type=gz
compress-level=9
EOF
sudo chown postgres:postgres /var/lib/pgbackrest
sudo mkdir -p /etc/pgbackrest
sudo mkdir -p /etc/pgbackrest/conf.d
sudo mv /etc/pgbackrest.conf /etc/pgbackrest/
sudo chown -R postgres:postgres /etc/pgbackrest
sudo yum install postgresql-contrib -y
sudo -u postgres ssh-keygen -t rsa -N '' -f /var/lib/pgsql/.ssh/id_rsa
sudo setenforce 0
## S3
#sudo useradd -s /sbin/nologin -d /opt/minio minio
#sudo yum install -y wget
#sudo mkdir -p /opt/minio/bin/minio
#sudo wget https://dl.min.io/server/minio/release/linux-amd64/minio -O /opt/minio/bin/minio
#sudo chmod +x /opt/minio/bin/minio
#cat<<EOF | sudo tee "/opt/minio/minio.conf"
#MINIO_VOLUMES=/opt/minio/data
#MINIO_DOMAIN=minio.local
#MINIO_OPTS="--certs-dir /opt/minio/certs --address :443 --compat"
#MINIO_ACCESS_KEY="workshop16_access_key"
#MINIO_SECRET_KEY="workshop16_secret_key"
#EOF
#sudo chown -R minio:minio /opt/minio
#sudo mkdir ~/certs
#sudo cd ~/certs && openssl genrsa -out ca.key 2048
#sudo cd ~/certs && openssl req -new -x509 -extensions v3_ca -key ca.key -out ca.crt -days 99999 -subj "/C=BE/ST=Country/L=City/O=Organization/CN=some-really-cool-name"
#sudo cd ~/certs && openssl genrsa -out server.key 2048
#sudo cd ~/certs && openssl req -new -key server.key -out server.csr -subj "/C=BE/ST=Country/L=City/O=Organization/CN=some-really-cool-name"
#sudo cd ~/certs && openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 99999 -sha256
#sudo mkdir -p -m 755 /opt/minio/certs
#sudo cp server.crt /opt/minio/certs/public.crt
#sudo cp server.key /opt/minio/certs/private.key
#sudo chown -R minio:minio /opt/minio/certs
#sudo chmod -R 644 /opt/minio/certs/public.crt
#sudo chmod -R 644 /opt/minio/certs/private.key
#cat<<EOF | sudo tee "/etc/systemd/system/minio.service"
#[Unit]
#Description=Minio
#Documentation=https://docs.minio.io
#Wants=network-online.target
#After=network-online.target
#AssertFileIsExecutable=/opt/minio/bin/minio
#
#[Service]
#AmbientCapabilities=CAP_NET_BIND_SERVICE
#WorkingDirectory=/opt/minio
#
#User=minio
#Group=minio
#
#PermissionsStartOnly=true
#
#EnvironmentFile=-/opt/minio/minio.conf
#ExecStartPre=/bin/bash -c "[ -n \\"\${MINIO_VOLUMES}\\" ] || echo \\"Variable MINIO_VOLUMES not set in /opt/minio/minio.conf\\""
#
#ExecStart=/opt/minio/bin/minio server \$MINIO_OPTS \$MINIO_VOLUMES
#
#StandardOutput=journal
#StandardError=inherit
#
## Specifies the maximum file descriptor number that can be opened by this process
#LimitNOFILE=65536
#
## Disable timeout logic and wait until process is stopped
#TimeoutStopSec=0
#
## SIGTERM signal is used to stop Minio
#KillSignal=SIGTERM
#
#SendSIGKILL=no
#
#SuccessExitStatus=0
#
#[Install]
#WantedBy=multi-user.target
#EOF
#
#sudo systemctl enable minio
#sudo systemctl start minio
#sudo firewall-cmd --quiet --permanent --add-service=https
#sudo firewall-cmd --quiet --reload
#sudo systemctl status minio

# bucket name: q9maqbezkxk6
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 83f114d

Please sign in to comment.