需求背景
相信做Java开发的小伙伴可能都会遇到这样的需求,在生产环境多台机器需要访问一台机器上数据,这样的数据一般都是为了统一管理和存储,并且呢,这样的数据一般比较大,不容易进行迁移,因此我需要多台机器访问一台机器的上的数据的功能。
技术路线1
About Samba
Samba is the standard Windows interoperability suite of programs for Linux and Unix.
Samba is Free Software licensed under the GNU General Public License, the Samba project is a member of the Software Freedom Conservancy.
Since 1992, Samba has provided secure, stable and fast file and print services for all clients using the SMB/CIFS protocol, such as all versions of DOS and Windows, OS/2, Linux and many others.
Samba is an important component to seamlessly integrate Linux/Unix Servers and Desktops into Active Directory environments. It can function both as a domain controller or as a regular domain member.
安装Samba并配置
1 | ini复制代码 # 在线安装samba和samba-client |
添加用户
1 | bash复制代码 useradd -s /sbin/nologin/sambauser |
设置密码
1 | css复制代码 smbpasswd -a sambauser |
检测用户是否添加成功
1 | 复制代码 pdbedit -L |
设置samba服务开机自启
1 | bash复制代码 systemctl enable smb.service |
设置samba服务可以通过防火墙防御
1 | css复制代码 firewall-cmd --permanent --zone=public --add-service=samba |
测试语法是否正确
1 | 复制代码 testparam |
开始挂载
1 | bash复制代码 Mount –t cift //192.168.10.18:/share /share –o username=sambatest,password=xxxy |
修改服务端口
samba服务默认使用的是445端口,按照如下方式可以进行修改:
1 | ini复制代码 vim /etc/samba/smb.conf |
查看服务状态
1 | lua复制代码 systemctl status smbd |
1 | bash复制代码 tail /var/log/samba/log.smbd |
查看服务是否运行在4455端口
1 | css复制代码 lsof -i:4455 |
对不同版本的Windows做了抓包测试,发现WinXP只访问139端口,Win7同时访问139与445端口,Win10只访问445端口
技术路线2
About nfs
NFS 就是 Network FileSystem 的缩写,最早之前是由 Sun这家公司所发展出来的 。 它最大的功能就是可以透过网络,让不同的机器、不同的操作系统、可以彼此分享文件。
服务端在线安装nfs
1 | bash复制代码 # 使用yum安装nfs-utils时会把rpcbind一起安装上 |
设置nfs服务端开机自启
1 | bash复制代码 systemctl enable rpcbind.service |
确认NFS服务器启动成功
1 | css复制代码 rpcinfo -p |
通过查看service列中是否有nfs服务来确认NFS是否启动
1 | arduino复制代码 showmount -e 192.168.0.3 // 主机IP |
在客户端安装nfs服务
1 | bash复制代码 yum install -y nfs-utils |
注意:客户端不需要启动nfs服务,只需要启动rpcbind服务.
检查nfs服务器端是否有目录共享
1 | 复制代码 showmount -e 192.168.0.3 |
使用 mount 挂载A服务器端的目录/opt/nfs到客户端B的目录/opt/nfs下
1 | ruby复制代码 [root@localhost ~]# mkdir /opt/nfs |
如果需要A、B、C三台机器都能够向共享目录写入文件,可按照如下操作进行:
1 | bash复制代码 [root@localhost home]# id root |
\
本文转载自: 掘金