百度推广网站可以链接到同公司另一个网站吗/广州白云区今天的消息
@[toc]shell编程笔记2-ns挂载
shell编程笔记2–ns挂载
NFS简介
NFS就是Network File System的缩写,它最大的功能就是可以通过网络,让不同的机器、不同的操作系统可以共享彼此的文件。NFS服务器可以让PC将网络中的NFS服务器共享的目录挂载到本地端的文件系统中,而在本地端的系统中来看,那个远程主机的目录就好像是自己的一个磁盘分区一样,在使用上相当便利.由於在工作中非常實用,此處將其寫成了兩個腳本,以便於後續使用時候查看.
服务|客户端shell脚本
服務端:
服務端將對應內容寫到/etc/exports中,並重啓nfs-kernel-server即可;
#!/bin/bashusage()
{echo "usage:$0 usable_ip share_pathbash nfs_mount.sh 127.0.0.1 /home/user/dir1"
}main()
{# back up fstabuser=xgBAKCUP=/home/$user/backup/nfsif [ ! -d $BAKCUP ];thensudo mkdir -p $BAKCUPficp /etc/exports ${BAKCUP}/exports.$(date +'%Y%m%d%H%M')# prepare dirif [ ! -d $2 ];thensudo mkdir -p $2fisudo touch $2/nfs-test.txt# install nfs-commondpkg -l | grep nfsif [ $? -ne 0 ];thenapt-get install -y nfs*if [ $? -ne 0 ];thenecho "install nfs* failed!"exit 1fifidpkg -l | grep rpcbindif [ $? -ne 0 ];thensudo apt-get install -y rpcbindif [ $? -ne 0 ];thenecho "install rpcbind failed!"exit 1fifi#mount_strcat /etc/exports | grep $2if [ $? -ne 0 ];thenmount_str=$2' '$1'(rw,sync,no_subtree_check)'sudo echo $mount_str >> /etc/exportsfi# check if mount successsudo service nfs-kernel-server restart
}main $1 $2
客戶端:
將相應內容寫到/etc/fstab中,並mount即可;
#!/bin/bash# author: xg
# email :
# function: nfs客户端挂载
# date: 2019-09-29 18:30usage()
{echo "usage:$0 nfs_server_ip share_path local_pathbash nfs_mount.sh ip /home/user/dir1 /home/user/dir2"
}main()
{# back up fstabuser=xgBAKCUP=/home/$user/backup/nfsif [ ! -d $BAKCUP ];thensudo mkdir -p $BAKCUPficp /etc/fstab ${BAKCUP}/fstab.$(date +'%Y%m%d%H%M')# install nfs-commondpkg -l | grep nfs-commonif [ $? -ne 0 ];thensudo apt-get install -y nfs-commonif [ $? -ne 0 ];thenecho "install nfs-common failed!"exit 1fifi# append to /etc/fstabcat /etc/fstab |grep $1if [ $? -ne 0 ];thenmount_str=$1:$2' '$3' nfs rw,async,vers=3,rsize=524288,wsize=524288,acdirmin=5,acdirmax=8,hard,proto=tcp 0 0'sudo /bin/bash -c "/bin/echo $mount_str >> /etc/fstab" fi# mkidr $3if [ ! -d $3 ];thensudo mkdir $3fi# mount -asudo mount -aif [ $? -ne 0 ];thenecho "mount -a error!"exit 1fi# check if mount successdf -h $2if [ $? -ne 0 ];thenecho "df -h failed!"exit 1fi
}main $1 $2 $3
说明
测试系统版本: Ubuntu 19.10 Desktop (64-bit)