Skip to content

Instantly share code, notes, and snippets.

@nicc777
Last active May 7, 2022 13:46
Show Gist options
  • Save nicc777/6a033865aaa0e546aa3e702d2ba21dcd to your computer and use it in GitHub Desktop.
Save nicc777/6a033865aaa0e546aa3e702d2ba21dcd to your computer and use it in GitHub Desktop.
GlusterFS Cluster Using MultiPass
#!/bin/sh
HF=/etc/hosts
MP=/glusterfs-data
echo "Updating /etc/hosts"
IP1=$(multipass info glusterfs1 | grep IPv4 | awk '{print $2}')
IP2=$(multipass info glusterfs2 | grep IPv4 | awk '{print $2}')
sudo sed -i '/glusterfs1/d' $HF
sudo sed -i '/glusterfs2/d' $HF
echo "$IP1 glusterfs1" | sudo tee -a $HF
echo "$IP2 glusterfs1" | sudo tee -a $HF
cat $HF | grep glusterfs
sudo mount -t glusterfs glusterfs1:volume1 /glusterfs-data
echo "Ready"
#!/bin/sh
echo "Deleting any prior clusters"
multipass stop glusterfs1 glusterfs2 && multipass delete glusterfs1 glusterfs2 && multipass purge
echo "Creating cluster nodes"
for node in glusterfs1 glusterfs2 ;do
multipass launch -c 1 -m 1G -d 12G -n $node
done
echo "Network Fix"
IP1=$(multipass info glusterfs1 | grep IPv4 | awk '{print $2}')
IP2=$(multipass info glusterfs2 | grep IPv4 | awk '{print $2}')
multipass exec glusterfs1 -- bash -c "echo \"${IP1} glusterfs1\" | sudo tee -a /etc/hosts"
multipass exec glusterfs1 -- bash -c "echo \"${IP2} glusterfs2\" | sudo tee -a /etc/hosts"
multipass exec glusterfs2 -- bash -c "echo \"${IP1} glusterfs1\" | sudo tee -a /etc/hosts"
multipass exec glusterfs2 -- bash -c "echo \"${IP2} glusterfs2\" | sudo tee -a /etc/hosts"
for node in glusterfs1 glusterfs2 ;do
echo "Data Directory Prep on $node"
multipass exec $node -- bash -c "sudo mkdir /data"
multipass exec $node -- bash -c "sudo chmod 777 /data"
echo "Prep common steps on $node"
multipass exec $node -- bash -c "sudo DEBIAN_FRONTEND=noninteractive apt update"
multipass exec $node -- bash -c "sudo DEBIAN_FRONTEND=noninteractive apt install software-properties-common"
multipass exec $node -- bash -c "sudo DEBIAN_FRONTEND=noninteractive add-apt-repository -y ppa:gluster/glusterfs-7"
multipass exec $node -- bash -c "sudo DEBIAN_FRONTEND=noninteractive apt update"
echo "Installing Server on $node"
multipass exec $node -- bash -c "sudo DEBIAN_FRONTEND=noninteractive apt install -yq glusterfs-server"
echo "Starting the GlusterFS service on $node"
multipass exec $node -- bash -c "sudo systemctl enable glusterd.service"
multipass exec $node -- bash -c "sudo systemctl start glusterd.service"
done
echo "Peering setup"
multipass exec glusterfs1 -- bash -c "sudo gluster peer probe glusterfs2"
echo "Creating Cluster Volume"
multipass exec glusterfs1 -- bash -c "sudo gluster volume create volume1 replica 2 glusterfs1:/data glusterfs2:/data force"
multipass exec glusterfs1 -- bash -c "sudo gluster volume start volume1"
multipass exec glusterfs1 -- bash -c "sudo gluster volume status"
#!/bin/sh
multipass stop glusterfs1
multipass stop glusterfs2
multipass start glusterfs1
multipass start glusterfs2
IP1=$(multipass info glusterfs1 | grep IPv4 | awk '{print $2}')
IP2=$(multipass info glusterfs2 | grep IPv4 | awk '{print $2}')
multipass exec glusterfs1 -- bash -c "echo \"${IP1} glusterfs1\" | sudo tee -a /etc/hosts"
multipass exec glusterfs1 -- bash -c "echo \"${IP2} glusterfs2\" | sudo tee -a /etc/hosts"
multipass exec glusterfs2 -- bash -c "echo \"${IP1} glusterfs1\" | sudo tee -a /etc/hosts"
multipass exec glusterfs2 -- bash -c "echo \"${IP2} glusterfs2\" | sudo tee -a /etc/hosts"
for node in glusterfs1 glusterfs2 ;do
echo "Starting the GlusterFS service on $node"
multipass exec $node -- bash -c "sudo systemctl enable glusterd.service"
multipass exec $node -- bash -c "sudo systemctl start glusterd.service"
done
echo "Starting Cluster Volume"
multipass exec glusterfs1 -- bash -c "sudo gluster volume start volume1"
multipass exec glusterfs1 -- bash -c "sudo gluster volume status"
echo "GlusterFS cluster is Ready"
#!/bin/sh
echo "Stopping the volume - THIS IS AN INTERACTIVE COMMAND - PLEASE CONFIRM...."
multipass exec glusterfs1 -- bash -c "sudo gluster volume stop volume1"
multipass exec glusterfs1 -- bash -c "sudo gluster volume status"
for node in glusterfs1 glusterfs2 ;do
echo "Stopping and Disabling the GlusterFS service on $node"
multipass exec $node -- bash -c "sudo systemctl stop glusterd.service"
multipass exec $node -- bash -c "sudo systemctl disable glusterd.service"
multipass stop $node
done
echo "GlusterFS cluster Was Stopped"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment