作者:张华 发表于:2021-08-28
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明
(http://blog.csdn.net/quqi99 )
刚工作需要做了一个nfs v3的测试,记录一下。
# set up nfs v3 server
sudo apt-get install nfs-kernel-server -y
cat <<EOF | sudo tee -a /etc/exports
/nfs *(rw,sync,no_subtree_check)
EOF
sudo mkdir -p /nfs && sudo chown -R $USER /nfs/
sudo systemctl restart nfs-server# set up nfs client
showmount -e node1
sudo mkdir -p /mnt/nfs && sudo chown -R $USER /mnt/nfs/
sudo mount -t nfs -o vers=3,proto=tcp,nolock node1:/nfs /mnt/nfs# prepare backing file
mkdir -p /nfs/images && sudo cp -v /images/kvm/bionic.qcow2 /nfs/images/
chmod 777 /nfs/image/bionic.qcow2# create two snapshots on the same backing file hosted in NFSv3 server
qemu-img create -f qcow2 -o backing_file=/mnt/nfs/image2/bionic.qcow2 /mnt/nfs/image2/bionic-snap.qcow2
chmod 777 /mnt/nfs/image2/bionic-snap.qcow2
qemu-img create -f qcow2 -o backing_file=/mnt/nfs/image2/bionic.qcow2 /mnt/nfs/image2/bionic-snap2.qcow2
chmod 777 /mnt/nfs/image2/bionic-snap2.qcow2# create two test VMs with two snapshots# run dd command on one VM, then restart another VM, but my both VMs run well so I didn't reproduce the problem.do test with sparse file test with: dd if=/dev/zero of=flat2.img bs=1024k count=0 seek=2048do test with non-sparse file test with: dd if=/dev/zero of=flat1.img bs=1024k count=1000
20210904更新 - 安装samba
买了个老母鸡(星客云),安装了armbian, 但运行nfs有问题(无法启动nfs-idmapd)
nfs-idmapd.service: Job nfs-idmapd.service/start failed with result 'dependency'
尝试了很多方法无法解决,还是换成samba吧(在windows上直接设置共享文件夹即可,但这里是linux).
安装配置samba服务端如下:
sudo apt install samba samba-common
sudo chmod 777 /mnt/sda4# modify smb.conf
root@OneCloud:~# grep -r 'security' /etc/samba/smb.conf -B1max log size = 1000security = user
root@OneCloud:~# cat /etc/samba/smb.conf |tail -n5[global]
read raw = Yes
write raw = Yes
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072
min receivefile size = 16384
use sendfile = true
aio read size = 16384
aio write size = 16384
max xmit = 65535
max connections = 0
deadtime = 0[share]comment = sda4path = /mnt/sda4browseable = yeswriteable = yesfollow symlinks = nowide links = noaio read size = 16384aio write size = 16384aio write behind = truewrite cache size = 2097152max xmit = 65536large readwrite = yestestparm
useradd hua
# use '-a' to avoid 'Failed to find entry for user root'
smbpasswd -a hua
systemctl restart smbd
配置samba客户端
# sudo mount -t cifs -o username=hua,password=password //storage/share /mnt/tmp/
# autofs
#/mnt/share -fstype=cifs,rw,username=nfs,password=password,file_mode=0777,dir_mode=0777 ://win/share
mnt/share -fstype=cifs,rw,username=hua,password=password,rw,rsize=61568,uid=1000,forceuid,gid=1000,forcegid,nounix,file_mode=0777,dir_mode=0777 ://storage/share
对于openwrt上的samba在client中映射出来的用户总是root (即使openwrt端不用root改用hua也是一样的), 在mount命令中添加’uid=1000,forceuid,gid=1000,forcegid’可映射到hua,但对autofs没效,后来发现原来是要添加nounix
opkg install shadow-common && opkg install shadow-useradd
# # use '-a' to avoid 'Failed to find entry for user root'
useradd hua && touch /etc/samba/smbpasswd && smbpasswd -a huasudo mount -t cifs -o username=hua,password=password,uid=$(id -u),gid=$(id -g),forceuid,forcegid //192.168.99.190/share /mnt/share# autofs
mnt/share -fstype=cifs,rw,username=hua,password=password,rw,rsize=61568,uid=1000,forceuid,gid=1000,forcegid,nounix,file_mode=0777,dir_mode=0777 ://xiaoyu/share
20220331 - openwrt上运行samba
今天将samba server从armbian移到了openwrt上(samba4体积太大,所以安装samba3.6), 但之后连接它时出错.于是开始调试它.
之前用useradd定义了一个hua用户,并且使用smbpasswd给它设置了一个密码:
opkg install shadow-common && opkg install shadow-useradd && opkg install shadow-groupmod
useradd hua && touch /etc/samba/smbpasswd
# use '-a' to avoid 'Failed to find entry for user root'
smbpasswd -a hua && groupmod -n smbgroups hua
发现可以运行:
smbclient -L //xiaoyu -U hua%password
但是不能运行:
# tree connect failed: NT_STATUS_ACCESS_DENIED
smbclient //xiaoyu/share -U hua%password -c "ls"
发现只能用root用户(server端记得将invalid users = root注释掉):
# use '-a' to avoid 'Failed to find entry for user root'
smbpasswd -a root
smbclient //xiaoyu/share -U root%password -c "ls"
之后发现仍然不能运行:
mount.cifs -o username=root,password=password //192.168.99.191/share/ /mnt/share
于是改到openwrt上来运行此命令,同时看dsmesg看到了下列错误:
No dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later (e.g. SMB3),
from CIFS (SMB1). To use the less secure SMB1 dialect to access old servers which do not support SMB3 (or SMB2.1) specify vers=1.0 on mount
原来是openwrt上的samba最高只能使用2.0
mount.cifs -o username=root,password=password,vers=2.0 //192.168.99.191/share/ /mnt/share
这样继续也就OK了:
sudo mount -t cifs -o vers=2.0,username=root,password=password,uid=$(id -u),gid=$(id -g),forceuid,forcegid //192.168.99.191/share /mnt/share
autofs中的定义如下:
#smbpasswd root
/mnt/share -fstype=cifs,rw,vers=2.0,username=root,password=password,rw,rsize=61568,uid=1000,forceuid,gid=1000,forcegid,nounix,file_mode=0777,dir_mode=0777 ://xiaoyu/share
我估计之前openwrt上的nfs不work也可能是和版本有关.
同时为了提升性能,在配置中添加了:
#invalid users = rootfollow symlinks = nowide links = noaio read size = 16384aio write size = 16384aio write behind = truewrite cache size = 2097152max xmit = 65536large readwrite = yes
完整配置如下:
root@OpenWrt:~# cat /etc/samba/smb.conf
[global]netbios name = xiaoyu display charset = UTF-8interfaces = lo br-lan server string = OpenWrtunix charset = UTF-8workgroup = WORKGROUPbind interfaces only = yesdeadtime = 30enable core files = no#invalid users = rootlocal master = yesmap to guest = Bad Usermax protocol = SMB2#max protocol = SMB3min receivefile size = 16384null passwords = yespassdb backend = smbpasswdsecurity = usersmb passwd file = /etc/samba/smbpasswdsocket options = TCP_NODELAY IPTOS_LOWDELAYuse sendfile = yes# by quqifollow symlinks = nowide links = noaio read size = 16384aio write size = 16384aio write behind = truewrite cache size = 2097152max xmit = 65536large readwrite = yes
[homes]comment = Home Directoriesbrowsable = noread only = nocreate mode = 0750[share]path = /mnt/sda4valid users = rootread only = noguest ok = yescreate mask = 0777directory mask = 0666browseable = yes
2022031 - openwrt上nfs的问题
见: https://www.right.com.cn/forum/thread-185602-1-1.html
oot@OpenWrt:~# mount.nfs -o vers=3,proto=tcp,nolock 192.168.99.191:/mnt/sda4 /mnt/share -v
mount.nfs: timeout set for Thu Mar 31 19:31:05 2022
mount.nfs: trying text-based options 'vers=3,proto=tcp,nolock,addr=192.168.99.191'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: trying 192.168.99.191 prog 100003 vers 3 prot TCP port 2049
mount.nfs: prog 100005, trying vers=3, prot=6
mount.nfs: trying 192.168.99.191 prog 100005 vers 3 prot TCP port 32780root@OpenWrt:~# logread |tail -n1
Thu Mar 31 19:29:05 2022 daemon.notice rpc.mountd[8309]: authenticated mount request from 192.168.99.191:993 for /mnt/sda4 (/mnt/sda4)netstat -lnput |grep 2049
20220709 - huawei share
在手机上的华为分享处打开"共享至电脑",然后在ubuntu的文件管理器中的左侧点击"其他位置", 接着在最下方有个"连接服务器",填入:smb://即可
[1] https://sq.sf.163.com/blog/article/218146701477384192