一、smb文件共享
1.安装和为smb添加用户 1.1安装smb软件 1
2
3
yum install samba samba-common samba-client-y
systemctl start smb nmb
systemctl enable smb nmb
1.2为smb添加用户 1
2
3
4
5
6
7
smb用户必须时本地用户
smbpasswd -a student
New SMB password: #输入smb当前用户密码
Retype new SMB password: #确认密码
pdbedit -L #查看smb用户信息
pdbedit -x smb用户 #删除smb用户
1.3查看smb的共享目录 查看自己的共享目录,添加目录后默认共享家目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[iyunv@server ~]# smbclient -L //172.25.254.231 -U student
Enter student's password:
Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3]
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC Service (Samba Server Version 4.2.3)
student Disk Home Directories
Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3]
Server Comment
--------- -------
Workgroup Master
--------- -------
1.4登陆smb 的共享目录 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[iyunv@server ~]# smbclient //172.25.254.231/student -U student
Enter student's password:
Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3]
smb: \>
#此时你如果想看你的共享目录就会出现如下错误,因为的selinux 开着
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*
#这时你需要将selinux的samba_enable_home_dirs打开。
#同时还需要在配置文件中设定smb用户可以访问自己的家目录
#就是/etc/samba/smb.conf中第30行 setsebool -P samba_enable_home_dirs on
[iyunv@server ~]#setsebool samba_enable_home_dirs on
[iyunv@server ~]# smbclient //172.25.254.231/student -U student
Enter student's password:
Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3]
smb: \> ls
. D 0 Thu Jul 10 19:06:52 2014
.. D 0 Thu Jul 10 18:19:09 2014
.bash_logout H 18 Wed Jan 29 07:45:18 2014
.bash_profile H 193 Wed Jan 29 07:45:18 2014
.bashrc H 231 Wed Jan 29 07:45:18 2014
.ssh DH 0 Thu Jul 10 18:19:10 2014
.config DH 0 Thu Jul 10 19:06:53 2014
10473900 blocks of size 1024. 7318236 blocksavailable
2. /etc/samba/smb.conf 的简单配置 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[iyunv@server ~]# vim /etc/samba/smb.conf
30 setsebool -P samba_enable_home_dirs on
#开启可以查看用户的家目录
49 setsebool -P samba_export_all_roon
#只读共享
51 setsebool -P samba_export_all_rwon
#读写共享
##在selinux中设定smb用户可以访问自己的家目录
89 workgroup = MYGROUP
#修改标签名称也就是下面的Domai的名称
#[iyunv@server ~]# smbclient -L //172.25.254.231 -U student
#Enter student's password:
#Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3]
96 hosts allow =172.25.254.131
#只给172.25.254.131这个主机,其他用户远程登陆时会出下如下错误:
[iyunv@server ~]# smbclient //172.25.254.231/student -U student
Enter student's password:
protocol negotiation failed:NT_STATUS_INVALID_NETWORK_RESPONSE
3.共享目录的基本设定 3.1共享目录的简单设定步骤
1
2
3
4
5
6
7
8
9
10
11
12
vim /etc/samba/smb.conf
[haha] 共享名称
comment = 对共享目录的描述
path = 共享目录的绝对路径
workgroup = WESTOS
当共享目录为用户自建立目录时
semanage fcontext -a -t samba_share_t '目录名称(/.*)?'
restorecon -RvvF 目录名称
当共享目录为系统建立目录
setsebool -P samba_export_all_ro on #只读共享
setsebool -P samba_export_all_rw on #读写共享
3.2共享目录的实例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[iyunv@server ~]# vim /etc/samba/smb.conf
#下面为添加的共享目录的代码
[feitian]
#共享目录的名称,就是你挂载时需要填写的:例如//172.25.254.231/feitian
comment = local directory /westos
path = /westos
[iyunv@server ~]# systemctl restart smb
#这时你在查看就会多了一个共享目录当你登陆时会发现登陆之后,出现如下错误,还是因为selinux
[iyunv@server ~]# smbclient -L //172.25.254.231 -U student
feitian Disk local directory /westos
[iyunv@server westos]# smbclient //172.25.254.231/feitian -U student
Enter student's password: #输入添加的用户student的密码
Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3]
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*
#修改smb共享目录的安全上下文
[iyunv@server ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?'
[iyunv@server ~]# restorecon -RvvF /westos
restorecon reset /westos contextunconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/file1 contextunconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/file2 contextunconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/file3 contextunconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
#这时你登陆就会好了,别忘了/etc/samba/smb.conf中selinux需要打开。还要在主机上开启selinux对smb服务的只读或者读写权限。
[iyunv@client ~]# mount//172.25.254.231/student /mnt -o username=student,password=student
[iyunv@client ~]# df -h |grep//172.25.254.231
//172.25.254.231/student 10G 3.1G 7.0G 31% /mnt
#开机自动挂载
vim /etc/fstab
//172.25.254.231/feitian /mnt cifs defaults,username=studnet,password 0 0
4.samba的配置参数 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#匿名用户访问
guest ok = yes
map to guest = bad user
#访问控制
hosts allow = #仅允许
hosts deny = #仅拒绝
valid users = #当前共享的有效用户
valid users = westos #当前共享的有效用户为westos
valid users = @westos #当前共享的有效用户为westos组
valid users = +westos #当前共享的有效用户为westos组
#读写控制
所有用户均可写
chmod o+w /mnt
setsebool -P samba_export_all_rw on
vim /etc/samba/smb.conf
writable = yes
#设定指定用户可写
write list = student #可写用户
write list = +student #可写用户组
write list = @student #也是可写用户组
admin users = westos #共享的超级用户指定
5.smb多用户共享 在客户端做如下操作
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[iyunv@client ~]# vim /root/haha
username=student
password=student
[iyunv@client ~]# chmod 600 /root/haha
[iyunv@client ~]# yum install cifs-utils -y
[iyunv@client ~]# cifscreds clear -u student 172.25.254.231
Password: ##smb用户student的密码
mount -o credentials=/root/haha,multiuser,sec=ntlmssp //172.25.254.231/haha /mnt/
#credentials=/root/haha 指定挂载时所用到的用户文件
#multiuser 支持多用户认证
#sec=ntlmssp 认证方式为标准smb认证方式
[iyunv@client ~]# df -h|grep 172.25.254.231
//172.25.254.231/feitian 10G 3.1G 7.0G 31% /mnt
#共享用户
cifscreds add -u westos 172.25.254.100
Password: ##smb用户westos的密码
ls /mnt
二 、NFS 文件共享
1、NFS介绍
NFS是Network File System 的缩写,主要功能是通过网络让不同的机器彼此之间共享文件或目录,可以通过挂载(mount)的方式将NFS服务器端共享的数据文件目录挂载到NFS客户端本地中。NFS协议有多个版本:Linux支持版本4、版本3和版本2,而大多数系统管理员熟悉的是NFSv3。默认情况下,该协议并不安全,但是更新的版本(如NFSv4)提供了更安全的身份验证支持,甚至可以通过kerberos进行加密
2、简单的NFS不同主机之间的共享
在server上的简但配置
1
2
3
4
[iyunv@nfs-clinent ~]# vim /etc/exports
/westso/lala 172.25.254.231(rw,sync)
#共享serve /westos/lala这个目录,客户端有读和写还有在共享目录的建立删除会直接写入主机的内存中
#exportfs -rv 直接刷新,不用重启NFS服务
在client的简但配置
1
2
3
4
5
6
[iyunv@nfs-clinent ~]# showmount -e 172.25.254.231
Export list for 172.25.254.231:
/westos/lala 172.25.254.131
[iyunv@nfs-clinent ~]# mount -t nfs 172.25.254.231:/westos /mnt
[iyunv@nfs-clinent ~]# df -h|gerp 172.25.254.231
172.25.254.231:/westos/lala 9.2G 2.5G 6.3G 29% /mnt
设置开机自动挂载,这里就不在说了,已经说太多变了
3、默认目录自动挂载
3.1 安装软件
客户端安装软件
1
2
3
4
5
6
7
8
9
[iyunv@nfs-clinent ~]# yum install autofs -y
[iyunv@nfs-clinent ~]# systemctl restart autifs.server
[iyunv@nfs-clinent ~]# cd /net
[iyunv@nfs-clinent ~]# cd 172.25.254.231
[iyunv@nfs-clinent ~]# ls
westos
[iyunv@nfs-clinent ~]# cd /westos/lala
#这样就可以看到他的共享目录下面的内容,而且是自动挂载,退出目录后默认5分钟自动卸载。他可以修改
#在/etc/autofs.conf中可以修改。
4、 指定目录的自动挂载
在客户端修改配置文件
1
2
3
4
5
6
7
[iyunv@nfs-clinent ~]# vim /etc/auto.master
#添加一行,/nfs是指共享目录的第一层目录,/etc/auto.nfs他是master的子文件
/westos /etc/auto.nfs
[iyunv@nfs-clinent ~]#vim /etc/auto.nfs
#共享目录的第二层目录
* 172.25.254.231:/&
#这个意思是前面的第二层目录和第一层目录是一致的,如果你挂载了lala就表示你 自动挂载的目录为/westos/lala
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com