{{tag>Brouillon DB KV}} # Notes etcd Voir aussi : * [[Notes CouchDB|CouchDB]] Python : * https://www.dasblinkenlichten.com/python-pieces-working-with-etcd/ ## Intro * https://etcd.io/ * https://etcd.io/docs/v3.5/dev-guide/interacting_v3/ * https://www.ionos.fr/digitalguide/hebergement/aspects-techniques/quest-ce-quetcd/ * https://www.blackcreeper.com/kubernetes/etcd-decouverte-et-premiers-pas/ ## Install * http://play.etcd.io/install * https://www.digitalocean.com/community/tutorials/how-to-set-up-and-secure-an-etcd-cluster-with-ansible-on-ubuntu-18-04-fr * https://docs.okd.io/3.11/admin_guide/assembly_replace-etcd-member.html ~~~bash apt install etcd-client apt-get install etcd ~~~ ## Config ### Droits https://etcd.io/docs/v3.5/demo/ ## Exemples basiques Lancement ~~~bash etcd ~~~ Connexion ~~~bash etcdctl --endpoints http://127.0.0.1:2379 get / ~~~ Put ~~~bash etcdctl put greeting "Hello, etcd" ~~~ Get ~~~bash ETCDCTL_API=3 etcdctl get greeting etcdctl get foo --print-value-only etcdctl get --prefix --rev=4 foo etcdctl watch foo --hex ~~~ ~~~bash etcdctl --no-sync --peers https//plop1.lan:10835,https//plop2.lan:10836 -u username:password ls / alias e='etcdctl --ca-file ~/compose_etcd.pk --no-sync --peers https://aws-us-east-1-portal10.dblayer.com:10835,https://aws-us-east-1-portal11.dblayer.com:27265 -u root:*********' ~~~ ~~~bash etcdctl mk x 3 etcdctl mk y 123 etcdctl ls etcdctl get /y etcdctl set new 6 etcdctl set d/a 4 etcdctl set d/b 5 etcdctl ls d etcdctl rm --recursive d # TTL of 5 seconds etcdctl mk e 4 --ttl "5" ~~~ ~~~bash export ETCDCTL_API=3 export ETCDCTL_ENDPOINTS=$(minikube service example-etcd-cluster-client-service --url) ~~~ backup (cluster & local) Voir https://etcd.io/docs/v3.5/op-guide/recovery/ ~~~bash ETCDCTL_API=3 etcdctl --endpoints $ENDPOINT snapshot save snapshot.db #--cacert /etc/ssl/etcd/ca.crt --cert /etc/ssl/etcd/client.crt --key /etc/ssl/etcd/client.key ~~~ Verify the snapshot: ~~~bash ETCDCTL_API=3 etcdctl --write-out=table snapshot status snapshotdb ~~~ Restore (local) ~~~bash ETCDCTL_API=3 etcdctl snapshot restore snapshot.db ~~~ grpc-proxy ~~~bash etcd grpc-proxy start --endpoints=infra0.example.com,infra1.example.com,infra2.example.com --listen-addr=127.0.0.1:2379 ~~~ ## Tuning IO ~~~bash # best effort, highest priority sudo ionice -c2 -n0 -p `pgrep etcd` ~~~ CPU ~~~bash echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ~~~ ## Diag ~~~bash sudo chown -R etcd:etcd /var/lib/etcd sudo systemctl start etcd ~~~ List the cluster member: ~~~bash etcdctl --endpoints=http://${NODE1}:2379 member list ~~~ ## Client API Python https://www.dasblinkenlichten.com/python-pieces-working-with-etcd/ ## Autre ### pas de type list ? Voir https://github.com/ake-persson/etcdtool etcd doesn't support list's, this is handled by using the index as the key: JSON Input: ~~~javascript { "users": [ { "username": "jblack", "first_name": "John", "last_name": "Blackbeard" }, { "username": "ltrier", "first_name": "Lars", "last_name": "Von Trier" } ] } ~~~ Result in etcd: ~~~ users/0/username: jblack users/0/first_name: John users/0/last_name: Blackbeard users/1/username: ltrier users/1/first_name: Ludwig users/1/last_name: Von Treimer ~~~