Ricerca nel sito web

Come installare e configurare il cluster SeaweedFS su Ubuntu 20.04


Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa SeaweedFS
  4. Crea un file di servizio Systemd per Master
  5. Crea e avvia i server di volume
  6. Scrivi un file di esempio nel volume
  7. Accedi a SeaweedFS
  8. Conclusione

SeaweedFS è un file system distribuito open source, semplice e altamente scalabile per archiviare e servire miliardi di file velocemente. È molto simile ad altri file system tra cui Ceph, GlusterFS e HDFS. Può essere facilmente integrato con il cloud e ottenere tempi di accesso rapidi senza alcuna modifica lato client. Ha un ricco set di funzionalità tra cui, failover automatico dei server master, scadenza TTL con ingresso automatico, elaborazione parallela, gestione di file grandi e piccoli, accesso a bassa latenza a qualsiasi file e molto altro.

In questo tutorial, ti mostreremo come configurare il cluster SeaweedFS sul server Ubuntu 20.04.

Prerequisiti

  • Un server che esegue il server Ubuntu 20.04.
  • Sul server è configurata una password di root.

Iniziare

Prima di iniziare, si consiglia di aggiornare i pacchetti di sistema all'ultima versione. Puoi aggiornarli con il seguente comando:

apt-get update -y

Una volta aggiornati tutti i pacchetti, dovrai installare alcune altre dipendenze richieste nel tuo server. Puoi installarli tutti eseguendo il seguente comando:

apt-get install build-essential autoconf automake gdb git libffi-dev zlib1g-dev libssl-dev unzip -y

Dopo aver installato tutte le dipendenze, devi anche installare Golang nel tuo sistema. Puoi installarlo con il seguente comando:

apt-get install golang -y

Una volta completata l'installazione, puoi procedere al passaggio successivo.

Installa SeaweedFS

Per impostazione predefinita, SeaweedFS non è disponibile nel repository predefinito di Ubuntu 20.04. Quindi dovrai scaricarlo e compilarlo dalla fonte.

Innanzitutto, scarica l'ultima versione di SeaweedFS dal repository Git usando il seguente comando:

git clone https://github.com/chrislusf/seaweedfs.git

Una volta completato il download, cambia la directory in SeaweedFS e installala con il seguente comando:

cd ~/seaweedfs
make install

Il comando sopra installerà il binario SeaweedFS all'interno della directory ~/go/bin/. Ora, copia il file binario installato nella directory /usr/loca/bin con il seguente comando:

cp ~/go/bin/weed /usr/local/bin/

Successivamente, verifica la versione installata di SeaweedFS con il seguente comando:

weed version

Dovresti ottenere il seguente output:

version 30GB 2.14 4211601e linux amd64

Una volta terminato, puoi procedere al passaggio successivo.

Crea un file di servizio Systemd per Master

Innanzitutto, dovrai creare un file di servizio systemd per gestire il servizio SeaweedFS. Puoi crearlo eseguendo il seguente comando:

nano /etc/systemd/system/seaweedmaster.service

Aggiungi le seguenti righe:

[Unit]
Description=SeaweedFS Master
After=network.target

[Service]
Type=simple
User=root
Group=root

ExecStart=/usr/local/bin/weed master
WorkingDirectory=/usr/local/bin/
SyslogIdentifier=seaweedfs-master

[Install]
WantedBy=multi-user.target

Salva e chiudi il file, quindi ricarica il demone systemd con il seguente comando:

systemctl daemon-reload

Successivamente, avvia il servizio SeaweedFS e abilitalo per l'avvio al riavvio del sistema con il seguente comando:

systemctl start seaweedmaster
systemctl enable seaweedmaster

Puoi verificare lo stato del master SeaweedFS con il seguente comando:

systemctl status seaweedmaster

Dovresti ottenere il seguente output:

? seaweedmaster.service - SeaweedFS Master
     Loaded: loaded (/etc/systemd/system/seaweedmaster.service; disabled; vendor preset: enabled)
     Active: active (running) since Wed 2020-12-09 08:30:06 UTC; 3s ago
   Main PID: 25740 (weed)
      Tasks: 10 (limit: 4691)
     Memory: 8.0M
     CGroup: /system.slice/seaweedmaster.service
             ??25740 /usr/local/bin/weed master

Dec 09 08:30:06 ubunt4 seaweedfs-master[25740]: I1209 08:30:06 25740 master_server.go:107] Volume Size Limit is 30000 MB
Dec 09 08:30:06 ubunt4 seaweedfs-master[25740]: I1209 08:30:06 25740 master_server.go:192] adminScripts:
Dec 09 08:30:06 ubunt4 seaweedfs-master[25740]: I1209 08:30:06 25740 master.go:122] Start Seaweed Master 30GB 2.14 4211601e at 0.0.0.0:9333
Dec 09 08:30:06 ubunt4 seaweedfs-master[25740]: I1209 08:30:06 25740 raft_server.go:70] Starting RaftServer with 69.87.216.36:9333
Dec 09 08:30:06 ubunt4 seaweedfs-master[25740]: I1209 08:30:06 25740 raft_server.go:129] current cluster leader:
Dec 09 08:30:06 ubunt4 seaweedfs-master[25740]: I1209 08:30:06 25740 master.go:146] Start Seaweed Master 30GB 2.14 4211601e grpc server at>
Dec 09 08:30:08 ubunt4 seaweedfs-master[25740]: I1209 08:30:08 25740 masterclient.go:78] No existing leader found!
Dec 09 08:30:08 ubunt4 seaweedfs-master[25740]: I1209 08:30:08 25740 raft_server.go:154] Initializing new cluster
Dec 09 08:30:08 ubunt4 seaweedfs-master[25740]: I1209 08:30:08 25740 master_server.go:141] leader change event:  => 69.87.216.36:9333
Dec 09 08:30:08 ubunt4 seaweedfs-master[25740]: I1209 08:30:08 25740 master_server.go:143] [ 69.87.216.36:9333 ] 69.87.216.36:9333 becomes>

Una volta terminato, puoi procedere al passaggio successivo.

Creare e avviare i server di volume

A questo punto, il server master è avviato e attende i volumi. Innanzitutto, crea una directory di due volumi con il seguente comando:

mkdir /mnt/{vol1,vol2}

Successivamente, crea un file di servizio systemd per gestire il Volume1 con il seguente comando:

nano /etc/systemd/system/seaweedvolume1.service

Aggiungi le seguenti righe:

[Unit]
Description=SeaweedFS Volume
After=network.target

[Service]
Type=simple
User=root
Group=root

ExecStart=/usr/local/bin/weed volume -dir="/mnt/vol1" -max=10 -mserver="69.87.216.36:9333" -port=8081
WorkingDirectory=/usr/local/bin/
SyslogIdentifier=seaweedfs-volume

[Install]
WantedBy=multi-user.target

Salva e chiudi il file, quindi ricarica il demone systemd con il seguente comando:

systemctl daemon-reload

Successivamente, avvia il servizio Volume1 e abilitalo per l'avvio al riavvio del sistema:

systemctl start seaweedvolume1.service
systemctl enable seaweedvolume1.service

Puoi verificare lo stato del servizio Volume1 con il seguente comando:

systemctl status seaweedvolume1

Dovresti ottenere il seguente output:

? seaweedvolume1.service - SeaweedFS Volume
     Loaded: loaded (/etc/systemd/system/seaweedvolume1.service; disabled; vendor preset: enabled)
     Active: active (running) since Wed 2020-12-09 08:31:14 UTC; 4s ago
   Main PID: 25870 (weed)
      Tasks: 9 (limit: 4691)
     Memory: 7.3M
     CGroup: /system.slice/seaweedvolume1.service
             ??25870 /usr/local/bin/weed volume -dir=/mnt/vol1 -max=10 -mserver=69.87.216.36:9333 -port=8081

Dec 09 08:31:14 ubunt4 systemd[1]: Started SeaweedFS Volume.
Dec 09 08:31:14 ubunt4 seaweedfs-volume[25870]: I1209 08:31:14 25870 file_util.go:23] Folder /mnt/vol1 Permission: -rwxr-xr-x
Dec 09 08:31:14 ubunt4 seaweedfs-volume[25870]: I1209 08:31:14 25870 disk_location.go:154] Store started on dir: /mnt/vol1 with 0 volumes >
Dec 09 08:31:14 ubunt4 seaweedfs-volume[25870]: I1209 08:31:14 25870 disk_location.go:157] Store started on dir: /mnt/vol1 with 0 ec shards
Dec 09 08:31:14 ubunt4 seaweedfs-volume[25870]: I1209 08:31:14 25870 volume_grpc_client_to_master.go:52] Volume server start with seed mas>
Dec 09 08:31:14 ubunt4 seaweedfs-volume[25870]: I1209 08:31:14 25870 volume.go:334] Start Seaweed volume server 30GB 2.14 4211601e at 0.0.>
Dec 09 08:31:14 ubunt4 seaweedfs-volume[25870]: I1209 08:31:14 25870 volume_grpc_client_to_master.go:114] Heartbeat to: 69.87.216.36:9333

Quindi, crea un file di servizio systemd per Volume2 con il seguente comando:

nano /etc/systemd/system/seaweedvolume2.service

Aggiungi le seguenti righe:

[Unit]
Description=SeaweedFS Volume
After=network.target

[Service]
Type=simple
User=root
Group=root

ExecStart=/usr/local/bin/weed volume -dir="/mnt/vol2" -max=5  -mserver="69.87.216.36:9333" -port=8080
WorkingDirectory=/usr/local/bin/
SyslogIdentifier=seaweedfs-volume2

[Install]
WantedBy=multi-user.target

Salva e chiudi il file, quindi ricarica il demone systemd con il seguente comando:

systemctl daemon-reload

Successivamente, avvia il servizio Volume2 e abilitalo per l'avvio al riavvio del sistema:

systemctl start seaweedvolume2.service
systemctl enable seaweedvolume2.service

Puoi verificare lo stato del servizio Volume2 con il seguente comando:

systemctl status seaweedvolume2

Dovresti ottenere il seguente output:

? seaweedvolume2.service - SeaweedFS Volume
     Loaded: loaded (/etc/systemd/system/seaweedvolume2.service; disabled; vendor preset: enabled)
     Active: active (running) since Wed 2020-12-09 08:32:03 UTC; 4s ago
   Main PID: 25921 (weed)
      Tasks: 10 (limit: 4691)
     Memory: 7.7M
     CGroup: /system.slice/seaweedvolume2.service
             ??25921 /usr/local/bin/weed volume -dir=/mnt/vol2 -max=5 -mserver=69.87.216.36:9333 -port=8080

Dec 09 08:32:03 ubunt4 systemd[1]: Started SeaweedFS Volume.
Dec 09 08:32:03 ubunt4 seaweedfs-volume2[25921]: I1209 08:32:03 25921 file_util.go:23] Folder /mnt/vol2 Permission: -rwxr-xr-x
Dec 09 08:32:03 ubunt4 seaweedfs-volume2[25921]: I1209 08:32:03 25921 disk_location.go:154] Store started on dir: /mnt/vol2 with 0 volumes>
Dec 09 08:32:03 ubunt4 seaweedfs-volume2[25921]: I1209 08:32:03 25921 disk_location.go:157] Store started on dir: /mnt/vol2 with 0 ec shar>
Dec 09 08:32:03 ubunt4 seaweedfs-volume2[25921]: I1209 08:32:03 25921 volume.go:334] Start Seaweed volume server 30GB 2.14 4211601e at 0.0>
Dec 09 08:32:03 ubunt4 seaweedfs-volume2[25921]: I1209 08:32:03 25921 volume_grpc_client_to_master.go:52] Volume server start with seed ma>
Dec 09 08:32:03 ubunt4 seaweedfs-volume2[25921]: I1209 08:32:03 25921 volume_grpc_client_to_master.go:114] Heartbeat to: 69.87.216.36:9333

Una volta terminato, puoi procedere al passaggio successivo.

Scrivi un file di esempio nel volume

Innanzitutto, dovrai inviare una richiesta HTTP POST, PUT o GET per ottenere un ID file e un URL del server del volume. Puoi farlo con il seguente comando:

curl http://localhost:9333/dir/assign

Dovresti vedere l'ID file e l'URL del server del volume nel seguente output:

{"fid":"7,016bad1bc0","url":"69.87.216.36:8080","publicUrl":"69.87.216.36:8080","count":1}

Successivamente, aggiungi un file di esempio denominato file1.png al volume utilizzando l'ID file e l'URL del volume come mostrato di seguito:

curl -F /root/file1.png http://69.87.216.36:8080/7,016bad1bc0

Dovresti ottenere il seguente output:

{"name":"file1.png","size":74912,"eTag":"7a6511cbeda98ca00346544ca2968046"}

Dopo aver caricato il file sul volume, puoi leggerlo con il seguente comando:

curl http://69.87.216.36:9333/dir/lookup?volumeId=7

Dovresti ottenere il seguente output:

{"volumeId":"7","locations":[{"url":"69.87.216.36:8080","publicUrl":"69.87.216.36:8080"}]}

Una volta terminato, puoi procedere al passaggio successivo.

Accedi a SeaweedFS

È ora possibile accedere a SeaweedFS utilizzando l'URL http://your-server-ip:8080/7,016bad1bc0 per visualizzare il file archiviato nell'object store SeaweedFS:

Puoi vedere il tuo file che hai caricato in precedenza nella schermata sopra.

Conclusione

Congratulazioni! hai installato e configurato correttamente il cluster SeaweedFS sul server Ubuntu 20.04. Per ulteriori informazioni, visita la pagina della documentazione di SeaweedFS. Non esitate a chiedermi se avete domande.