MODOP – Cluster IPFS RAID1 – déploiement d’un peers au Cluster via Script Bash – Partie 4

1. Inventaire du nouveaux peer

Hostname

  • Node-ipfsp4 : IP = 192.168.1.74 (peer)

HDD

  • Disque SCSI0 : Système
  • Disque SCSI1 & SCSI2 : RAID1

2. Installation des prérequis

##### CONFIGURATION #####

HOSTNAME="node-ipfsp4"
DEVICE1="/dev/sdb"
DEVICE2="/dev/sdc"
DEVICERAID="/dev/md0"
MOUNT_POINT="/mnt/ipfs-data"
IPHOST="192.168.1.74"

echo "#################################"
echo " Prérequis client peer "
echo "#################################"

echo "##### 1 - Set Hostname #####"
hostnamectl hostname ${HOSTNAME}
hostnamectl

echo "##### 2 - Update Machine #####"
dnf -y update

echo "##### 3 - Desactiver SELinux #####"
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

echo "##### 4 - NTP Client #####"
timedatectl set-timezone Europe/Paris
timedatectl

echo "##### 5 - Installer paquet utils #####"
dnf install epel-release net-tools nmap wget tar git –y

3. Installation du RAID1

echo "#################################"
echo " Installation du RAID1 "
echo "#################################"

echo "#### 1 - Prédisposition du RAID Logiciel #####"
dnf -y install mdadm

echo "modprobe linear" >> /etc/rc.local
echo "modprobe raid1" >> /etc/rc.local
chmod +x /etc/rc.local
source /etc/rc.local
cat /proc/mdstat

echo "##### 2 - Partitionnement des disques en mode RAID #####"
parted -s ${DEVICE1} mklabel msdos
parted -s ${DEVICE2} mklabel msdos

parted -s ${DEVICE1} mkpart primary 1MiB 100%
parted -s ${DEVICE2} mkpart primary 1MiB 100%

parted -s ${DEVICE1} set 1 raid on
parted -s ${DEVICE2} set 1 raid on

echo "#### 3 - Création du RAID1 #####"
yes | mdadm --create ${DEVICERAID} --level=1 --raid-devices=2 ${DEVICE1}1 ${DEVICE2}1

while grep -qE 'resync|recovery' /proc/mdstat; do
 cat /proc/mdstat
 sleep 20
done

echo "#### 4 - Préparation du volume RAID"
mkfs.ext4 ${DEVICERAID}
mkdir -p ${MOUNT_POINT}

echo "/dev/md0 /mnt/ipfs-data ext4 defaults 0 2" >> /etc/fstab
systemctl daemon-reload
mount -a
df -Th |grep ipfs

4. Installation des règles Firewall

echo "###################################"
echo " Installation des règles Firewall "
echo "###################################"

firewall-cmd --add-port={4001,5001,9094,9095,9096,8080}/tcp --permanent
firewall-cmd --add-port=4001/udp --permanent
firewall-cmd --remove-service={cockpit,dhcpv6-client} --permanent
firewall-cmd --reload
firewall-cmd --list-all

5. Installation des middleware IPFS et Cluster

echo "###################################"
echo " Installation Middleware IPFS "
echo "###################################"

echo "#### 1 - Installation langage GO #####"
cd /home && wget https://go.dev/dl/go1.24.4.linux-amd64.tar.gz
cd /home && tar -xvf go1.24.4.linux-amd64.tar.gz && mv go /usr/local
mkdir $HOME/gopath

echo "export GOROOT=/usr/local/go" >> $HOME/.bashrc
echo "export GOPATH=$HOME/gopath" >> $HOME/.bashrc
sed -i 's/export PATH/#export PATH/g' $HOME/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> $HOME/.bashrc
source $HOME/.bashrc

echo ""
echo "#####################"
go version
echo "#####################"
sleep 1
clear

echo "##### 2 - Installation Go-ipfs KUBO #####"
cd /home && wget https://dist.ipfs.tech/kubo/v0.35.0/kubo_v0.35.0_linux-amd64.tar.gz
cd /home && tar -xzvf kubo_v0.35.0_linux-amd64.tar.gz kubo/
cd /home/kubo && bash install.sh

echo ""
echo "#####################"
ipfs --version
echo "#####################"
sleep 1
clear

echo "##### 3 - Installation ipfs Cluster service #####"
cd /home && wget https://dist.ipfs.tech/ipfs-cluster-service/v1.1.4/ipfs-cluster-service_v1.1.4_linux-amd64.tar.gz
cd /home && tar -xzvf ipfs-cluster-service_v1.1.4_linux-amd64.tar.gz ipfs-cluster-service/
cd /home && mv ipfs-cluster-service/ipfs-cluster-service /usr/local/bin/

echo ""
echo "#####################"
ipfs-cluster-service --version
echo "#####################"
sleep 1
clear

echo "##### 4 - Installation ipfs cluster ctl #####"
cd /home && wget https://dist.ipfs.tech/ipfs-cluster-ctl/v1.1.4/ipfs-cluster-ctl_v1.1.4_linux-amd64.tar.gz
cd /home && tar -xzvf ipfs-cluster-ctl_v1.1.4_linux-amd64.tar.gz ipfs-cluster-ctl/
cd /home && mv ipfs-cluster-ctl/ipfs-cluster-ctl /usr/local/bin/

echo ""
echo "#####################"
ipfs-cluster-ctl --version
echo "#####################"
sleep 1
clear 

echo "##### 5 - Installation des variables ENV ipfs ####"
echo "export IPFS_PATH=/mnt/ipfs-data/ipfs" >> $HOME/.bashrc
echo "export IPFS_CLUSTER_PATH=/mnt/ipfs-data/ipfs-cluster" >> $HOME/.bashrc
echo "export LIBP2P_FORCE_PNET=1" >> $HOME/.bashrc
source $HOME/.bashrc

6. Initialisation et service IPFS Kubo

echo "#######################################"
echo " Initialisation et service IPFS Peer "
echo "#######################################"

echo "#### 1 - Initialisation du Peer #####"
ipfs init

echo "#### 2 - Paramètrage du peer #####"
ipfs config --json Datastore.StorageMax '"40GB"'
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://'${IPHOST}':5001", "http://localhost:3000", "http://127.0.0.1:5001", "https://'${HOSTNAME}'.house.cp"]'

echo "#### 3 - Paramétrage mode Privé #####"
cat <<EOF > /mnt/ipfs-data/ipfs/swarm.key
/key/swarm/psk/1.0.0/
/base16/
1c77bfd716e3d5811049260f3aaedcdcadf0997113b02dbddc1ecab3308b15ac
EOF

ipfs bootstrap rm --all
ipfs config Routing.Type dht
ipfs config --json AutoTLS.Enabled false
ipfs config --json Swarm.Transports.Network.WebTransport false
ipfs config --json Swarm.Transports.Network '{"TCP": true, "QUIC": false, "Websocket": false, "Relay": false, "WebTransport": false, "WebRTCDirect": false}'

echo "#### 4 - Service ipfs peer ####"
cat <<EOF > /etc/systemd/system/ipfs-peer.service
[Unit]
Description=IPFS Node (Pair – stockage RAID1)
After=network.target

[Service]
User=root
Environment="IPFS_PATH=/mnt/ipfs-data/ipfs"
ExecStart=/usr/local/bin/ipfs daemon
Restart=on-failure
LimitNOFILE=10240

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reexec && systemctl daemon-reload
systemctl enable ipfs-peer.service && systemctl restart ipfs-peer.service
systemctl status ipfs-peer.service

7. Initialisation et service IPFS Cluster

echo "###################################"
echo " Installation du cluster IPFS "
echo "#################################i##"

echo "##### 1 - Initialisation du Cluster sur la machine ######"
ipfs-cluster-service init

echo "##### 2 - Ajout de la clef privée du cluster #####"
sed -i 's/\"secret\": \".*\"/\"secret\": \"9dc28eb1c943ec508cc9f5a8b4c4726a5398be979c62521dd93252d62cb72196\"/' /mnt/ipfs-data/ipfs-cluster/service.json

echo "##### 3 - Service ipfs Cluster ####"
cat <<EOF > /etc/systemd/system/ipfs-cluster-peer.service
[Unit]
Description=IPFS Cluster Peer Service
After=network.target

[Service]
User=root
Group=root
Environment=IPFS_CLUSTER_PATH=/mnt/ipfs-data/ipfs-cluster
ExecStart=/usr/local/bin/ipfs-cluster-service daemon --bootstrap /ip4/192.168.1.70/tcp/9096/p2p/12D3KooWALCus4V2sFQmK8ZtLeSsBvxsE9GeUpdv4jJvwC3qPpAD
WorkingDirectory=/mnt/ipfs-data/ipfs-cluster
Restart=always
RestartSec=10
LimitNOFILE=10240

[Install]
WantedBy=multi-user.target
EOF

echo "##### 4 - Ouverture des accès web API 9094 ####"
sed -i 's|"/ip4/127.0.0.1/tcp/9094"|"/ip4/0.0.0.0/tcp/9094"|' /mnt/ipfs-data/ipfs-cluster/service.json

echo "##### 5 - OUverture des accès Web URL 8080 #####"
sed -i 's|"/ip4/127.0.0.1/tcp/8080"|"/ip4/0.0.0.0/tcp/8080"|' /mnt/ipfs-data/ipfs/config

echo "##### 6 - Démarrage de l'ensembl des service IPS et IPS Cluster #####"
systemctl stop ipfs-peer && systemctl start ipfs-peer
systemctl daemon-reexec && systemctl daemon-reload
systemctl enable ipfs-cluster-peer.service && systemctl start ipfs-cluster-peer.service
sleep 6

echo "##### 7 - Check des connexions clientes et Cluster #####"

echo ""
echo "########### Liste des Noeuds du Cluster ############################"
ipfs-cluster-ctl peers ls |grep "192.168.1.7"

echo ""
echo "########## Liste des Noeuds attaché au peer client ################"
ipfs swarm peers

8. Résultat du script

Liste les nœuds du cluster IPFS

[root@node-ipfsp4 ~]# ipfs-cluster-ctl peers ls |grep "192.168.1.7"

Liste les nœuds connectés sur le peer n°4

[root@node-ipfsp4 ~]# ipfs swarm peers

Accès du fichier «Bob_l_eponge.jpg » répliqué précédemment

Views: 1

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *