Skip to content

Instantly share code, notes, and snippets.

@crazytaxii
Last active January 12, 2021 07:04
Show Gist options
  • Save crazytaxii/55e4a44f8bc11b487fd25cf45a5b2422 to your computer and use it in GitHub Desktop.
Save crazytaxii/55e4a44f8bc11b487fd25cf45a5b2422 to your computer and use it in GitHub Desktop.
Deploying local nfs service for testing.
#!/bin/bash
set -e
# Default settings
NFS_DATA_DEV=${NFS_DATA_DEV:-/dev/sdb}
NFS_DATA_DIR=${NFS_DATA_DIR:-/nfs/data}
install_dep() {
sudo yum install nfs-utils -y
}
mount_disk() {
mkdir -p $NFS_DATA_DIR
if [ "$(blkid $NFS_DATA_DEV -o value -s TYPE)" != "xfs" ]; then
mkfs.xfs $NFS_DATA_DEV -f
fi
if [ "$(findmnt $NFS_DATA_DEV -o TARGET) | tail -1" != "$NFS_DATA_DIR" ]; then
mount $NFS_DATA_DEV $NFS_DATA_DIR
fi
echo "$NFS_DATA_DEV $NFS_DATA_DIR xfs defaults 0 0" >> /etc/fstab
}
config() {
echo "$NFS_DATA_DIR *(rw,no_root_squash,sync)" > /etc/exports
exportfs -r
}
start_service() {
systemctl restart $1
systemctl enable $1
}
main() {
install_dep
mount_disk
config
start_service rpcbind
start_service nfs
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment