一、用户控制登陆
1.安装samba
[root@angel ~]# yum install samba //安装软件
[root@angel ~]# systemctl start smb //启动服务器
[root@angel ~]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
[root@angel ~]# firewall-cmd --permanent --add-service=samba //配置防火墙允许samba访问
success
[root@angel ~]# firewall-cmd --reload
success
2. 创建共享目录
[root@angel ~]# mkdir /share #某用户认证的共享目录
[root@angel ~]# mkdir /public #用来做匿名的用户
[root@angel ~]# chmod 777 /share
[root@angel ~]# chmod 777 /public
3.修改共享目录上下级关系,设置布尔值
[root@angel ~]# yum install policycoreutils-python
[root@angel ~]# semanage fcontext -a -t samba_share_t '/share(/.*)?'
[root@angel ~]# semanage fcontext -a -t samba_share_t '/public(/.*)?'
[root@angel ~]# restorecon -RFv /share
restorecon reset /share context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
[root@angel ~]# restorecon -RFv /public
restorecon reset /public context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
[root@angel ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
tmpreaper_use_samba --> off
use_samba_home_dirs --> off
virt_use_samba --> off
[root@angel ~]# setsebool -P samba_export_all_ro on
[root@angel ~]# setsebool -P samba_export_all_rw on
[root@angel ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> on
samba_export_all_rw --> on
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
tmpreaper_use_samba --> off
use_samba_home_dirs --> off
virt_use_samba --> off
4. 修改配置文件
[root@angel ~]# yum -y install vim
[root@angel ~]# vim /etc/samba/smb.conf
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[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
[share] //普通用户配置共享文件
comment = share directory
path = /share
browseable = yes
writeable = no
write list = user01
[public]
comment = this is public directory //匿名用户共享配置文件
path = /public
browseable = yes
writeable = yes
public = yes
5.创建用户,给共享用户添加密码
[root@angel ~]# useradd user01
[root@angel ~]# smbpasswd -a user01
New SMB password:
Retype new SMB password:
Added user user01.
6.重启服务
[root@angel ~]# systemctl restart smb
7.实施结果
输入自己创建的用户名及密码
登录后即可查看共享文件
二、cifs挂载
1.下载cifs
[root@angel ~]# yum install cifs-utils -y
2.客户端创建文件并写入用户名及密码
[root@angel ~]# vim /root/smbusers
username=user01
password=1
3.第一次挂载并认证
[root@angel ~]# mount -o credentials=/root/smbusers,multiuser,sec=ntlmssp //192.168.16.128/share /mnt
[root@angel ~]# useradd test //添加测试用户
[root@angel ~]# su - test //切换测试用户
[test@angel ~]$ ls /mnt //浏览挂载文件
ls: cannot access /mnt: Permission denied
[test@angel ~]$ cifscreds add -u user01 192.168.81.128 #添加认证
Password:
[test@angel ~]$ ls /mnt
[test@angel ~]$ cd /mnt
[test@angel mnt]$ touch file1
[test@angel mnt]$ ls -l file1
-rwxr-xr-x. 1 test test 0 Aug 1 14:46 file1
三、磁盘阵列
关闭虚拟机,另外创建四个硬盘
[root@angel ~]# lsblk //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
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@angel ~]# yum -y install mdadm //安装mdadm
[root@angel ~]# mdadm -Cv /dev/md0 -a yes -n 4 -l 10 /dev/sdb /dev/sdc /dev/sdd /dev/sde
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@angel ~]# 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@angel ~]# 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@angel ~]# mkdir /raid //创建新文件夹
[root@angel ~]# mount /dev/md0 /raid //挂载 将/dev/md0挂载至 /raid
[root@angel ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.1G 16G 7% /
devtmpfs 979M 0 979M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 1014M 133M 882M 14% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/md0 40G 33M 40G 1% /raid
[root@angel ~]# mdadm -D /dev/md0 #查看md0阵列的详细信息。
/dev/md0:
Version : 1.2
Creation Time : Sat Jun 27 20:21:36 2020
Raid Level : raid10
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Sat Jun 27 20:23:16 2020
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : near=2
Chunk Size : 512K
Consistency Policy : resync
Name : angel:0 (local to host angel)
UUID : 696555b5:1b716b01:dbe12935:b63cfd8e
Events : 19
Number Major Minor RaidDevice State
0 8 16 0 active sync set-A /dev/sdb
1 8 32 1 active sync set-B /dev/sdc
2 8 48 2 active sync set-A /dev/sdd
3 8 64 3 active sync set-B /dev/sde
[root@angel ~]# mdadm /dev/md0 -f /dev/sdb //模拟某块磁盘坏掉
mdadm: set /dev/sdb faulty in /dev/md0
[root@angel ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Mon Jun 29 17:08:46 2020
Raid Level : raid10
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Mon Jun 29 21:40:02 2020
State : clean, degraded
Active Devices : 3
Working Devices : 3
Failed Devices : 1
Spare Devices : 0
Layout : near=2
Chunk Size : 512K
Consistency Policy : resync
Name : angel:0 (local to host angel)
UUID : 982349dc:94488cf2:1321f071:135e3299
Events : 25
Number Major Minor RaidDevice State
- 0 0 0 removed
1 8 32 1 active sync set-B /dev/sdc
2 8 48 2 active sync set-A /dev/sdd
3 8 64 3 active sync set-B /dev/sde
0 8 16 - faulty /dev/sdb
[root@angel ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.1G 16G 7% /
devtmpfs 979M 0 979M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 1014M 133M 882M 14% /boot
tmpfs 199M 0 199M 0% /run/user/0
[root@angel ~]# cd /raid //进入raid目录下
[root@angel raid]# ls
[root@angel raid]# touch file1 //创建文件夹file1,检验磁盘是否能写进数据
[root@angel raid]# ls
file1 //磁盘阵列搭建成功
[root@angel raid]# dd if=/dev/zero of=/raid/file bs=100M count=10 //写入1个G的数据
10+0 records in
10+0 records out
1048576000 bytes (1.0 GB) copied, 11.149 s, 94.1 MB/s
[root@angel raid]# ll -h #查看是否写入磁盘
total 1000M #已写入,磁盘阵列搭建成功
-rw-r--r--. 1 root root 1000M Jun 29 21:42 file
-rw-r--r--. 1 root root 0 Jun 29 21:41 file1
磁盘映射