Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
16c177fa5b | |||
ad18fb502e | |||
46e2166943 | |||
874bbac6e7 | |||
00da92bdf9 | |||
9dbde4a623 | |||
076a48b0a2 | |||
d97a266456 | |||
ecf4af3734 |
@ -1,6 +1,6 @@
|
||||
# vagrant
|
||||
|
||||
le 2023-01-17
|
||||
le 2023-01-19
|
||||
|
||||
Ce dépôt héberge des **Vagrantfile** dont
|
||||
* **docker**
|
||||
@ -16,3 +16,4 @@ Ce dépôt héberge des **Vagrantfile** dont
|
||||
* **k8s** : kubernetes 1.26.00 + playbook pour master **k8s-master** et 2 noeuds **node-1** et **node-2**
|
||||
* **minione**
|
||||
* **rundeck** : Vagrantfile + playbook pour installation avec Mariadb
|
||||
* **wp-lb** : Wordpress web1 et web2, lb HaProxy, nfs, db Mariadb - Vagrantfile + playbooks
|
||||
|
243
divers/bind/mkzone
Executable file
243
divers/bind/mkzone
Executable file
@ -0,0 +1,243 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
trap cleanup SIGINT SIGTERM ERR EXIT
|
||||
|
||||
# cree les fichiers de configuration bind9
|
||||
# - ficher de zone directe
|
||||
# - ficher de zone inverse
|
||||
#
|
||||
|
||||
version="1.1"
|
||||
zone="domaine.lan"
|
||||
slave=0
|
||||
|
||||
|
||||
cleanup() {
|
||||
trap - SIGINT SIGTERM ERR EXIT
|
||||
# script cleanup here
|
||||
}
|
||||
|
||||
initialize () {
|
||||
readonly zonenet="192.168.56"
|
||||
readonly zonerev="56.168.192.in-addr.arpa"
|
||||
|
||||
# NS1
|
||||
readonly nsname="srv1"
|
||||
readonly nsip="${zonenet}.10"
|
||||
readonly nsiprev=$(echo ${nsip}|cut -d. -f4) # dernier octet pour classe C
|
||||
|
||||
# NS2
|
||||
readonly nsname2="srv2"
|
||||
readonly nsip2="${zonenet}.11"
|
||||
readonly nsiprev2=$(echo ${nsip2}|cut -d. -f4)
|
||||
readonly ttl="86400"
|
||||
|
||||
# Global
|
||||
readonly nsfqdn="${nsname}.${zone}"
|
||||
readonly nsfqdnp="${nsfqdn}."
|
||||
readonly zonep="${zone}."
|
||||
readonly date=$(date +%Y%m%d00)
|
||||
}
|
||||
|
||||
mkconflocal () {
|
||||
if [[ "${slave}" != 1 ]] ; then
|
||||
echo "Generation fichier named.conf.local ..."
|
||||
cat <<EOT > "named.conf.local"
|
||||
# fichier zone ${zone}
|
||||
# le $(date)
|
||||
|
||||
zone "${zone}" {
|
||||
type master;
|
||||
file "/etc/bind/db.${zone}"; # zone directe
|
||||
};
|
||||
|
||||
zone "${zonerev}" {
|
||||
type master;
|
||||
};
|
||||
EOT
|
||||
else
|
||||
echo "Generation fichier named.conf.local ..."
|
||||
cat <<EOT > "named.conf.local"
|
||||
# fichier zone ${zone}
|
||||
# le $(date)
|
||||
|
||||
zone "${zone}" {
|
||||
type slave;
|
||||
file "/var/cache/bind/db.${zone}"; # zone directe
|
||||
masters { ${nsip} ; };
|
||||
};
|
||||
|
||||
zone "${zonerev}" {
|
||||
type slave;
|
||||
file "/var/cache/bind/db.${zone}.rev"; # zone directe
|
||||
masters { ${nsip} ; };
|
||||
};
|
||||
|
||||
EOT
|
||||
fi
|
||||
}
|
||||
|
||||
mkzdirrect () {
|
||||
# fichier de zone directe
|
||||
echo "Generation fichier de zone directe db.${zone} ..."
|
||||
cat <<EOT > "db.${zone}"
|
||||
; fichier zone ${zone}
|
||||
; le $(date)
|
||||
\$TTL ${ttl} ; (1 day)
|
||||
\$ORIGIN ${zonep}
|
||||
@ IN SOA ${nsfqdnp} root.${nsfqdnp} (
|
||||
${date} ; serial YYYYMMDDnn
|
||||
14400 ; refresh (4 hours)
|
||||
1800 ; retry (30 minutes)
|
||||
1209600 ; expire (2 weeks)
|
||||
3600 ; minimum (1 hour)
|
||||
)
|
||||
|
||||
@ IN NS ${nsname}
|
||||
@ IN NS ${nsname2}
|
||||
|
||||
IN A 203.0.113.10 ; zone
|
||||
IN AAAA 2001:DB8:BEEF:113::10 ;
|
||||
www IN CNAME ${nsfqdnp}
|
||||
ftp IN CNAME ${nsfqdnp}
|
||||
|
||||
${nsname} IN A ${nsip}
|
||||
IN AAAA 2001:DB8:BEEF:2::22
|
||||
${nsname2} IN A ${nsip2}
|
||||
IN AAAA 2001:DB8:BEEF:100::22
|
||||
|
||||
EOT
|
||||
}
|
||||
|
||||
mkzreverse () {
|
||||
echo "Generation fichier de zone inverse db.${zone}.rev ..."
|
||||
cat <<EOT > "db.${zone}.rev"
|
||||
; fichier zone inverse ${zone}
|
||||
; le $(date)
|
||||
\$TTL ${ttl} ; (1 day)
|
||||
@ IN SOA ${nsfqdnp} root.${nsfqdnp} (
|
||||
${date} ; serial YYYYMMDDnn
|
||||
14400 ; refresh (4 hours)
|
||||
1800 ; retry (30 minutes)
|
||||
1209600 ; expire (2 weeks)
|
||||
3600 ; minimum (1 hour)
|
||||
)
|
||||
|
||||
@ IN NS ${nsname}.${zone}.
|
||||
@ IN NS ${nsname2}.${zone}.
|
||||
|
||||
|
||||
${nsiprev} IN PTR ${nsname}.${zone}.
|
||||
${nsiprev2} IN PTR ${nsname2}.${zone}.
|
||||
|
||||
EOT
|
||||
|
||||
}
|
||||
|
||||
mkresolv () {
|
||||
echo "Generation fichier /etc/resolv.conf ..."
|
||||
cat <<EOT > "/etc/resolv.conf"
|
||||
|
||||
# fichier resolv.conf ${zone}
|
||||
# le $(date)
|
||||
domain ${zone}
|
||||
search ${zone}
|
||||
nameserver 127.0.0.1
|
||||
EOT
|
||||
}
|
||||
|
||||
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
|
||||
|
||||
usage() {
|
||||
cat <<EOF # remove the space between << and EOF, this is due to web plugin issue
|
||||
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value zone [arg2...]
|
||||
|
||||
Script description here.
|
||||
|
||||
Available options:
|
||||
|
||||
-h, --help Print this help and exit
|
||||
-v, --verbose Print script debug info
|
||||
-s, --slave Some flag description
|
||||
-p, --param Some param description
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
trap - SIGINT SIGTERM ERR EXIT
|
||||
# script cleanup here
|
||||
}
|
||||
|
||||
setup_colors() {
|
||||
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
|
||||
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
|
||||
else
|
||||
NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
|
||||
fi
|
||||
}
|
||||
|
||||
msg() {
|
||||
echo >&2 -e "${1-}"
|
||||
}
|
||||
|
||||
die() {
|
||||
local msg=$1
|
||||
local code=${2-1} # default exit status 1
|
||||
msg "$msg"
|
||||
exit "$code"
|
||||
}
|
||||
|
||||
parse_params() {
|
||||
# default values of variables set from params
|
||||
flag=0
|
||||
param=''
|
||||
|
||||
while :; do
|
||||
case "${1-}" in
|
||||
-h | --help) usage ;;
|
||||
--no-color) NO_COLOR=1 ;;
|
||||
-s | --slave) flag=1 ;; # example flag
|
||||
# -p | --param) # example named parameter
|
||||
# param="${2-}"
|
||||
# shift
|
||||
# ;;
|
||||
-?*) die "Unknown option: $1" ;;
|
||||
*) break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
args=("$@")
|
||||
|
||||
# check required params and arguments
|
||||
# [[ -z "${param-}" ]] && die "Missing required parameter: param"
|
||||
[[ ${#args[@]} -eq 0 ]] && die "Missing script arguments"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
parse_params "$@"
|
||||
setup_colors
|
||||
|
||||
# script logic here
|
||||
|
||||
#msg "${RED}Read parameters:${NOFORMAT}"
|
||||
#msg "- flag: ${flag}"
|
||||
#msg "- param: ${param}"
|
||||
#msg "- arguments: ${args[*]-}"
|
||||
|
||||
zone="${args[0]-}"
|
||||
slave="${flag}"
|
||||
initialize
|
||||
if [[ ${flag} != 1 ]] ; then
|
||||
mkconflocal
|
||||
mkzdirect
|
||||
mkzreverse
|
||||
mkresolv
|
||||
else
|
||||
mkconflocal
|
||||
mkresolv
|
||||
fi
|
||||
exit 0
|
@ -12,7 +12,7 @@ fi
|
||||
|
||||
[[ -e "$rep" ]] || mkdir "$rep"
|
||||
|
||||
cd "$rep" || exit 1
|
||||
cd "$rep" || exit 1
|
||||
|
||||
cat > docker-compose.yml <<EOT
|
||||
version: '3'
|
||||
|
81
wp-lb/Vagrantfile
vendored
Normal file
81
wp-lb/Vagrantfile
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
# Base VM OS configuration.
|
||||
config.vm.box = "debian/bullseye64"
|
||||
config.ssh.insert_key = false
|
||||
config.vm.synced_folder '.', '/vagrant', disabled: true
|
||||
|
||||
# General VirtualBox VM configuration.
|
||||
config.vm.provider :virtualbox do |v|
|
||||
v.memory = 512
|
||||
v.cpus = 1
|
||||
v.linked_clone = true
|
||||
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
|
||||
v.customize ["modifyvm", :id, "--ioapic", "on"]
|
||||
end
|
||||
|
||||
# lb HAproxy.
|
||||
config.vm.define "lb" do |lb|
|
||||
lb.vm.hostname = "lb.test"
|
||||
lb.vm.network :private_network, ip: "192.168.56.2"
|
||||
lb.vm.provision "shell",
|
||||
inline: "sudo apt-get update ; sudo apt-get install -y vim curl wget"
|
||||
lb.vm.provision "ansible" do |ansible|
|
||||
ansible.playbook = "provision/setup-lb.yml"
|
||||
end
|
||||
end
|
||||
|
||||
# NFS.
|
||||
config.vm.define "nfs" do |nfs|
|
||||
nfs.vm.hostname = "nfs.test"
|
||||
nfs.vm.network :private_network, ip: "192.168.56.6"
|
||||
nfs.vm.provision "shell",
|
||||
inline: "sudo apt-get update ; sudo apt-get install -y vim curl wget"
|
||||
nfs.vm.provision "ansible" do |ansible|
|
||||
ansible.playbook = "provision/setup-nfs.yml"
|
||||
end
|
||||
end
|
||||
|
||||
# MySQL.
|
||||
config.vm.define "db" do |db|
|
||||
db.vm.hostname = "db.test"
|
||||
db.vm.network :private_network, ip: "192.168.56.5"
|
||||
db.vm.provision "shell",
|
||||
inline: "sudo apt-get update ; sudo apt-get install -y vim curl wget"
|
||||
db.vm.provision "ansible" do |ansible|
|
||||
ansible.playbook = "provision/setup-db.yml"
|
||||
end
|
||||
end
|
||||
|
||||
# Apache web1.
|
||||
config.vm.define "web1" do |web1|
|
||||
web1.vm.hostname = "web1.test"
|
||||
web1.vm.network :private_network, ip: "192.168.56.3"
|
||||
web1.vm.provider :virtualbox do |v|
|
||||
v.customize ["modifyvm", :id, "--memory", 512]
|
||||
end
|
||||
web1.vm.provision "shell",
|
||||
inline: "sudo apt-get update ; sudo apt-get install -y vim curl wget"
|
||||
web1.vm.provision "ansible" do |ansible|
|
||||
ansible.playbook = "provision/setup-web.yml"
|
||||
end
|
||||
end
|
||||
|
||||
# Apachei web2.
|
||||
config.vm.define "web2" do |web2|
|
||||
web2.vm.hostname = "web2.test"
|
||||
web2.vm.network :private_network, ip: "192.168.56.4"
|
||||
web2.vm.provider :virtualbox do |v|
|
||||
v.customize ["modifyvm", :id, "--memory", 512]
|
||||
end
|
||||
web2.vm.provision "shell",
|
||||
inline: "sudo apt-get update ; sudo apt-get install -y vim curl wget"
|
||||
web2.vm.provision "ansible" do |ansible|
|
||||
ansible.playbook = "provision/setup-web.yml"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
43
wp-lb/provision/setup-db.yml
Normal file
43
wp-lb/provision/setup-db.yml
Normal file
@ -0,0 +1,43 @@
|
||||
---
|
||||
- hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- name: modules python pour
|
||||
apt:
|
||||
name: python3-pymysql
|
||||
state: present
|
||||
|
||||
- name: install mariadb-server
|
||||
apt:
|
||||
name: mariadb-server
|
||||
state: present
|
||||
|
||||
- name: Cree Bd wordpress
|
||||
mysql_db:
|
||||
db: wordpressdb
|
||||
login_unix_socket: /var/run/mysqld/mysqld.sock
|
||||
state: present
|
||||
|
||||
- name: Ouvre port 3306 mariadb-server
|
||||
replace:
|
||||
path: /etc/mysql/mariadb.conf.d/50-server.cnf
|
||||
regexp: '^bind-address.*'
|
||||
replace: '#bind-adress = 127.0.0.1'
|
||||
backup: yes
|
||||
notify: restart mariadb
|
||||
|
||||
- name: Create MySQL user for wordpress.
|
||||
mysql_user:
|
||||
name: wordpressuser
|
||||
password: wordpresspasswd
|
||||
priv: "wordpressdb.*:ALL"
|
||||
host: '%'
|
||||
state: present
|
||||
login_unix_socket: /var/run/mysqld/mysqld.sock
|
||||
|
||||
handlers:
|
||||
- name: restart mariadb
|
||||
ansible.builtin.service:
|
||||
name: mariadb
|
||||
state: restarted
|
||||
|
29
wp-lb/provision/setup-lb.yml
Normal file
29
wp-lb/provision/setup-lb.yml
Normal file
@ -0,0 +1,29 @@
|
||||
---
|
||||
- hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- name: install haproxy
|
||||
apt:
|
||||
name: haproxy
|
||||
state: present
|
||||
|
||||
- name: parametre backend et fontend
|
||||
blockinfile:
|
||||
path: /etc/haproxy/haproxy.cfg
|
||||
block: |
|
||||
frontend proxypublic
|
||||
bind 192.168.56.2:80
|
||||
default_backend fermeweb
|
||||
|
||||
backend fermeweb
|
||||
balance roundrobin
|
||||
option httpclose
|
||||
#option httpchk HEAD / HTTP/1.0
|
||||
server web1.test 192.168.56.3:80 check
|
||||
#server web2.test 192.168.56.4:80 check
|
||||
|
||||
- name: redemarre haproxy
|
||||
service:
|
||||
name: haproxy
|
||||
state: restarted
|
||||
enabled: yes
|
88
wp-lb/provision/setup-nfs.yml
Normal file
88
wp-lb/provision/setup-nfs.yml
Normal file
@ -0,0 +1,88 @@
|
||||
---
|
||||
- hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- name: 00 - cree repertoire wordpress pour export nfs
|
||||
file:
|
||||
path: /exports/wordpress
|
||||
state: directory
|
||||
|
||||
- name: 05 - Install nfs-server
|
||||
apt:
|
||||
name: nfs-server
|
||||
state: present
|
||||
|
||||
- name: 10 - creation fichier exports nfs
|
||||
ansible.builtin.blockinfile:
|
||||
path: /etc/exports
|
||||
block: |
|
||||
/exports/wordpress 192.168.56.0/255.255.255.0 (rw,no_root_squash,subtree_check)
|
||||
|
||||
|
||||
- name: 15 - Recupere wordpress.tar.gz
|
||||
get_url:
|
||||
url: "https://fr.wordpress.org/latest-fr_FR.tar.gz"
|
||||
dest: /tmp/wordpress-6.1.1-fr_FR.tar.gz
|
||||
|
||||
- name: 20 - decompresse wordpress
|
||||
unarchive:
|
||||
src: /tmp/wordpress-6.1.1-fr_FR.tar.gz
|
||||
dest: /exports/
|
||||
remote_src: yes
|
||||
|
||||
- name: 22 - change owner et group pour repertoire wordpress
|
||||
file:
|
||||
path: /exports/wordpress
|
||||
state: directory
|
||||
recurse: yes
|
||||
owner: www-data
|
||||
group: www-data
|
||||
|
||||
- name: 25 - genere fichier de config wordpress
|
||||
copy:
|
||||
src: /exports/wordpress/wp-config-sample.php
|
||||
dest: /exports/wordpress/wp-config.php
|
||||
remote_src: yes
|
||||
|
||||
- name: 30 - genere fichier de config wordpress
|
||||
copy:
|
||||
src: /exports/wordpress/wp-config-sample.php
|
||||
dest: /exports/wordpress/wp-config.php
|
||||
remote_src: yes
|
||||
|
||||
- name: 35 - ajuste variable dbname dans fichier de config wp-config.php
|
||||
replace:
|
||||
path: /exports/wordpress/wp-config.php
|
||||
regexp: "votre_nom_de_bdd"
|
||||
replace: "wordpressdb"
|
||||
backup: yes
|
||||
|
||||
|
||||
- name: 40 ajuste variable dbusername dans fichier de config wp-config.php
|
||||
replace:
|
||||
path: /exports/wordpress/wp-config.php
|
||||
regexp: "votre_utilisateur_de_bdd"
|
||||
replace: "wordpressuser"
|
||||
backup: yes
|
||||
|
||||
- name: 45 - ajuste variable mdp dans fichier de config wp-config.php
|
||||
replace:
|
||||
path: /exports/wordpress/wp-config.php
|
||||
regexp: "votre_mdp_de_bdd"
|
||||
replace: "wordpresspasswd"
|
||||
backup: yes
|
||||
|
||||
- name: 50 - ajuste hostname fichier wp-config.php
|
||||
replace:
|
||||
path: /exports/wordpress/wp-config.php
|
||||
regexp: "localhost"
|
||||
replace: "192.168.56.5"
|
||||
backup: yes
|
||||
|
||||
- name: 55 - relance nfs
|
||||
service:
|
||||
name: nfs-server
|
||||
state: restarted
|
||||
enabled: yes
|
||||
|
||||
|
31
wp-lb/provision/setup-web.yml
Normal file
31
wp-lb/provision/setup-web.yml
Normal file
@ -0,0 +1,31 @@
|
||||
---
|
||||
- hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- name: install apache ...
|
||||
apt:
|
||||
name:
|
||||
- apache2
|
||||
- php
|
||||
- php-mbstring
|
||||
- php-mysql
|
||||
- mariadb-client
|
||||
state: present
|
||||
|
||||
- name: install nfs-common ...
|
||||
apt:
|
||||
name: nfs-common
|
||||
state: present
|
||||
|
||||
- name: montage nfs pour word press
|
||||
blockinfile:
|
||||
path: /etc/fstab
|
||||
block: |
|
||||
192.168.56.6:/exports/wordpress /var/www/html nfs soft,timeo=5,intr,rsize=8192,wsize=8192,wsize=8192 0 0
|
||||
|
||||
- name: monte export wordpress
|
||||
ansible.posix.mount:
|
||||
path: /var/www/html
|
||||
state: mounted
|
||||
fstype: nfs
|
||||
src: 192.168.56.6:/exports/wordpress
|
Reference in New Issue
Block a user