Linux共享文件系统

1.安装samba

[root@apple ~]# yum install samba samba-common samba-client -y//安装samba软件
[root@apple ~]# systemctl start smb//启动samba软件服务
[root@apple ~]# systemctl enable smb   //设置开机启动
Created symlink
from /etc/systemd/system/multi-user.target.wants/smb.service to
/usr/lib/systemd/system/smb.service.
[root@apple ~]# firewall-cmd --permanent --add-service=samba//配置防火墙允许samba访问
success
[root@apple ~]# firewall-cmd --permanent --add-service=mountd//防火墙永久允许挂载服务
Success

2.更改centos7ip地址使window是和Linux处于同一网段

[root@apple ~]#
vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
IPADDR=192.168.64.233
NETMASK=255.255.255.0
GATEWAY=192.168.64.2
DNS1=114.114.114.114
DNS2=114.114.115.115
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="50b3ae39-26a3-4515-b283-8e52a50e9bdb"
DEVICE="ens33"
ONBOOT="yes"

3.samba用户登录

[root@apple ~]# useradd smbuser //创建用户
[root@apple ~]# smbpasswd -a smbuser //为用户登录增加密码
New SMB password:
Retype new SMB password:
Added user
student.

4.修改配置文件

mkdir /sambashared/node1 -pv //创建共享目录
[root@apple ~]# chmod o+w /sambashared/node1
//用setfacl方式对指定用户开放权限
 [root@apple ~]# chmod 777 /sambashared/node1 //权限开放
[root@apple ~]# vim /etc/samba/smb.conf  //主要配置gloal部分
[printers]
        comment = All Printers
        path = /var/tmp
        printable = Yes
        create mask = 0600
        browseable = No
[print$]
        comment = Printer Drivers
        path = /var/lib/samba/drivers
        write list = @printadmin root
        force group = @printadmin
        create mask = 0664
        directory mask = 0775
[node1]//共享文件夹名
        comment = shared node1 //备注
        path = /sambashared/node1  //共享目录绝对路径
        write list = smbuser //可更改者
        browseable = yes //是否可见
        guest ok = no 
        valid users = smbuser //使用用户
systemctl restart nmb smb //重启smb服务,配置文件修改生效

5.windows访问共享文件夹
在windows运行或文件夹中输入\\192.168.64.233 #Linux的ip地址

Linux共享文件系统_第1张图片Linux共享文件系统_第2张图片然后弹出用户验证
Linux共享文件系统_第3张图片

Linux共享文件系统_第4张图片【注】win10系统很可能出现只能看见共享文件夹,而进入不了文件夹
1、发现Samba不能进入文件夹,提示没有权限,发现这是Centos7的SELinux安全级别太高引起,降低为Permissive 宽容模式即可
编辑:vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
然后重启系统生效
用getenforce命令查看,显示Permissive就成功了
方法来源于:https://blog.csdn.net/qq_18484091/article/details/101454455?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase
6.磁盘阵列和磁盘映射
磁盘阵列(R10)
创建4块硬盘,可选择将虚拟硬盘为单个文件,便于实验后删除
Linux共享文件系统_第5张图片

[root@apple ~]# lsblk //查看磁盘,可发现已有bcde四块虚拟磁盘
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk 
sdc               8:32   0   20G  0 disk 
sdd               8:48   0   20G  0 disk 
sde               8:64   0   20G  0 disk 
sr0              11:0    1  918M  0 rom  
[root@apple ~]#  yum -y install mdadm //安装mdadm软件
[root@apple ~]# mdadm -Cv /dev/md0 -a yes -n 4 -l 10 /dev/sdb /dev/sdc /dev/sdd /dev/sde //利用mdadm进行磁盘部署
mdadm: layout defaults to n2
mdadm: layout defaults to n2
mdadm: chunk size defaults to 512K
mdadm: size set to 20954112K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@apple ~]# lsblk //再次查看磁盘
NAME            MAJ:MIN RM  SIZE RO TYPE   MOUNTPOINT
sda               8:0    0   20G  0 disk   
├─sda1            8:1    0    1G  0 part   /boot
└─sda2            8:2    0   19G  0 part   
  ├─centos-root 253:0    0   17G  0 lvm    /
  └─centos-swap 253:1    0    2G  0 lvm    [SWAP]
sdb               8:16   0   20G  0 disk   
└─md0             9:0    0   40G  0 raid10 
sdc               8:32   0   20G  0 disk   
└─md0             9:0    0   40G  0 raid10 
sdd               8:48   0   20G  0 disk   
└─md0             9:0    0   40G  0 raid10 
sde               8:64   0   20G  0 disk   
└─md0             9:0    0   40G  0 raid10 
sr0              11:0    1  918M  0 rom    
[root@apple ~]# mkfs.xfs /dev/md0  //格式化硬盘
meta-data=/dev/md0               isize=512    agcount=16, agsize=654720 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=10475520, imaxpct=25
         =                       sunit=128    swidth=256 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=5120, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@apple ~]# mount /dev/md0 /sambashared/node1
[root@apple ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G  1.2G   16G   7% /
devtmpfs                 898M     0  898M   0% /dev
tmpfs                    910M     0  910M   0% /dev/shm
tmpfs                    910M  9.6M  901M   2% /run
tmpfs                    910M     0  910M   0% /sys/fs/cgroup
/dev/sda1               1014M  146M  869M  15% /boot
tmpfs                    182M     0  182M   0% /run/user/0
/dev/md0                  40G   33M   40G   1% /sambashared/node1
[root@apple ~]# vi /etc/fstab //设置自动挂载

7.磁盘映射
\\ip地址\文件夹名称
Linux共享文件系统_第6张图片
Linux共享文件系统_第7张图片

你可能感兴趣的:(Linux网课学习)