【转载】https://blog.csdn.net/m0_37797991/article/details/73381739
链接:
第一篇:FastDFS 详细介绍
第三篇:FastDFS 整合 nginx
第四篇:整合 Java Spring MVC 上传
1.CentOS7FastDFS 搭建
前面已下载好了要用到的工具集,下面就可以开始安装了:
如果安装过程中出现问题,可以下载我提供的,当前测试可以通过的工具包:
fastdfs-5.11 下载
fastdfs-client-java-1.26 下载
fastdfs-nginx-module-1.20 下载
libfastcommon-1.36 下载
nginx-1.12.0 下载
请大家原谅我可耻的收了一分,写这么长的博文确实是很辛苦的,要花很长时间。如果觉得这篇博文帮忙到了你,还请帮忙下载支持一下。您的鼓励将成为我最大的动力。当然,作者的 GitHub 地址已提供给大家,大家可以去 GitHub 下载。
1.1 安装 libfastcommon
由于我的 centOS7 是最小化安装,我里面没有安装 zip 解压。
先安装 :
yum -y install unzip zip
安装成功后解压 libfastcommon-master.zip
unzip libfastcommon-master.zip
进入我们刚刚解压的目录:
[root@localhost ftp]# cd libfastcommon-master
[root@localhost libfastcommon-master]# ll
total 32
drwxr-xr-x 2 root root 117 Apr 5 18:07 doc
-rw-r--r-- 1 root root 8005 Apr 5 18:07 HISTORY
-rw-r--r-- 1 root root 566 Apr 5 18:07 INSTALL
-rw-r--r-- 1 root root 1606 Apr 5 18:07 libfastcommon.spec
-rwxr-xr-x 1 root root 3099 Apr 5 18:07 make.sh
drwxr-xr-x 2 root root 191 Apr 5 18:07 php-fastcommon
-rw-r--r-- 1 root root 2763 Apr 5 18:07 README
drwxr-xr-x 3 root root 4096 Jun 8 21:51 src
当我们./make.sh 的时候会提示,gcc 命令没有找到。
用 yum 安装 gcc:
yum 命令相当好用,是 RedHad 和 CentOS 从指定服务器下载 RPM 包并自动安装。我个人比较喜欢。
yum -y install gcc-c++
这个时候分别执行./make.sh 和./make.sh install,正常情况是可以成功的。
libfastcommon 默认会被安装到/usr/lib64/libfastcommon.so 但是 FastDFS 的主程序却在/usr/local/lib 目录下
这个时候我们就要建立一个软链接了,实际上也相当于 windows 上的快捷方式。
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
1.2 安装 FastDFS
解压 FastDFS 安装包
unzip fastdfs-5.11.zip
解压后看到:
[root@localhost ftp]# ls
593d8f1eN5b3b8133.jpg libfastcommon-master
fastdfs-5.11 libfastcommon-master.zip
fastdfs-5.11.zip nginx-1.12.0.tar.gz
fastdfs-client-java-master.zip record.txt
fastdfs-nginx-module-master.zip zookeeper-3.4.6.tar.gz
进到刚解压的目录
cd fastdfs-5.11
./make.sh
./make.sh install
如果没有报错那么就成功了。安装 log 中会提示 FastDFS 安装到了/etc/fdfs 目录下。
成功后查看安装目录:
[root@localhost ftp]# cd /etc/fdfs/
[root@localhost fdfs]# ll
-rw-r--r-- 1 root root 1461 Jun 8 21:56 client.conf.sample
-rw-r--r-- 1 root root 7927 Jun 8 21:56 storage.conf.sample
-rw-r--r-- 1 root root 7389 Jun 8 21:56 tracker.conf.sample
我们需要把这三个示例文件复制一份,去掉.sample。
cp client.conf.sample client.conf
cp storage.conf.sample storage.conf
cp tracker.conf.sample tracker.conf
FastDFS 安装结束。
1.3 安装 tracker
1.3.1 创建 tracker 工作目录
这个目录可以自定义,用来保存 tracker 的 data 和 log
根据个人习惯,我创建了下面的目录:
[root@localhost ~]# cd /usr/
[root@localhost usr]# mkdir yong.cao
[root@localhost usr]# cd yong.cao/
[root@localhost yong.cao]# mkdir dev
[root@localhost yong.cao]# cd dev/
[root@localhost dev]# mkdir fastdfs
[root@localhost yong.cao]# cd fastdfs/
[root@localhost dev]# mkdir fastdfs_tracker
[root@localhost fastdfs]# cd fastdfs_tracker/
[root@localhost fastdfs_tracker]# pwd
/usr/yong.cao/dev/fastdfs/fastdfs_tracker #这个是我最终创建的目录
[root@localhost fastdfs_tracker]#
1.3.2 配置 tracker
cd /etc/fdfs
vim tracker.conf
最小化的 CentOS7 是没有安装 vim 的,可以把 vim tracker.conf 命令改成 vi tracker.conf,也可以去下载一个 vim
yum -y install vim #简单粗暴安装方法
打开后重点关注下面 4 个配置:
- disabled=false #默认开启
- port=22122 #默认端口号
- base_path=/usr/yong.cao/dev/fastdfs/fastdfs_tracker #我刚刚创建的目录
- http.server_port=6666 #默认端口是 8080
1.3.3 启动 tracker
保存配置后启动 tracker,命令如下:
service fdfs_trackerd start
如果不能启动,或提示用 systemctl 可改用命令:
systemctl start fdfs_trackerd
成功后应该可以看到:
[root@localhost fdfs]# service fdfs_trackerd start
Starting fdfs_trackerd (via systemctl): [ OK ]
进行刚刚创建的 tracker 目录,发现目录中多了 data 和 log 两个目录
[root@localhost fdfs]# cd /usr/yong.cao/dev/fastdfs/fastdfs_tracker/
[root@localhost fastdfs_tracker]# ll
total 0
drwxr-xr-x 2 root root 178 Jun 16 21:19 data
drwxr-xr-x 2 root root 26 Jun 13 22:01 logs
最后我们需要给 tracker 加入开机启动
[root@localhost fastdfs_tracker]# ll /etc/rc.d/rc.local
-rw-r--r-- 1 root root 501 Jun 16 21:34 /etc/rc.d/rc.local
发现并没有执行权限,需要加一下:
chmod +x /etc/rc.d/rc.local
加完后应该是这样的:
-rwxr-xr-x 1 root root 501 Jun 16 21:34 /etc/rc.d/rc.local
修改rc.local
vim /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
service fdfs_trackerd start
查看一下 tracker 的端口监听情况
[root@localhost fastdfs_tracker]# netstat -unltp|grep fdfs
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 2231/fdfs_trackerd
端口 22122 成功监听。
1.4 安装 storage
storage 的安装与 tracker 很类似。
1.4.1 为 storage 配置工作目录
与 tracker 不现的是,由于 storage 还需要一个目录用来存储数据,所以我另外多建了一个 fasdfs_storage_data
下面是我的目录结构:
[root@localhost fastdfs]# ls
fastdfs_storage fastdfs_storage_data fastdfs_tracker
1.4.2 修改 storage 配置文件
修改 storage.conf
vim /etc/fdfs/storage.conf
- disabled=false
- group_name=group1 #组名,根据实际情况修改
- port=23000 #设置 storage 的端口号,默认是 23000,同一个组的 storage 端口号必须一致
- base_path=/usr/yong.cao/dev/fastdfs/fastdfs_storage #设置 storage 数据文件和日志目录
- store_path_count=1 #存储路径个数,需要和 store_path 个数匹配
- base_path0=/usr/yong.cao/dev/fastdfs/fastdfs_storage_data #实际文件存储路径
- tracker_server=192.168.128.131:22122 #我 CentOS7 的 ip 地址
- http.server_port=8888 #设置 http 端口号
修改保存后创建软引用
ln -s /usr/bin/fdfs_storaged /usr/local/bin
1.4.3 启动 storage
service fdfs_storaged start
如果不能启动,或提示用 systemctl 可改用命令:
systemctl start fdfs_storaged
成功后应该可以看到:
[root@localhost fdfs]# service fdfs_stroaged start
Starting fdfs_storaged (via systemctl): [ OK ]
同样的,设置开机启动:
修改 rc.local
vim /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
service fdfs_trackerd start
service fdfs_storaged start
查看一下服务是否启动
[root@localhost fastdfs]# netstat -unltp | grep fdfs
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 2231/fdfs_trackerd
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 2323/fdfs_storaged
服务已正常启动。
1.4.4 校验整合
到这里,fastdfs 的东西都已安装完成,最后我们还要确定一下,storage 是否注册到了 tracker 中去。
查看命令:
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
成功后可以看到:
p_addr = 192.168.128.131 (localhost.localdomain) ACTIVE
[root@localhost fastdfs]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2017-06-17 14:15:44] DEBUG - base_path=/usr/yong.cao/dev/fastdfs/fastdfs_storage, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
server_count=1, server_index=0
tracker server is 192.168.128.131:22122
group count: 1
Group 1:
group name = group1
disk total space = 8178 MB
disk free space = 6463 MB
trunk free space = 0 MB
storage server count = 2
active server count = 1
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
Storage 1:
id = 192.168.128.131
ip_addr = 192.168.128.131 (localhost.localdomain) ACTIVE
http domain =
version = 5.11
join time = 2017-06-13 22:19:42
up time = 2017-06-16 21:19:47
total storage = 8178 MB
free storage = 6463 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 8888
current_write_path = 0
source storage id =
if_trunk_server = 0
connection.alloc_count = 256
connection.current_count = 0
connection.max_count = 1
total_upload_count = 6
success_upload_count = 6
total_append_count = 0
success_append_count = 0
total_modify_count = 0
success_modify_count = 0
total_truncate_count = 0
success_truncate_count = 0
total_set_meta_count = 5
success_set_meta_count = 5
total_delete_count = 0
success_delete_count = 0
total_download_count = 0
success_download_count = 0
total_get_meta_count = 0
success_get_meta_count = 0
total_create_link_count = 0
success_create_link_count = 0
total_delete_link_count = 0
success_delete_link_count = 0
total_upload_bytes = 590790
success_upload_bytes = 590790
total_append_bytes = 0
success_append_bytes = 0
total_modify_bytes = 0
success_modify_bytes = 0
stotal_download_bytes = 0
success_download_bytes = 0
total_sync_in_bytes = 0
success_sync_in_bytes = 0
total_sync_out_bytes = 0
success_sync_out_bytes = 0
total_file_open_count = 6
success_file_open_count = 6
total_file_read_count = 0
success_file_read_count = 0
total_file_write_count = 6
success_file_write_count = 6
last_heart_beat_time = 2017-06-17 14:15:27
last_source_update = 2017-06-16 23:34:20
last_sync_update = 1970-01-01 08:00:00
last_synced_timestamp = 1970-01-01 08:00:00
[root@localhost fastdfs]#
本博文结束。接下来的第三篇会讲到文件上传的简单测试及整合 nginx 模块。
————————————————
版权声明:本文为 CSDN 博主「MrCao 杰罗尔德」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_37797991/article/details/73381739
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于