Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JonTheNiceGuy/bcaf1ff7ee5d2a02f56c216134900954 to your computer and use it in GitHub Desktop.
Save JonTheNiceGuy/bcaf1ff7ee5d2a02f56c216134900954 to your computer and use it in GitHub Desktop.

Gluster Setup Scripts for Proxmox

Following my blog post about setting up a Proxmox cluster with GlusterFS, this script automates the settings needed for a gluster disk.

#!/bin/bash
DEBIAN_RELEASE="$(cat /etc/apt/sources.list.d/* | grep -E -o 'pve (\S+) ' | head -n 1 | awk '{print $2}')"
GLUSTER_RELEASE=11
HOSTNAME="$(hostnamectl hostname)"
mkdir -p /etc/apt/keyrings
wget "https://download.gluster.org/pub/gluster/glusterfs/$GLUSTER_RELEASE/rsa.pub" -O /etc/apt/keyrings/gluster.asc
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/gluster.asc] https://download.gluster.org/pub/gluster/glusterfs/$GLUSTER_RELEASE/LATEST/Debian/$DEBIAN_RELEASE/amd64/apt $DEBIAN_RELEASE main" > /etc/apt/sources.list.d/gluster.list
apt update
apt install -y glusterfs-server
cp /etc/glusterfs/glusterd.vol /etc/glusterfs/glusterd.vol.bak
cat <<-EOF >/etc/glusterfs/glusterd.vol
volume management
type mgmt/glusterd
option working-directory /var/lib/glusterd
option transport-type socket
option transport.tcp.bind-address $HOSTNAME
option transport.rdma.bind-address $HOSTNAME
option transport.socket.bind-address $HOSTNAME
option transport.socket.keepalive-time 10
option transport.socket.keepalive-interval 2
option transport.socket.read-fail-log off
option transport.socket.listen-port 24007
option ping-timeout 0
option event-threads 1
# option lock-timer 180
# option transport.address-family inet6
# option base-port 49152
option max-port 60999
end-volume
EOF
if [ "$(diff /etc/glusterfs/glusterd.vol /etc/glusterfs/glusterd.vol.bak | wc -l)" -eq 4 ]
then
systemctl enable --now glusterd
else
echo "The glusterd.vol file has differed more than expected from the glusterd.vol.bak. Please review" >&" >&2
echo "the differences before running \"systemctl enable --now glusterd\"" >&2
diff /etc/glusterfs/glusterd.vol /etc/glusterfs/glusterd.vol.bak >&2
exit 1
fi
#!/bin/bash
[ -z "$1" ] && echo "No volume specified" >&2 && exit 1
pvesm status | grep -q "$1" && echo "Mounted already" >&2 && exit 0
gluster volume info "$1" | grep -E 'Brick[0-9]+:' | awk '{print $2}' | cut -d: -f1 | head -n 2 | while read -r server
do
if [ -z "${SERVER1:-}" ]
then
SERVER1=$server
elif [ -z "${SERVER2:-}" ]
then
SERVER2=$server
fi
done
if [ -n "${SERVER1:-}" ] && [ -n "${SERVER2:-}" ]
then
pvesm add glusterfs "$1" --server "$SERVER1" --server2 "$SERVER2" --volume "$1" --content backup,images,iso,snippets,vztmpl
else
echo "The two servers were not listed in the bricks area. 1: '${SERVER1:-}' 2: '${SERVER2:-}'"
fi
#!/bin/bash
TEMP_DATA_PATH="$(mktemp -d)"
export STATUS_FILE="$TEMP_DATA_PATH/info"
export CONFIG_FILE="$TEMP_DATA_PATH/settings"
trap cleanup SIGINT SIGTERM EXIT
cleanup() {
trap - SIGINT SIGTERM EXIT
rm -Rf "${TEMP_DATA_PATH}"
}
set_vol() {
volume="$1"
key="$2"
value="$3"
grep -q -E "^$key\s+$value\s+" "$CONFIG_FILE" || gluster volume set "$volume" "$key" "$value"
}
[ -z "$1" ] && echo "No disk specified" >&2 && exit 1
if gluster volume info "$1" > "$STATUS_FILE"
then
grep -q "Status: Started" "$STATUS_FILE" || gluster volume start "$1"
gluster volume get "$1" all > "$CONFIG_FILE"
set_vol "$1" cluster.heal-timeout 5
set_vol "$1" cluster.quorum-reads false
set_vol "$1" cluster.quorum-count 1
set_vol "$1" network.ping-timeout 2
set_vol "$1" cluster.favorite-child-policy mtime
set_vol "$1" cluster.data-self-heal-algorithm full
if gluster volume heal "$1" info > "$CONFIG_FILE"
then
gluster volume heal "$1" enable
gluster volume heal "$1" granular-entry-heal enable
fi
else
echo "Invalid volume" >&2 && exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment