#!/bin/bash
#安装utils,rpcbind
rpm -q rpcbind
if [ $? -eq 0 ];then
echo "rpcbind已安装"
else
echo "rpcbind未安装正在安装"
yum install -y rpcbind
echo "rpcbind安装成功"
fi
rpm -q nfs-utils
if [ $? -eq 0 ];then
echo "nfs-utils已经安装"
else "nfs-utils未安装,正在安装"
yum install -y nfs-utils
echo "nfs-utils安装成功"
fi
#设置共享目录
mkdir -p /opt/www
chmod 777 /opt/www
echo "/opt/www 192.168.239.0/24 (rw, sync,no_root_squash)" > /etc/exports
#启动nfs服务
systemctl restart rpcbind
systemctl enable rpcbind
systemctl restart nfs
systemctl enable nfs
echo "nfs各项服务已开启"
showmount -e 192.168.239.128 >> /dev/null
if [ $? -eq 0 ];then
echo "共享文件夹已存在"
else
echo "共享文件夹不存在,请检查"
fi
/usr/bin/expect <
expect {
"(yes/no)?"
{ send "yes\r"; exp_continue; }
"password:" {
send "123456\r"; }
"#"
{ send "mount 192.168.239.128:/opt/www/ /var/www/html\r"; }
{ send "echo "192.168.239.128:/opt/www /var/www/html nfs defaults,_netdev 0 0" >> /etc/fstab\r"; }
}
expect eof
EOF
#mount 192.168.239.128:/opt/www/ /var/www/html
#echo "192.168.239.128:/opt/www /var/www/html nfs defaults,_netdev 0 0" >> /etc/fstab