由于 Windows 和 Linux 同时有需求要访问文件共享功能,所以索性把 samba 和 nfs 都安装上了,但是读写速度比预期的要低很多,之后还要想办法优化一下。
samba
Ubuntu 安装
1
2
3
4
5
6
| ## 安装 samba 服务端
sudo apt-get install samba
sudo apt-get install samba-common
## 安装 samba 客户端
sudo apt-get install smbclient
|
CentOS 安装
1
2
| sudo yum install -y samba
sudo yum install -y samba-client
|
配置
在 /etc/samba/smb.conf
中添加以下配置
1
2
3
4
5
6
7
8
9
10
11
12
13
| [share]
comment = share folder
browseable = yes
path = /home/data
create mask = 0700
directory mask = 0700
valid users = qzp
force user = qzp
force group = qzp
public = yes
available = yes
writable = yes
|
设置 samba 用户密码
设置软连接可访问
【samba】ubuntu创建的软链接文件夹通过samba共享后,在pc端无写权限
1
2
3
4
5
6
7
8
9
10
11
12
| vim /etc/samba/smb.conf
## Allow users who've been granted usershare privileges to create
## public shares, not just authenticated ones
usershare allow guests = yes
# 以下三行是新增的
follow symlinks = yes
wide links = yes
unix extensions = no
## 重启 smb 服务
sudo /etc/init.d/smbd restart
|
连接 samba
linux
smbclient //localhost/share -U username%password
windows
\\localhost
nfs
Ubuntu 安装 nfs
1
2
3
| sudo apt-get install nfs-server
sudo apt-get install nfs-common
|
CentOS 安装 nfs
1
| yum install nfs-utils rpcbind
|
挂载
1
| mount -t nfs -o nolock,vers=2 192.168.199.179:/home/qzp /home/nfs
|
配置权限
1
2
3
| vim /etc/exports
/home/nfs *(rw)
|
读写测试
测试 nfs 写速度
time dd if=/dev/zero of=/nfsdir/testfile bs=8k count=1024
测试 nfs 读速度
time dd if=/nfsdir/testfile of=/dev/null bs=8k count=1024
设置开机启动
1
2
3
4
5
6
| systemctl list-unit-files --type=service | grep enable
systemctl enable smbd
systemctl enable nfs-kernel-server
systemctl enable nfs-commen
systemctl enable portmap
|