Commit 4d275c51 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Documenta, añade recursos de plugin Docker

Documenta diferentes tareas comunes y la preparación del plugin Docker
para integrar en entorno Docker, almacenando volúmenes dentro de
Seaweed.

Actualmente, se usa el plugin katharostech/docker-plugin_seaweedfs, del
que deriva el anteriormente documentado en #1. La novedad es que ahora
realizamos nosotros el compilado, por lo que la versión base no es un
problema que no podamos superar. Si en el futuro se compatibiliza
https://github.com/seaweedfs/seaweedfs-csi-driver con Swarm, se migrará
a este.

Incorpora versión estática del código fuente del plugin utilizado, para
que pueda volver a ser compilado en caso de que desaparezca el
repositorio de terceros que lo provee.

Fix #1.
parent 92fc8d4c
Loading
Loading
Loading
Loading
+152 −0
Original line number Diff line number Diff line
# SeaweedFS

Deployment of SeaweedFS, a distributed object store and file system

## Tareas comunes

### Cambio de replicación y rebalanceo de volúmenes

Ejecutar desde un nodo `volume`, por ejemplo:

```sh
weed shell -master swfs-master-1:9333,swfs-master-2:9333,swfs-master-3:9333

lock

# cambia ajuste de replicación por defecto
volume.configure.replication -replication=100

# aplica cambio de replicación
volume.fix.replication

# reparte equitativamente los volúmenes entre los nodos
volume.balance -force

unlock

exit
```

### Migración de store usado por filer

Ejecutar desde un nodo `filer`.

Primero, se guarda un backup del store actual:

```sh
weed shell -master swfs-master-1:9333,swfs-master-2:9333,swfs-master-3:9333 -filer 127.0.0.1:8888 -filerGroup filesystem

# fija directorio dentro de swfs desde el que guardar
fs.cd /

# genera fichero .meta con el backup del store
fs.meta.save

exit
```

Tras relanzar el servicio con el nuevo store, se carga el backup:

```sh
weed shell -master swfs-master-1:9333,swfs-master-2:9333,swfs-master-3:9333 -filer 127.0.0.1:8888 -filerGroup filesystem

# carga fichero de backup en el nuevo store
fs.meta.load 127.0.0.1:8888-*.meta

exit

# elimina fichero backup
rm 127.0.0.1:8888-*.meta
```

### Mantenimiento de store etcd (en desuso)

Ejecutar desde un nodo `etcd`:

```sh
# listar miembros del cluster con sus campos
etcdctl member list -w fields

# listar alarmas lanzadas
etcdctl alarm list

# comprobar estado del servicio local en detalle
etcdctl --write-out=table endpoint status

# capturar el número de la última revisión
rev=$(etcdctl --endpoints=:2379 endpoint status --write-out="json" | egrep -o '"revision":[0-9]*' | egrep -o '[0-9].*')

# compactar las revisiones anteriores a la capturada
etcdctl compact $rev

# desfragmentar el espacio tras la compactación
etcdctl defrag

# eliminar las alarmas para salir del modo mantenimiento
etcdctl alarm disarm
```

## Plugin de volúmenes Docker

### Compilación e instalación del plugin

Se ha hecho uso del plugin [katharostech/docker-plugin_seaweedfs](https://github.com/katharostech/docker-plugin_seaweedfs/tree/fb624481819998223bb2043171caaea1e29a4a7f), concretamente en el commit `fb62448` donde se utiliza seaweedfs en su versión `3.43`. Esto nos aporta mejoras en cuanto a compatibilidad y rendimiento, pero con la pega de que no se ha actualizado su versión compilada ([katharostech/seaweedfs-volume-plugin](https://registry.hub.docker.com/r/katharostech/seaweedfs-volume-plugin)) para su uso directo. Ya está disponible en [redmic/seaweedfs-volume-plugin](https://registry.hub.docker.com/r/redmic/seaweedfs-volume-plugin).

Por ello, se hace necesaria la descarga del repositorio (también está disponible una copia estática del commit `fb62448` en `plugins/seaweedfs-volume-plugin`), la compilación del plugin y la subida del resultado para su uso en las diferentes máquinas:

```sh
git clone https://github.com/katharostech/docker-plugin_seaweedfs.git
cd docker-plugin_seaweedfs
make clean rootfs

# si no se ha hecho antes, identificarse en DockerHub
docker login

docker plugin create redmic/seaweedfs-volume-plugin:v3.43 ./plugin
docker plugin push redmic/seaweedfs-volume-plugin:v3.43
docker plugin rm redmic/seaweedfs-volume-plugin:v3.43

docker plugin create redmic/seaweedfs-volume-plugin:latest ./plugin
docker plugin push redmic/seaweedfs-volume-plugin:latest
docker plugin rm redmic/seaweedfs-volume-plugin:latest

make clean
```

Luego, en cada nodo se puede instalar mediante:

```sh
docker plugin install --alias seaweedfs redmic/seaweedfs-volume-plugin:latest \
  HOST=localhost:8888 \
  REMOTE_PATH=/docker-volumes \
  MOUNT_OPTIONS="-volumeServerAccess=publicUrl -dataCenter=dc-$(docker node inspect -f '{{.ID}}' self) -cacheDir=/tmp -cacheCapacityMB=2048"
```

O si ya estaba instalado, pero se desea actualizar o cambiar a esta compilación:

```sh
docker plugin disable -f seaweedfs:latest

docker plugin upgrade --grant-all-permissions seaweedfs:latest redmic/seaweedfs-volume-plugin:latest

docker plugin enable seaweedfs:latest
```

### Configuración del plugin

Para ajustar la configuración del plugin cuando ya estaba funcionando:

```sh
docker plugin disable -f seaweedfs:latest

docker plugin set seaweedfs:latest \
  HOST=127.0.0.1:8888 \
  MOUNT_OPTIONS="..."

docker plugin enable seaweedfs:latest
```

Las variables disponibles son:

* `HOST`: Referencia al servicio `filer`, en este caso siempre ha de ser local.
* `MOUNT_OPTIONS`: Acepta cualquier parámetro de `weed mount`, ver su salida de ayuda para más información.
* `REMOTE_PATH`: Ruta raíz donde almacenar los volúmenes dentro de seaweedfs.
* `ROOT_VOLUME_NAME`: Nombre de volumen global con todo el contenido. Si se deja vacío no se genera.
* `LOG_LEVEL`: Nivel de salida de logs generados por el plugin. Consultar desde la máquina con `journalctl -f -n 100 -u docker`.
+3 −0
Original line number Diff line number Diff line
node_modules/
plugin/
.git/
+2 −0
Original line number Diff line number Diff line
node_modules/
plugin/
+53 −0
Original line number Diff line number Diff line
FROM node:10-alpine

####
# Install SeaweedFS Client
####

ARG SEAWEEDFS_VERSION=3.43
ENV SEAWEEDFS_VERSION=$SEAWEEDFS_VERSION
ARG GOARCH=amd64
ENV GOARCH=$GOARCH

RUN apk update && \
    apk add fuse3 && \
    apk add fuse && \
    apk add --no-cache --virtual build-dependencies --update wget curl ca-certificates && \
    wget -qO /tmp/linux_${GOARCH}.tar.gz https://github.com/chrislusf/seaweedfs/releases/download/${SEAWEEDFS_VERSION}/linux_${GOARCH}.tar.gz && \
    tar -C /usr/bin/ -xzvf /tmp/linux_${GOARCH}.tar.gz && \
    apk del build-dependencies && \
    rm -rf /tmp/*

####
# Install Docker volume driver API server
####

# Create directories for mounts
RUN mkdir -p /mnt/seaweedfs
RUN mkdir -p /mnt/docker-volumes

# Copy in package.json
COPY package.json package-lock.json /project/

# Switch to the project directory
WORKDIR /project

# Install project dependencies
RUN npm install

# Set Configuration Defaults
ENV HOST=filer \
    PORT=8888 \
    ALIAS=seaweedfs \
    ROOT_VOLUME_NAME="" \
    MOUNT_OPTIONS="" \
    REMOTE_PATH=/docker/volumes \
    LOCAL_PATH="" \
    CONNECT_TIMEOUT=10000 \
    LOG_LEVEL=info

# Copy in source code
COPY index.js /project

# Set the Docker entrypoint
ENTRYPOINT ["node", "index.js"]
+47 −0
Original line number Diff line number Diff line
The MIT License (MIT)

Copyright (c) 2018 Kadima Solutions

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


Makefile based on a Makefile for vieux/docker-volume-sshfs and is under the
following license.

The MIT License (MIT)

Copyright (c) 2015-2017 Victor Vieux

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading