Outils pour utilisateurs

Outils du site


blog

Dokuwiki - Strata semi-structured data

Intro

Voir :

DokuWiki utilise des fichiers plats, nul besoin de base de données relationnelle. Cependant il peut être utile d'utiliser des données structurées, sémantique et autre.

Une solution intéressante est l’extension Strata (semi-structured data) qui utilise par défaut sqlite (possibilité d'utiliser PostgreSQL ou MySQL).

Nous avons que les avantages d'une base de données relationnelle, sans les inconvénients. En effet, toutes les données sont dans les pages du Wiki au format texte. Un effacement de la base ne serait donc pas catastrophique !

Install

Nécessite l’extension DokuWiki sqlite

Module PHP pour communiquer avec sqlite. Sur Debian :

apt-get install php5-sqlite

Install sur alpine / PHP7

apk add php7-sqlite3 sqlite php7-pdo_sqlite

Note fichier :

Conf DW sqlite:@METADIR@/strata.sqlite3
Emplacement ./data/meta/strata.sqlite3

Notes

Pour commenter une ligne, préfixer là par “--” comme en SQL

Les données ne peuvent être saisi que par la balise <data> Pour requêter il existe les balises <table> et <list>

Exemple

Données

Création d'un page sur DokuWiki

people:alice_king

<data person>
Full Name: Alice King
Birthday [date::Y-m-d]: 1985-11-12
Birthplace [page::places]: London
Contact [link]: alice.king@example.org
Friends [ref]*: Bob Marley, Jean Paul
</data>

page people:bob_marley

<data person>
Full Name: Bob Marley
Birthday [date::Y-m-d]: 1945-02-06
Birthplace [page::places]: Nine Miles
Contact [link]:
Friends [ref]*: Alice King, Jean Paul
</data>

NB : Le ligne Contact [link]: ne contenant aucune valeur sera ignorée, elle ne sert à rien

La syntaxe basée sur SPARQL est assez simple pour la saisi de donnés.

<data nomDeLaTable>

-- Les lignes commençant par -- sont ignorées

-- Exemple
Clef: Valeur

-- Ou
Clef [type]: valeur

-- Ou encore
-- Le symbole "*" signifie que plusieurs valeurs sont possibles
Clef [type]*: valeur

Clef [type::hint]: valeur
-- Exemple
DateFacture [date::Y-m-d]: 2016-03-04
</data>

Le type sert à la fois au stockage des données ainsi qu'à la présentation

Requête

Sur une autre page

~~NOCACHE~~

<table ?p "Person" ?birthday "Birthday" ?birthplace "Birthplace" ?contact "Contact">
?p is a: person
?p Contact [link]: ?contact
?p Birthday [date]: ?birthday
?p Birthplace  [page::places]: ?birthplace
</table> 

Bob Marley n’apparaît pas. Ce n'est pas parce que vous n'avez pas assez fumé. En fait ici tous les champs demandés sont obligatoires alors que le champ Contact est vide

Réécrivons notre requête avec le champ Contact optionnel

<table ?p "Person" ?birthday "Birthday" ?birthplace "Birthplace" ?contact "Contact">
?p is a: person

optional {
  ?p Contact [link]: ?contact
} 

?p Birthday [date]: ?birthday
?p Birthplace  [page::places]: ?birthplace
</table> 

Exemple avec Union

<table ?p "Person" ?birthday "Birthday" ?birthplace "Birthplace" ?contact "Contact">
?p is a: person

optional {
  ?p Contact [link]: ?contact
}

?p Birthday [date]: ?birthday

--Lignes commentées
--?p Birthplace  [page::places]: ?birthplace
--?birthplace = London

union {
  {
    ?p Birthplace  [page::places]: ?birthplace
    ?birthplace = London
  }
  
  {
    ?p Birthplace  [page::places]: ?birthplace
    ?birthplace = Nine Miles
  }
}
</table>
2025/03/24 15:06

Docker-compose

Voir :

  • podman-compose

docker-compose.yml

version: "3.7"

services:

  memcached:
    image: memcached:1.5.19-alpine
    container_name: pm-memcached
    ports:
     - "11211"
    networks:
     - backend
    restart: unless-stopped

  php:
    image: acme/app1-www:1.01.02
    container_name: pm-www
    volumes:
     - src:/opt/acme/dir1/app1
     - /mnt/data:/mnt/data
    ports:
     - "8000"
    networks:
     - backend
    restart: unless-stopped
    depends_on:
     - memcached

  httpd:
    image: acme/app1-httpd:1.01.02
    container_name: pm-httpd
    volumes:
     - src:/opt/acme/dir1/app1
     - /var/log/app1:/var/log/app1
    ports:
     - "443:443"
    networks:
     - backend
    restart: unless-stopped
    depends_on:
     - php

networks:
  backend:
#    ipam:
#      driver: default
#      config:
#        - subnet: 192.168.10.0/24

volumes:
  src:

docker-compose.yml

version: "3.7"

services:
  webapp:
    build:
      context: .
      args:
        - http_proxy=http://192.168.56.1:3128
        - https_proxy=http://192.168.56.1:3128
    network_mode: "host"

docker-compose.yml

version: "3.7"

services:
  webapp:
    image: webapp
    container_name: webapp1
    network_mode: "host"
docker-compose build --no-cache
docker-compose up

Autres

    volumes:
      - "/etc/timezone:/etc/timezone:ro"
      - "/etc/localtime:/etc/localtime:ro"

Pb

docker-compose: error while loading shared libraries: libz.so.1: failed to map segment from shared object
# mount -o remount,noexec /tmp
# docker-compose
docker-compose: error while loading shared libraries: libz.so.1: failed to map segment from shared object
Solution
mkdir /plop
chmod 1777 /plop                  
export TMPDIR=/plop                  
docker-compose

Faire un wrapper

mv /usr/local/bin/docker-compose /usr/local/bin/docker-compose-bin

/usr/local/bin/docker-compose

#! /bin/bash
 
DIR=$(dirname "$(realpath "$0")")
TMPDIR=/tmp2
 
if [ ! -d "$TMPDIR" ]
then
        mkdir "$TMPDIR"
        chmod 1777 "$TMPDIR"
fi
 
export TMPDIR
${DIR}/docker-compose-bin "$@"
2025/03/24 15:06

Docker volume storage

Voir :

  • rclone
  • Container Storage Interface (CSI)

NFS

/etc/nfs.conf

[nfsd]
 tcp=y
 vers2=n
 vers3=n
 vers4=y
 vers4.0=y
 vers4.1=y
 vers4.2=y
systemctl restart nfs-server.service
exportfs -rav

/etc/exports

/export         *(rw,sync,fsid=0,crossmnt,no_subtree_check)
/export/partage *(rw,sync,nohide,insecure,no_subtree_check)
docker volume create --driver local --opt type=nfs4 --opt o=addr=172.19.0.1,rw --opt device=:/partage data-nfs
docker run -ti -v data-nfs:/data debian /bin/bash
2025/03/24 15:06

Docker Swarm

Notes générales

Vous allez avoir besoin d'au moins trois serveurs ou machines virtuelles avec Docker d'installé

The network ports required for a Docker Swarm to function correctly are:

TCP port 2376 for secure Docker client communication. This port is required for Docker Machine to work. Docker Machine is used to orchestrate Docker hosts.
TCP port 2377. This port is used for communication between the nodes of a Docker Swarm or cluster. It only needs to be opened on manager nodes.
TCP and UDP port 7946 for communication among nodes (container network discovery).
UDP port 4789 for overlay network traffic (container ingress networking).
ufw allow 22/tcp
ufw allow 2376/tcp
 
# Que sur le Manager
ufw allow 2377/tcp
 
ufw allow 7946/tcp
ufw allow 7946/udp
ufw allow 4789/udp
ufw reload
ufw enable
 
systemctl restart docker
docker system info

and looking for a message Swarm: active

Sur le Manager

# docker swarm init --advertise-addr 192.168.99.121
docker swarm init
docker swarm join --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2 192.168.99.121:2377

Voir l'état des nœuds

docker node ls

https://www.grottedubarbu.fr/introduction-docker-swarm/

$ openstack server create --image "Ubuntu 20.04" --flavor "s1-4" --key-name "MyKey" --net "Ext-Net" --user-data=docker.yaml my-manager
$ openstack server create --image "Ubuntu 20.04" --flavor "s1-4" --key-name "MyKey" --net "Ext-Net" --user-data=docker.yaml my-worker1
$ openstack server create --image "Ubuntu 20.04" --flavor "s1-4" --key-name "MyKey" --net "Ext-Net" --user-data=docker.yaml my-worker2

docker-compose.yaml

version: "3"
services:
  viz:
    image: dockersamples/visualizer
    volumes:
       - "/var/run/docker.sock:/var/run/docker.sock"
    ports:
       - "8080:8080"
docker stack deploy -c docker-compose.yaml visualizer

Pour vérifier que votre service fonctionne :

docker service ls
docker service ps --no-trunc visualizer
docker service inspect visualizer

Registry

Voir https://docs.docker.com/engine/swarm/stack-deploy/

docker service create --name registry --publish published=5000,target=5000 registry:2
docker service ls
curl http://localhost:5000/v2/

Test the app with Compose

docker-compose up
docker-compose down --volumes

Push the generated image to the registry

docker-compose push

Déinstall

docker service ls
docker stack rm plop
docker swarm leave --force

Autres

docker swarm update --snapshot-interval 10000
systemctl restart docker
2025/03/24 15:06

Ansible add mount option for hardening - loop on ansible mounts

- name: add nodev mount option for all LVM mounts exept root part
  mount:
    name: '{{ item.mount }}'
    src: '{{ item.device }}' # UUID not needed when LVM
    state: mounted
    fstype: '{{ item.fstype }}'
    opts: "{{ item.options |regex_replace(',nodev','') }},nodev" # Fix duplicate
  when: item.options.find("nodev") != -1 and item.device.find("mapper") != -1 and not item.mount in [ "/" ]
  with_items: '{{ ansible_mounts }}'

- name: add nodev mount option for all non-LVM mounts exept root part
  mount:
    name: '{{ item.mount }}'
    src: 'UUID={{ item.uuid }}'
    state: mounted
    fstype: '{{ item.fstype }}'
    opts: "{{ item.options |regex_replace(',nodev','') }},nodev" # Fix duplicate
  when: item.options.find("nodev") != -1 and item.device.find("mapper") == -1 and not item.mount in [ "/" ]
  with_items: '{{ ansible_mounts }}'

ou encore mieux

- name: add nodev mount option for all except root part
  mount:
    name: '{{ item.mount }}'
    # Pour les partitions non LVM, on utilise UUID, sinon on prend le device
    src: "{{ 'UUID=%s' % item.uuid if item.device.find('mapper') == -1 else item.device }}"
    state: present
    fstype: '{{ item.fstype }}'
    opts: "{{ item.options |regex_replace(',nodev','') }},nodev" # Fix duplicate
  when: item.options is not search("nodev") and not item.mount in [ "/", "/var/tmp" ]
  with_items: '{{ ansible_mounts }}'
  register: nodev_mounts
2025/03/24 15:06
blog.txt · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki