mfs的分布式文件存储系统--找回删除文件

冷备机制
当master挂了,会储存一部分数据
master:

[root@server4 ~]# yum install -y moosefs-master-3.0.97-1.rhsysv.x86_64.rpm moosefs-cgiserv-3.0.97-1.rhsysv.x86_64.rpm moosefs-cgi-3.0.97-1.rhsysv.x86_64.rpm 
[root@server4 ~]# vim /etc/hosts
172.25.23.4 server4 mfsmaster
[root@server4 ~]# cd /var/lib/mfs/
[root@server4 mfs]# ll
total 8
-rwxr--r--. 1 mfs mfs 8 Aug 26 09:36 metadata.mfs
-rwxr--r--. 1 mfs mfs 8 Aug  2  2017 metadata.mfs.empty
[root@server4 mfs]# vim /etc/mfs/mfsmaster.cfg
配置文件。不修改
[root@server4 mfs]# /etc/init.d/moosefs-master start
Starting mfsmaster:                                        [  OK  ]

这里写图片描述

[root@server4 mfs]# yum install net-tools
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Package net-tools-1.60-110.el6_2.x86_64 already installed and latest version
Nothing to do
[root@server4 mfs]# netstat -antlup
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:9419                0.0.0.0:*                   LISTEN      1420/mfsmaster      
tcp        0      0 0.0.0.0:9420                0.0.0.0:*                   LISTEN      1420/mfsmaster      
tcp        0      0 0.0.0.0:9421                0.0.0.0:*                   LISTEN      1420/mfsmaster      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      908/sshd            
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      984/master          
tcp        0      0 172.25.23.4:22              172.25.23.250:43360         ESTABLISHED 1354/sshd           
tcp        0      0 :::22                       :::*                        LISTEN      908/sshd            
tcp        0      0 ::1:25                      :::*                        LISTEN      984/master  
进行监控        
[root@server4 mfs]# /etc/init.d/moosefs-cgiserv start
Starting mfscgiserv:                                       [  OK  ]
[root@server4 mfs]# netstat -antlup
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:9419                0.0.0.0:*                   LISTEN      1420/mfsmaster      
tcp        0      0 0.0.0.0:9420                0.0.0.0:*                   LISTEN      1420/mfsmaster      
tcp        0      0 0.0.0.0:9421                0.0.0.0:*                   LISTEN      1420/mfsmaster      
tcp        0      0 0.0.0.0:9425                0.0.0.0:*                   LISTEN      1429/python         
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      908/sshd            
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      984/master          
tcp        0      0 172.25.23.4:22              172.25.23.250:43360         ESTABLISHED 1354/sshd           
tcp        0      0 :::22                       :::*                        LISTEN      908/sshd            
tcp        0      0 ::1:25                      :::*                        LISTEN      984/master          

这里写图片描述

[root@server5 ~]# yum install moosefs-chunkserver-3.0.97-1.rhsysv.x86_64.rpm  -y

[root@server5 ~]# mkdir /mnt/chunk1
[root@server5 ~]# vim /etc/mfs/mfshdd.cfg
/mnt/chunk1
[root@server5 ~]# chown mfs.mfs /mnt/chunk1/
[root@server5 ~]# vim /etc/hosts
172.25.23.4 server4 mfsmaster
[root@server5 ~]# /etc/init.d/moosefs-chunkserver start
Starting mfschunkserver:                                   [  OK  ]

这里写图片描述

[root@server6 ~]# yum install moosefs-chunkserver-3.0.97-1.rhsysv.x86_64.rpm 

[root@server6 ~]# vim /etc/mfs/mfshdd.cfg
/mnt/chunk2
[root@server6 ~]# mkdir /mnt/chunk2
[root@server6 ~]# chuwn mfs.mfs /mnt/chunk2/
-bash: chuwn: command not found
[root@server6 ~]# chown mfs.mfs /mnt/chunk2/
[root@server6 ~]# /etc/init.d/moosefs-chunkserver start^C^C
[root@server6 ~]# vim /etc/hosts
172.25.23.4 server4 mfsmaster

[root@server6 ~]# /etc/init.d/moosefs-chunkserver start
Starting mfschunkserver:                                   [  OK  ]

这里写图片描述

客户机:9421

[root@foundation23 Desktop]# yum install moosefs-client-3.0.97-1.rhsystemd.x86_64.rpm  -y
[root@foundation23 Desktop]# vim /etc/mfs/mfsmount.cfg
/mnt/mfs
[root@foundation23 Desktop]# vim /etc/hosts
172.25.23.4 server4 mfsmaster

[root@foundation23 Desktop]# mkdir /mnt/mfs
[root@foundation23 Desktop]# mfsmount
mfsmaster accepted connection with parameters: read-write,restricted_ip,admin ; root mapped to root:root
[root@foundation23 Desktop]# df
Filesystem                         1K-blocks     Used Available Use% Mounted on
/dev/mapper/rhel_foundation23-root 307430744 47446776 259983968  16% /
devtmpfs                             1952032        0   1952032   0% /dev
tmpfs                                1965404      488   1964916   1% /dev/shm
tmpfs                                1965404     9100   1956304   1% /run
tmpfs                                1965404        0   1965404   0% /sys/fs/cgroup
/dev/sda1                            1038336   143504    894832  14% /boot
/dev/loop0                           3704296  3704296         0 100% /var/www/html/rhel7.0
/dev/loop1                           3762278  3762278         0 100% /var/www/html/rhel6.5
tmpfs                                 393084       28    393056   1% /run/user/1000
mfsmaster:9421                      36324672  2377536  33947136   7% /mnt/mfs

这里写图片描述
这里写图片描述

测试:
在客户机上创建文件,在两个节点储存

[root@foundation23 mnt]# cd mfs/
[root@foundation23 mfs]# ls
[root@foundation23 mfs]# mkdir dir1
[root@foundation23 mfs]# mkdir dir2
[root@foundation23 mfs]# mfsgetgoal dir1/
dir1/: 2
[root@foundation23 mfs]# mfsgetgoal dir2/
dir2/: 2
[root@foundation23 mfs]# mfsgetgoal dir1
dir1: 2
[root@foundation23 mfs]# ls
dir1  dir2

这里写图片描述

[root@foundation23 mfs]# mfssetgoal -r 1 dir1/
dir1/:
 inodes with goal changed:                       1
 inodes with goal not changed:                   0
 inodes with permission denied:                  0
[root@foundation23 mfs]# mfsgetgoal dir1/
dir1/: 1
[root@foundation23 mfs]# cd dir1/
[root@foundation23 dir1]# cp /etc/passwd .
[root@foundation23 dir1]# mfsfileinfo passwd
passwd:
    chunk 0: 0000000000000001_00000001 / (id:1 ver:1)
        copy 1: 172.25.23.6:9422 (status:VALID)
[root@foundation23 dir1]# cd ..
[root@foundation23 mfs]# cd dir2/
[root@foundation23 dir2]# cp /etc/fstab .
[root@foundation23 dir2]# ls
fstab
[root@foundation23 dir2]# mfsfileinfo fstab 
fstab:
    chunk 0: 0000000000000002_00000001 / (id:2 ver:1)
        copy 1: 172.25.23.5:9422 (status:VALID)
        copy 2: 172.25.23.6:9422 (status:VALID)

这里写图片描述
一个chunk只能储存64M数据,如果只备份一次,且数据大于64M,则进行分片,在另一个节点也会备份数据

[root@foundation23 dir1]# dd if=/dev/zero of=file1 bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.26427 s, 397 MB/s
[root@foundation23 dir1]# mfsfileinfo file1 
file1:
    chunk 0: 0000000000000003_00000001 / (id:3 ver:1)
        copy 1: 172.25.23.6:9422 (status:VALID)
    chunk 1: 0000000000000004_00000001 / (id:4 ver:1)
        copy 1: 172.25.23.5:9422 (status:VALID)
[root@foundation23 dir2]# dd if=/dev/zero of=file1 bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.527456 s, 199 MB/s
[root@foundation23 dir2]# mfsfileinfo file1 
file1:
    chunk 0: 0000000000000005_00000001 / (id:5 ver:1)
        copy 1: 172.25.23.5:9422 (status:VALID)
        copy 2: 172.25.23.6:9422 (status:VALID)
    chunk 1: 0000000000000006_00000001 / (id:6 ver:1)
        copy 1: 172.25.23.5:9422 (status:VALID)
        copy 2: 172.25.23.6:9422 (status:VALID)
[root@foundation23 dir2]# ls
file1  fstab

这里写图片描述

怎样将删除的文件找回来?

[root@foundation23 dir1]# rm -fr passwd 
[root@foundation23 dir1]# mkdir mfsmeta
[root@foundation23 dir1]# rm -fr mfsmeta/
[root@foundation23 dir1]# mkdir /mnt/mfsmeta
[root@foundation23 dir1]# mfsmount  -m /mnt/mfsmeta/
mfsmaster accepted connection with parameters: read-write,restricted_ip

这里写图片描述
查看挂载

[root@foundation23 dir1]# df
Filesystem                         1K-blocks     Used Available Use% Mounted on
/dev/mapper/rhel_foundation23-root 307430744 47526432 259904312  16% /
devtmpfs                             1952032        0   1952032   0% /dev
tmpfs                                1965404      492   1964912   1% /dev/shm
tmpfs                                1965404     9096   1956308   1% /run
tmpfs                                1965404        0   1965404   0% /sys/fs/cgroup
/dev/sda1                            1038336   143504    894832  14% /boot
/dev/loop0                           3704296  3704296         0 100% /var/www/html/rhel7.0
/dev/loop1                           3762278  3762278         0 100% /var/www/html/rhel6.5
tmpfs                                 393084       20    393064   1% /run/user/1000
mfsmaster:9421                      36324672  2385600  33939072   7% /mnt/mfs
[root@foundation23 dir1]# ls
file1

这里写图片描述

找寻文件

[root@foundation23 dir1]# cd /mnt/mfsmeta/
[root@foundation23 mfsmeta]# ls
sustained  trash
[root@foundation23 mfsmeta]# cd trash/
[root@foundation23 trash]# find -name *passwd*
./004/00000004|dir1|passwd
[root@foundation23 trash]# mv 004/00000004\|dir1\|passwd undel/
[root@foundation23 trash]# cd /mnt/dir1
-bash: cd: /mnt/dir1: No such file or directory
[root@foundation23 trash]# cd /mnt/mfs/dir1/
[root@foundation23 dir1]# ls
file1  passwd

这里写图片描述

猜你喜欢

转载自blog.csdn.net/ningyuxuan123/article/details/82079082