如何在centos7中安装配置FasterDFS
admin
2023-01-24 18:00:58
0

简介

FastDFS是一款类Google FS的开源分布式文件系统,它用纯C语言实现,支持Linux、FreeBSD、AIX等UNIX系统。它只能通过专有API对文件进行存取访问,不支持POSIX接口方式,不能mount使用。准确地讲,Google FS以及FastDFS、mogileFS、HDFS、TFS等类Google FS都不是系统级的分布式文件系统,而是应用级的分布式文件存储服务。

FastDFS集群中的Tracker server也可以有多台,Tracker server和Storage server均不存在单点问题。Tracker server之间是对等关系,组内的Storage server之间也是对等关系。传统的Master-Slave结构中的Master是单点,写操作仅针对Master。如果Master失效,需要将Slave提升为Master,实现逻辑会比较复杂。和Master-Slave结构相比,对等结构中所有结点的地位是相同的,每个结点都是Master,不存在单点问题。

一、环境准备

centos7-1 : tracker 192.168.142.66
centos7-2 : storage+nginx 192.168.142.77

二、开始安装

(1)安装libfastcommon服务(所有节点均进行安装)

安装基础环境包
yum -y install libevent  libevent-devel perl  make gcc zlib  zlib-devel pcre pcre-devel  gcc-c++  openssl-devel
安装libfastcommon

[root@storage ~]# wget https://github.com/happyfish200/libfastcommon/archive/V1.0.38.tar.gz
[root@storage ~]# tar zxf V1.0.38.tar.gz -C /opt/
[root@storage ~]# cd /opt/libfastcommon-1.0.38/
编译并建立软链接以方便系统识别

[root@storage libfastcommon-1.0.38]# ./make.sh && ./make.sh install
[root@storage libfastcommon-1.0.38]# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
[root@storage libfastcommon-1.0.38]# ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
[root@storage libfastcommon-1.0.38]# ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so~~

(2)安装FastDFS服务(所有节点均进行安装)

下载安装
[root@storage ~]# wget https://github.com/happyfish200/fastdfs/archive/V5.11.tar.gz
[root@storage ~]# tar zxf V5.11.tar.gz -C /opt/
[root@storage ~]# cd /opt/fastdfs-5.11/
编译

[root@storage fastdfs-5.11]# ./make.sh && ./make.sh install
将模板文件进行更改

[root@storage fastdfs-5.11]# cd /etc/fdfs/              //配置文件模板路径
[root@storage fdfs]# cp tracker.conf.sample tracker.conf
[root@storage fdfs]# cp storage.conf.sample storage.conf
[root@storage fdfs]# cp client.conf.sample client.conf

3)tracker监控端配置

建立数据文件、日志文件存放目录
mkdir -m 755 -p /opt/fastdfs
修改tracker配置文件

[root@tracker ~]# vim /etc/fdfs/tracker.conf
#修改以下配置
port=22122         //tracker服务默认端口22122即可
base_path=/opt/fastdfs      //tracker存储data和log的跟路径,必须提前创建好
http.server_port=8080 //tracker服务器上启动http服务进程,没装忽略
开启服务

[root@tracker ~]# fdfs_trackerd /etc/fdfs/tracker.conf start
[root@tracker ~]# netstat -atnp | grep 22122
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      43776/fdfs_trackerd

[root@tracker ~]# systemctl stop firewalld
[root@tracker ~]# setenforce 0

(4)storage服务端修改

建立数据文件、日志文件存放目录

mkdir -m 755 -p /opt/fastdfs
修改storage配置文件

[root@storage ~]# vim /etc/fdfs/storage.conf
#修改以下配置
group_name=group1        //默认组名,根据实际情况修改
port=23000       //storge默认23000,同一个组的storage端口号必须一致
base_path=/opt/fastdfs          //storage日志文件的根路径
store_path_count=1              //与下径个数相同,默认为1
store_path0=/opt/fastdfs       //提供的存储路径(默认与日志文件存放在一起)
tracker_server=192.168.142.66:22122      //自己的tracker服务器IP(重点!!!)
http.server_port=80            //http访问文件的端口默认为8888,nginx中配置的监听端口保持一致
开启服务

#开启服务(命令支持start|stop|restart)
[root@storage ~]# fdfs_storaged  /etc/fdfs/storage.conf start
[root@storage ~]# netstat -atnp | grep 23000
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      40430/fdfs_storaged

[root@storage ~]# systemctl stop firewalld
[root@storage ~]# setenforce 0
检查是否与tracker监控端关联成功

[root@storage ~]# fdfs_monitor /etc/fdfs/storage.conf
Storage 1:
id = 192.168.142.77
ip_addr = 192.168.142.77 (storage)  ACTIVE
http domain =
......省略

(5)安装nginx服务(storage:192.168.142.77)

这里为了减少虚拟机开启的数量,就在storage端进行nginx的安装

安装nginx及其组件

[root@storage ~]# tar zxf nginx-1.12.0.tar.gz -C /opt/

#下载fastdfs-nginx-module安装包
[root@storage ~]# wget https://github.com/happyfish200/fastdfs-nginx-module/archive/V1.20.tar.gz
[root@storage ~]# tar zxf V1.20.tar.gz -C /opt/
编译&安装

[root@storage ~]# cd /opt/nginx-1.12.0
[root@storage nginx-1.12.0]# ./configure \
--prefix=/usr/local/nginx \
--add-module=/opt/fastdfs-nginx-module-1.20/src/             //fastdfs-nginx-module模块
[root@storage nginx-1.12.0]# make && make install
注意

可能的报错:
/usr/include/fastdfs/fdfs_define.h:15:27: fatal error: common_define.h: No such file or directory

解决方案:
修改fastdfs-nginx-module-1.20/src/config文件,然后重新配置、编译及安装
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
配置fastdfs-nginx-module模块

[root@storage nginx-1.12.0]# cd fastdfs-nginx-module-1.20/src
[root@storage nginx-1.12.0]# cp mod_fastdfs.conf /etc/fdfs/           //移动其配置文件至fdfs目录下

#修改fastdfs-nginx-module模块配置文件mod-fasts.conf
[root@storage nginx-1.12.0]# cd /etc/fdfs
[root@storage fdfs]# vim mod_fastdfs.conf
#检查一下配置
base_path=/opt/fastdfs         //存放数据文件、日志的路径
tracker_server=192.168.142.66:22122    //tracker端的地址(重点!!!)
url_have_group_name = true  //url是否包含group名称
storage_server_port=23000           //需要和storage配置的相同
store_path_count=1              //存储路径个数,需要和store_path个数匹配
store_path0=/opt/fastdfs               //文件存储的位置
修改nginx配置文件

[root@storage fdfs]# vim /usr/local/nginx/conf/nginx.conf
#空行处添加
location ~/M00 {
root /opt/fastdfs/data;
ngx_fastdfs_module;
}
拷贝fastdfs解压目录中的http.conf和mime.types

#不做这步可能会导致报错
[root@storage fdfs]# cd /opt/fastdfs-5.11/conf/
[root@storage conf]# cp mime.types http.conf /etc/fdfs/

(6)修改client端(本次实验即为storage端)

修改配置文件

[root@storage ~]# vim /etc/fdfs/client.conf
#检查以下配置
base_path=/opt/fastdfs     //tracker服务器文件路径
tracker_server=192.168.142.66:22122            //tracker服务器IP地址和端口号
http.tracker_server_port=8080                  // tracker服务器的http端口号,必须和tracker的设置

三、测验

上传测试文件abc.txt

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf   abc.txt

下载文件abc.txt

/usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKiOTV354W2AIf7GAAAAEh4TEws726.txt abc.txt

删除文件abc.txt

fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKiOTV354W2AIf7GAAAAEh4TEws726.txt

上一篇:Docker 常用命令

下一篇:KVM虚拟化

相关内容

热门资讯

德国总理:美国正在被伊朗羞辱 德国之声4月27日报道,德国总理默茨在访问一所学校时表示,在当前的持续冲突中,伊朗领导层正试图羞辱美...
理响中国|“长”歌以行,风云激... 光阴如梭,东方潮阔。这里是中国的长三角,世界的长三角。无论过去、现在还是未来,这片土地都因时代而生,...
白宫:特朗普及其国安团队开会讨... 新华社华盛顿4月27日电 美国白宫新闻秘书莱维特27日在记者会上证实,总统特朗普及其国家安全团队当天...
人民日报刊文:日本放开杀伤性武... 日本放开杀伤性武器出口推高地缘冲突风险(国际论坛)常思纯《人民日报》(2026年04月28日 第 0...
医疗保障法草案二审:明确生育保... 满足多样化健康保障需求本报记者 彭 波4月27日,医疗保障法草案二审稿提请十四届全国人大常委会第二十...
天津一景区发生自转旋翼机事故1... 澎湃新闻记者 吕新文中国民用航空华北地区管理局4月22日公布《豪客通航“10•1”天津长芦汉盐旅游区...
卡塔尔埃米尔与美国总统特朗普通... 当地时间24日,卡塔尔埃米尔塔米姆与美国总统特朗普通电话,重点就中东地区局势以及伊朗与美国谈判问题交...
男子30年前被扣押2859克黄... 澎湃新闻记者 王鑫家住辽宁省大连市的潘永嘉近日向澎湃新闻反映称,三十年前,他在大连周水子机场被盖州市...
商务部:取消反制欧盟两家金融机... 中华人民共和国商务部令二〇二六年 第1号鉴于欧盟已取消对中国两家金融机构的制裁措施,现公布《关于取消...
过去24小时共有5艘船只通过霍... 总台记者当地时间24日获悉,过去24小时内,共有5艘船只通过霍尔木兹海峡,其中包括一艘伊朗油轮。(总...