标签:分布式存储--->在线服务 服务器 手机访问 虚拟机 支付宝
同一个网站,根据客户端用电脑或手机访问不同 出现的会有宽屏或长格式 是用不同的样式表文件决定 但网页文件还是那一个
FASTDFS 主控服务器 (存所有文件目录信息,要找一个文件先找他)----》数据库服务器(存放文件)
分布式文件系统:fastDFS功能:文件存储,文件访问,文件同步(上传下载) 解决大容量存储和负载均衡问题,适合以文件为载体在线服务,如相册网站,视频网站(京东,51cto,赶集,支付宝
FastDFS服务分为跟踪器和存储节点两块,存储节点一个组可以是多个,这样使保存的数据更安全。客户的数据可以上传下载,节点上都能查到,但客户把自己的数据文件删了,节点就不会有。
______________________________________________________________
fdfs_trackerd 22122 fdfs_storaged 23000
—————————————————————————————————————————————
1)vh01
1.先新建两台虚拟机,vh01和vh02
vh01.tedu.cn 192.168.4.1/24 tracker
vh02.tedu.cn 192.168.4.2/24 group1/storage 额外硬盘
2.安装fastDFS trakcer (vh01做跟踪器)
安装依赖包
# ls fdfs_soft/
fastdfs-nginx-module_v1.16.tar.gz
FastDFS_v4.06.tar.gz
libevent-devel-1.4.13-4.el6.x86_64.rpm
libevent-doc-1.4.13-4.el6.noarch.rpm
libevent-headers-1.4.13-4.el6.noarch.rpm
nginx-1.7.10.tar.gz
tedu.jpg
#cd fdfs_soft
# yum -y install gcc libevent make *.rpm (先把依赖包装,因为有些依赖在光盘中没有,先下好放在一起,再装)rpm包也可以用yum装 不需要用rpm -ivh *.rpm (这样可以解决依赖关系)
# tar -zxvf FastDFS_v4.06.tar.gz
# cd FastDFS
# vim INSTALL (查看安装需要过程和依赖)
# ./make.sh
# ./make install
2.配置tracker (vh01跟踪器)
# cp init.d/fdfs_trackerd /etc/init.d/ (拷贝fdfs_trackerd 启动脚本到/etc下)
# mkdir -p /data/fastdfs
# vim /etc/fdfs/tracker.conf
22 base_path=/data/fastdfs
25 max_connections=4096
32 # the method of selecting group to upload files
33 # 0: round robin
34 # 1: specify group
35 # 2: load balance, select the max free space group to upload file
36 store_lookup=2
186 storage_ids_filename = storage_ids.conf
# cp storage_ids.conf /etc/fdfs/
100001 group1 192.168.4.2
3.启动服务器:
# service fdfs_trackerd start; chkconfig fdfs_trackerd on
Starting FastDFS tracker server:
# service fdfs_trackerd status
fdfs_trackerd (pid 3342) 正在运行...
————————————————————————————————————————————
# vim /data/fastdfs/logs/trackerd.log 日志文件存在这(出现什么问题可以查看日志)
————————————————————————————————————————————
2)vh02
1.配置storage(vh02存储节点,属于group1组)
#cd fdfs_soft/
#yum -y install gcc libevent *.rpm make
#tar -zxf FastDFS_v4.06.tar.gz
#cd FastDFS
#./make.sh
#./make.sh install
#lsblk
#parted /dev/vdb
mktab gpt
mkpart
primary
ext4
1M
-1
quit
#lsblk
#mkfs.ext4 /dev/vdb1
#blkid /dev/vdb1
#mkdir -p /data/fastdfs
#vim /etc/fstab (永久挂载)
UUID="c8b37f56-7bb5-4c9b-b45b-610a3884f785" /data/fastdfs ext4 defaults 0 0
#mount -a
#cp init.d/fdfs_storaged /etc/init.d/ (拷贝fdfs_storadged启动脚本到etc下)
#vim /etc/fdfs/storage.conf
7 group_name=group1
37 base_path=/data/fastdfs
42 max_connections=4096
96 store_path_count=1
100 store_path0=/data/fastdfs
109 tracker_server=192.168.4.1:22122
172 upload_priority=10
起服务并验证:
#service fdfs_storaged start; chkconfig fdfs_storaged on
#service fdfs_storaged status
# ls /data/fastdfs/data/00
#netstat -anptu | grep :23000
3)物理机
配置物理主机为客户端(192.168.4.254)
1、在物理主机上创建工作目录
# mkdir /tmp/fdfs
2、将服务端上/usr/local/bin/下所有的fdfs命令文件拷贝到物理主机
[root@vh02 FastDFS]# scp /usr/local/bin/fdfs_* 192.168.4.254:/tmp/fdfs/
3、将服务端配置文件client.conf拷贝到物理主机
[root@vh02 FastDFS]# scp /etc/fdfs/client.conf 192.168.4.254:/tmp/fdfs/
4、修改配置文件
#cd /tmp/fdfs
#vim client.conf
base_path=/tmp/fdfs
tracker_server=192.168.4.1:22122
物理机:数据上传和下载,删除:
[root@room1pc01 fdfs]# ./fdfs_upload_file client.conf /etc/passwd
group1/M00/00/00/wKgEAljPFZyAXM7xAAALqve6qZ43997550
[root@room1pc01 fdfs]# ./fdfs_download_file client.conf group1/M00/00/00/wKgEAljPFZyAXM7xAAALqve6qZ43997550 /tmp/users
服务器(vh02 storage)查看:
[root@vh02 00]# pwd
/data/fastdfs/data/00/00
[root@vh02 00]# ls (物理机上传的服务器会有节点存储,文件名就是物理机生成的文件名和路径)
wKgEAljPFZyAXM7xAAALqve6qZ43997550
删除:(物理机把上传的删除后,服务器存储节点就没有了)
[root@room1pc01 fdfs]# ./fdfs_delete_file client.conf group1/M00/00/00/wKgEAljPFZyAXM7xAAALqve6qZ43997550
4)vh02:
1.在storage上配置web访问(vh02加网站模块,上传图片文件)
#yum -y install -y pcre pcre-devel zlib-devel
#useradd -s /sbin/nologin nginx
#cd fdfs_soft/
#tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
#tar -zxvf nginx-1.7.10.tar.gz
#cd nginx-1.7.10
#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --add-module=../fastdfs-nginx-module/src/
#make && make install
#cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
#vim /etc/fdfs/mod_fastdfs.conf
base_path=/data/fastdfs
tracker_server=192.168.4.1:22122
group_name=group1
store_path_count=1
store_path0=/data/fastdfs
#vim /usr/local/nginx/conf/nginx.conf
location / {
# root html;
# index index.html index.htm;
ngx_fastdfs_module;
}
#/usr/local/nginx/sbin/nginx
2.测试,物理机上传图片:
[root@room1pc01 fdfs]# ./fdfs_upload_file client.conf /root/桌面/2138294562.jpg
group1/M00/00/00/wKgEAljPHCKAdT4XAADb1hKlWxM275.jpg
[root@room1pc01 fdfs]# firefox http://192.168.4.2/group1/M00/00/00/wKgEAljPHCKAdT4XAADb1hKlWxM275.jpg
服务器(vh02 storage)查看(也会有文件图片保存):
[root@vh02 00]# pwd
/data/fastdfs/data/00/00
[root@vh02 00]# ls
wKgEAljPHCKAdT4XAADb1hKlWxM275.jpg
————
上面是vh01做fastDFS trakcer跟踪器 且只设一个group1组,组内只有一个备份存储节点vh02,现在在group1组加一个节点vh03(192.168.4.3),再加一个group2组,存储节点vh04(192.168.4.4),vh01 trakcer采取的存储数据的方式是轮循。一个组保存一次,当group1组保数据时,vh02和vh03这两个节点都会有备份。(这两个节点最大存储的空间以小的为准)。
1)vh01
[root@vh01 fdfs_soft]# vim /etc/fdfs/storage_ids.conf
# <id> <group_name> <ip_or_hostname>
# 100001 group1 192.168.0.196
# 100002 group1 192.168.0.116
100001 group1 192.168.4.2
100002 group1 192.168.4.3
100003 group2 192.168.4.4
[root@vh01 fdfs_soft]# vim /etc/fdfs/tracker.conf (设置轮循存储)
32 # the method of selecting group to upload files
33 # 0: round robin
34 # 1: specify group
35 # 2: load balance, select the max free space group to upload file
36 store_lookup=0
[root@vh01 fdfs_soft]# service fdfs_trackerd restart;chkconfig fdfs_trackerd on
2)vh03:
192.168.4.3 加一块硬盘:
1.配置storage(vh03存储节点,属于group1组与vh02一样)
#cd fdfs_soft/
#yum -y install gcc libevent *.rpm make
#tar -zxf FastDFS_v4.06.tar.gz
#cd FastDFS
#./make.sh
#./make.sh install
#lsblk
#parted /dev/vdb
mktab gpt
mkpart
primary
ext4
1M
-1
quit
#lsblk
#mkfs.ext4 /dev/vdb1
#blkid /dev/vdb1
#mkdir -p /data/fastdfs
#vim /etc/fstab (永久挂载)
UUID="c8b37f56-7bb5-4c9b-b45b-610a3884f785" /data/fastdfs ext4 defaults 0 0
#mount -a
#cp init.d/fdfs_storaged /etc/init.d/ (拷贝fdfs_storadged启动脚本到etc下)
#vim /etc/fdfs/storage.conf
7 group_name=group1
37 base_path=/data/fastdfs
42 max_connections=4096
96 store_path_count=1
100 store_path0=/data/fastdfs
109 tracker_server=192.168.4.1:22122
172 upload_priority=10
起服务并验证:
#service fdfs_storaged start; chkconfig fdfs_storaged on
#service fdfs_storaged status
# ls /data/fastdfs/data/00
#netstat -anptu | grep :23000
3)vh03:
1.在storage上配置web访问(vh03加网站模块,上传图片文件)
#yum -y install -y pcre pcre-devel zlib-devel
#useradd -s /sbin/nologin nginx
#cd fdfs_soft/
#tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
#tar -zxvf nginx-1.7.10.tar.gz
#cd nginx-1.7.10
#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --add-module=../fastdfs-nginx-module/src/
#make && make install
#cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
#vim /etc/fdfs/mod_fastdfs.conf
base_path=/data/fastdfs
tracker_server=192.168.4.1:22122
group_name=group1
store_path_count=1
store_path0=/data/fastdfs
#vim /usr/local/nginx/conf/nginx.conf
location / {
# root html;
# index index.html index.htm;
ngx_fastdfs_module;
}
#/usr/local/nginx/sbin/nginx (也可做个链接 #ln -s /usr/lcoal/nginx/sbin/nginx /bin #nginx)
#service fdfs_storaged start;chkconfig fdfs_storaged on
4)vh04:
1.配置storage(vh04存储节点,属于group2组)
#cd fdfs_soft/
#yum -y install gcc libevent *.rpm make
#tar -zxf FastDFS_v4.06.tar.gz
#cd FastDFS
#./make.sh
#./make.sh install
#lsblk
#parted /dev/vdb
mktab gpt
mkpart
primary
ext4
1M
-1
quit
#lsblk
#mkfs.ext4 /dev/vdb1
#blkid /dev/vdb1
#mkdir -p /data/fastdfs
#vim /etc/fstab (永久挂载)
UUID="c8b37f56-7bb5-4c9b-b45b-610a3884f541" /data/fastdfs ext4 defaults 0 0
#mount -a
#cp init.d/fdfs_storaged /etc/init.d/ (拷贝fdfs_storadged启动脚本到etc下)
#vim /etc/fdfs/storage.conf
7 group_name=group2
37 base_path=/data/fastdfs
42 max_connections=4096
96 store_path_count=1
100 store_path0=/data/fastdfs
109 tracker_server=192.168.4.1:22122
172 upload_priority=10
起服务并验证:
#service fdfs_storaged start; chkconfig fdfs_storaged on
#service fdfs_storaged status
# ls /data/fastdfs/data/00
#netstat -anptu | grep :23000
5)vh04:
1.在storage上配置web访问(vh04加网站模块,上传图片文件)
#yum -y install -y pcre pcre-devel zlib-devel
#useradd -s /sbin/nologin nginx
#cd fdfs_soft/
#tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
#tar -zxvf nginx-1.7.10.tar.gz
#cd nginx-1.7.10
#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --add-module=../fastdfs-nginx-module/src/
#make && make install
#cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
#vim /etc/fdfs/mod_fastdfs.conf
base_path=/data/fastdfs
tracker_server=192.168.4.1:22122
group_name=group1
store_path_count=1
store_path0=/data/fastdfs
#vim /usr/local/nginx/conf/nginx.conf
location / {
# root html;
# index index.html index.htm;
ngx_fastdfs_module;
}
#ln -s /usr/lcoal/nginx/sbin/nginx /bin
#nginx
#service fdfs_storaged start;chkconfig fdfs_storaged on
6)测试::
在物理机测试(结果保存第一张图片文件,存储在group1的两个节点,第二在group2节点)
[root@room1pc01 fdfs]# ./fdfs_upload_file client.conf /root/桌面/121.jpg
group1/M00/00/00/wKgEAljPTJuAa39OAACwEV-ILDc227.jpg
[root@vh02 00]# pwd
/data/fastdfs/data/00/00
[root@vh02 00]# ls
wKgEAljPEPGABqmoAAABqYAP-0I1945621_big wKgEAljPHCKAdT4XAADb1hKlWxM275.jpg
wKgEAljPEPGABqmoAAABqYAP-0I1945621_big-m wKgEAljPL1SAJ-PhAAALqve6qZ40251435
wKgEAljPG46AAfv-AACwEV-ILDc994.jpg wKgEAljPTJuAa39OAACwEV-ILDc227.jpg
[root@vh03 00]# pwd
/data/fastdfs/data/00/00
[root@vh03 00]# ls
wKgEAljPEPGABqmoAAABqYAP-0I1945621_big wKgEAljPHCKAdT4XAADb1hKlWxM275.jpg
wKgEAljPEPGABqmoAAABqYAP-0I1945621_big-m wKgEAljPL1SAJ-PhAAALqve6qZ40251435
wKgEAljPG46AAfv-AACwEV-ILDc994.jpg wKgEAljPTJuAa39OAACwEV-ILDc227.jpg
[root@room1pc01 fdfs]# ./fdfs_upload_file client.conf /root/桌面/121.jpg
group2/M00/00/00/wKgEBFjPTxuAGZo4AACwEV-ILDc534.jpg
[root@vh04 00]# pwd
/data/fastdfs/data/00/00
[root@vh04 00]# ls
wKgEBFjPTxuAGZo4AACwEV-ILDc534.jpg
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
本文出自 “12336621” 博客,请务必保留此出处http://12346621.blog.51cto.com/12336621/1908554
标签:分布式存储--->在线服务 服务器 手机访问 虚拟机 支付宝
原文地址:http://12346621.blog.51cto.com/12336621/1908554