目录
文章目录
- 2.0 安装软件及版本
- 2.1 安装依赖包
- 2.2 安装libfastcommon
- 2.3 安装fastdfs主程序
- 2.4 fastdfs关联tracker配置
- 2.5 fastdfs关联storage配置
- 2.6 检查fastdfs的tracker与storage是否整合成功
- 2.7 测试fastdfs客户端工具进行文件上传下载
- 3.1 准备fastdfs-nginx-module软件安装包
- 3.2 解压fastdfs-nginx-module软件安装包
- 3.3 修改fastdfs-nginx-module软件安装包里面的config文件
- 4.1 安装nginx(nginx_storage)的依赖库
- 4.2 创建nginx用户
- 4.3 准备并解压nginx(nginx_storage)安装包
- 4.4 编译安装nginx(nginx_storage)
- 4.5 编辑修改nginx(nginx_storage)配置文件
- 4.6 拷贝fastdfs的配置文件
- 4.7 拷贝fastdfs-nginx-module的配置文件mod_fastdfs.conf
- 4.8 编辑拷贝的mod_fastdfs.conf配置文件
- 4.9 创建文件实际存储目录的软链接
- 4.10 启动nginx_storage
- 4.11 测试storage的http访问:浏览器访问ip+http端口号
- 五、配置nginx为tracker server提供http访问接口
- 5.1 安装nginx(nginx_tracker)的依赖库(单机不需要这一步)
- 5.2 重新解压一个nginx(nginx_tracker)安装包
- 5.3 编译安装nginx(nginx_tracker)
- 5.5 编辑修改nginx(nginx_tracker)配置文件
- 5.6 启动nginx_tracker
- 5.7 测试tracker的http访问:浏览器访问ip+http端口号
一、部署的环境准备
1.1 机器准备
一台虚拟机:
hostname: myhost
ip地址: 192.168.2.122
1.2 系统环境
[root@myhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@myhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.122 netmask 255.255.255.0 broadcast 10.199.41.255
inet6 fe80::215:5dff:fe89:cd43 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:89:cd:43 txqueuelen 1000 (Ethernet)
RX packets 1365008 bytes 289565779 (276.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 213902 bytes 207232091 (197.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 7772 bytes 435190 (424.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7772 bytes 435190 (424.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@myhost ~]# getenforce
Enforcing
[root@myhost ~]# setenforce 0
[root@myhost ~]# getenforce
Permissive
[root@myhost ~]# sed -i "s#enforcing#disabled#g" /etc/sysconfig/selinux
[root@myhost ~]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38: icmp_seq=1 ttl=54 time=31.6 ms
64 bytes from 14.215.177.38: icmp_seq=2 ttl=54 time=32.0 ms
64 bytes from 14.215.177.38: icmp_seq=3 ttl=54 time=31.6 ms
64 bytes from 14.215.177.38: icmp_seq=4 ttl=54 time=31.0 ms
二、fastdfs安装及配置
2.0 安装软件及版本
- libfastcommon-1.0.43.tar.gz
- fastdfs-6.06.tar.gz
- fastdfs-nginx-module-1.22.tar.gz
- nginx-1.16.1.tar.gz
2.1 安装依赖包
[root@myhost ~]# yum groupinstall "Development Tools" "Server platform Development" -y
[root@myhost ~]# yum install -y libao*
2.2 安装libfastcommon
2.2.1 准备libfastcommon软件安装包
[root@myhost ~]# cd /home/tools/
[root@myhost tools]# ll
总用量 5526
-rw-r--r--. 1 root root 166526 6月 8 13:27 libfastcommon-1.0.43.tar.gz
2.2.2 解压libfastcommon软件安装包
[root@myhost tools]# tar xf libfastcommon-1.0.43.tar.gz
[root@myhost tools]# cd libfastcommon-1.0.43
[root@myhost libfastcommon-1.0.43]# ll
总用量 40
drwxrwxr-x. 2 root root 4096 12月 25 20:35 doc
-rw-rw-r--. 1 root root 10301 12月 25 20:35 HISTORY
-rw-rw-r--. 1 root root 674 12月 25 20:35 INSTALL
-rw-rw-r--. 1 root root 1607 12月 25 20:35 libfastcommon.spec
-rwxrwxr-x. 1 root root 3253 12月 25 20:35 make.sh #### 编译安装脚本 ####
drwxrwxr-x. 2 root root 4096 12月 25 20:35 php-fastcommon
-rw-rw-r--. 1 root root 2776 12月 25 20:35 README
drwxrwxr-x. 3 root root 4096 12月 25 20:35 src
2.2.3 编译安装libfastcommon
[root@myhost libfastcommon-1.0.43]# ./make.sh && ./make.sh install
[root@myhost libfastcommon-1.0.43]# echo $?
0
[root@myhost libfastcommon-1.0.43]# ls /usr/lib64|grep libfastcommon
libfastcommon.so
[root@myhost libfastcommon-1.0.43]# ls /usr/lib|grep libfastcommon
libfastcommon.so
#至此libfastcommon就已经安装成功了,
#但注意一下: libfastcommon.so 默认安装到了/usr/lib64/libfastcommon.so以及/usr/lib/libfastcommon.so里面了。
2.3 安装fastdfs主程序
2.3.1 准备fastdfs软件安装包
[root@myhost libfastcommon-1.0.43]# cd ../
[root@myhost tools]# ll
总用量 37560
-rwxr-xr-x. 1 root root 809328 6月 9 14:03 fastdfs-6.06.tar.gz
drwxrwxr-x. 5 root root 4096 6月 9 14:14 libfastcommon-1.0.43
-rwxr-xr-x. 1 root root 166526 6月 9 14:03 libfastcommon-1.0.43.tar.gz
2.3.2 解压fastdfs软件安装包
[root@myhost tools]# tar xf fastdfs-6.06.tar.gz
[root@myhost tools]# cd fastdfs-6.06
[root@myhost fastdfs-6.06]# ll
总用量 148
drwxrwxr-x. 3 root root 4096 12月 31 07:36 client
drwxrwxr-x. 2 root root 4096 12月 31 07:36 common
drwxrwxr-x. 2 root root 4096 12月 31 07:36 conf
-rw-rw-r--. 1 root root 35067 12月 31 07:36 COPYING-3_0.txt
drwxrwxr-x. 4 root root 54 12月 31 07:36 docker
-rw-rw-r--. 1 root root 3170 12月 31 07:36 fastdfs.spec
-rw-rw-r--. 1 root root 36881 12月 31 07:36 HISTORY
drwxrwxr-x. 2 root root 26 12月 31 07:36 images
drwxrwxr-x. 2 root root 46 12月 31 07:36 init.d
-rw-rw-r--. 1 root root 8344 12月 31 07:36 INSTALL
-rwxrwxr-x. 1 root root 5517 12月 31 07:36 make.sh #### 编译安装脚本 ####
drwxrwxr-x. 2 root root 4096 12月 31 07:36 php_client
-rw-rw-r--. 1 root root 2448 12月 31 07:36 README.md
-rw-rw-r--. 1 root root 1700 12月 31 07:36 README_zh.md
-rwxrwxr-x. 1 root root 1768 12月 31 07:36 restart.sh
-rwxrwxr-x. 1 root root 763 12月 31 07:36 setup.sh
-rwxrwxr-x. 1 root root 1680 12月 31 07:36 stop.sh
drwxrwxr-x. 4 root root 4096 12月 31 07:36 storage
drwxrwxr-x. 2 root root 4096 12月 31 07:36 test
drwxrwxr-x. 2 root root 4096 12月 31 07:36 tracker
2.3.3 编译安装fastdfs主程序
[root@myhost fastdfs-6.06]# ./make.sh && ./make.sh install
[root@myhost fastdfs-6.06]# echo $?
0
[root@myhost fastdfs-6.06]# ls /usr/bin|grep fdfs
fdfs_appender_test
fdfs_appender_test1
fdfs_append_file
fdfs_crc32
fdfs_delete_file
fdfs_download_file
fdfs_file_info
fdfs_monitor
fdfs_regenerate_filename
fdfs_storaged
fdfs_test
fdfs_test1
fdfs_trackerd
fdfs_upload_appender
fdfs_upload_file
2.3.4 进入fastdfs的配置文件目录/etc/fdfs
[root@myhost fastdfs-6.06]# cd /etc/fdfs/
[root@myhost fdfs]# ll
总用量 32
-rw-r--r--. 1 root root 1909 6月 8 13:40 client.conf.sample
-rw-r--r--. 1 root root 10246 6月 8 13:40 storage.conf.sample
-rw-r--r--. 1 root root 620 6月 8 13:40 storage_ids.conf.sample
-rw-r--r--. 1 root root 9138 6月 8 13:40 tracker.conf.sample
fastdfs主程序安装成功后就会生成如上的3个.sample文件(示例配置文件),我们再分别拷贝出3个以备后面用正式配置的时候用。
[root@myhost fdfs]# cp ./client.conf.sample ./client.conf
[root@myhost fdfs]# cp ./storage.conf.sample ./storage.conf
[root@myhost fdfs]# cp ./tracker.conf.sample ./tracker.conf
[root@myhost fdfs]# ll
总用量 60
-rw-r--r--. 1 root root 1909 6月 8 13:42 client.conf
-rw-r--r--. 1 root root 1909 6月 8 13:40 client.conf.sample
-rw-r--r--. 1 root root 10246 6月 8 13:42 storage.conf
-rw-r--r--. 1 root root 10246 6月 8 13:40 storage.conf.sample
-rw-r--r--. 1 root root 620 6月 8 13:40 storage_ids.conf.sample
-rw-r--r--. 1 root root 9138 6月 8 13:42 tracker.conf
-rw-r--r--. 1 root root 9138 6月 8 13:40 tracker.conf.sample
至此,fastdfs已经安装完毕,接下来的工作就是依次配置tracker和storage了。
2.4 fastdfs关联tracker配置
2.4.1 创建tracker服务器文件存放路径
- 在配置tracker之前,首先需要创建tracker服务器的文件路径,即用于存储tracker的数据文件和日志文件等,
- 这里我选择在/home/fastdfs目录下创建一个fastdfs_tracker目录用于存放tracker服务器的相关文件。
[root@myhost fdfs]# mkdir /home/fastdfs
[root@myhost fdfs]# cd /home/fastdfs/
[root@myhost fastdfs]# mkdir fastdfs_tracker
[root@myhost fastdfs]# ll
总用量 0
drwxr-xr-x. 2 root root 6 6月 8 13:43 fastdfs_tracker
2.4.2 编辑安装fastdfs软件时产生的tracker.conf配置文件
[root@myhost fdfs]# vi /etc/fdfs/tracker.conf
[root@myhost fdfs]# egrep -v "^$|#" /etc/fdfs/tracker.conf
disabled = false #启用配置文件(默认启用)
bind_addr =
port = 22122 #设置tracker的端口号,通常采用22122这个默认端口
connect_timeout = 30
network_timeout = 60
base_path = /home/fastdfs/fastdfs_tracker #设置tracker的数据文件和日志目录
max_connections = 1024
accept_threads = 1
work_threads = 4
min_buff_size = 8KB
max_buff_size = 128KB
store_lookup = 2
store_group = group2
store_server = 0
store_path = 0
download_server = 0
reserved_storage_space = 20%
log_level = info
run_by_group=
run_by_user =
allow_hosts = *
sync_log_buff_interval = 1
check_active_interval = 120
thread_stack_size = 256KB
storage_ip_changed_auto_adjust = true
storage_sync_file_max_delay = 86400
storage_sync_file_max_time = 300
use_trunk_file = false
slot_min_size = 256
slot_max_size = 1MB
trunk_alloc_alignment_size = 256
trunk_free_space_merge = true
delete_unused_trunk_files = false
trunk_file_size = 64MB
trunk_create_file_advance = false
trunk_create_file_time_base = 02:00
trunk_create_file_interval = 86400
trunk_create_file_space_threshold = 20G
trunk_init_check_occupying = false
trunk_init_reload_from_binlog = false
trunk_compress_binlog_min_interval = 86400
trunk_compress_binlog_interval = 86400
trunk_compress_binlog_time_base = 03:00
trunk_binlog_max_backups = 7
use_storage_id = false
storage_ids_filename = storage_ids.conf
id_type_in_filename = id
store_slave_file_use_link = false
rotate_error_log = false
error_log_rotate_time = 00:00
compress_old_error_log = false
compress_error_log_days_before = 7
rotate_error_log_size = 0
log_file_keep_days = 0
use_connection_pool = true
connection_pool_max_idle_time = 3600
http.server_port = 89 #设置tracker服务的http端口号,和tracker-nginx的http端口相关
http.check_alive_interval = 30
http.check_alive_type = tcp
http.check_alive_uri = /status.html
2.4.3 启动fdfs_trackerd服务
[root@myhost fdfs]# /etc/init.d/fdfs_trackerd start
Reloading systemd: [ 确定 ]
Starting fdfs_trackerd (via systemctl): [ 确定 ]
[root@myhost fdfs]# /etc/init.d/fdfs_trackerd status
● fdfs_trackerd.service - LSB: FastDFS tracker server
Loaded: loaded (/etc/rc.d/init.d/fdfs_trackerd; bad; vendor preset: disabled)
Active: active (running) since 一 2020-06-08 13:51:29 CST; 4s ago
Docs: man:systemd-sysv-generator(8)
Process: 1413 ExecStart=/etc/rc.d/init.d/fdfs_trackerd start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/fdfs_trackerd.service
└─1416 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
6月 08 13:51:29 myhost systemd[1]: Starting LSB: FastDFS tracker server...
6月 08 13:51:29 myhost fdfs_trackerd[1413]: Starting FastDFS tracker server:
6月 08 13:51:29 myhost systemd[1]: Started LSB: FastDFS tracker server.
如果启动命令执行成功,那么同时在刚才创建的tracker文件目录/home/fastdfs/fastdfs_tracker中就可以看到启动后新生成的data和logs目录,tracker服务的端口也应当被正常监听,最后再通过netstat命令查看一下端口监听情况:
[root@myhost fdfs]# netstat -lntup |grep fdfs
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 1416/fdfs_trackerd
2.5 fastdfs关联storage配置
2.5.1 创建storage服务器文件存放路径
同理,步骤基本与配置tracker一致,首先是创建storage服务器的文件目录,
需要注意的是同tracker相比多建了一个目录,因为storage还需要一个文件存储路径,用于存放接收的文件。
[root@myhost fdfs]# cd /home/fastdfs/
[root@myhost fastdfs]# mkdir fastdfs_storage fastdfs_storage_data
[root@myhost fastdfs]# ll
总用量 0
drwxr-xr-x. 2 root root 6 6月 8 13:43 fastdfs_storage
drwxr-xr-x. 2 root root 6 6月 8 13:43 fastdfs_storage_data
drwxr-xr-x. 2 root root 6 6月 8 13:43 fastdfs_tracker
2.5.2 编辑安装fastdfs软件时产生的storage.conf配置文件
[root@myhost fdfs]# vi storage.conf
[root@myhost fdfs]# egrep -v "^$|#" /etc/fdfs/storage.conf
disabled=false #启用配置文件(默认启用)
group_name=group1 #组名,根据实际情况修改
bind_addr=
client_bind=true
port=23000 #设置storage的端口号,默认是23000,同一个组的storage端口号必须一致
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/home/fastdfs/fastdfs_storage #设置storage数据文件和日志目录
max_connections=256
buff_size = 256KB
accept_threads=1
work_threads=4
disk_rw_separated = true
disk_reader_threads = 1
disk_writer_threads = 1
sync_wait_msec=50
sync_interval=0
sync_start_time=00:00
sync_end_time=23:59
write_mark_file_freq=500
store_path_count=1 #存储路径个数,需要和store_path个数匹配
store_path0=/home/fastdfs/fastdfs_storage_data #图片文件实际存储路径
subdir_count_per_path=256
tracker_server=192.168.2.122:22122
#tracker 服务器的 IP地址和端口号,
#如果是单机搭建,IP不要写127.0.0.1,否则启动不成功(此处的ip是我的CentOS虚拟机ip,也不是映射的公网地址)
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
file_distribute_path_mode=0
file_distribute_rotate_count=100
fsync_after_written_bytes=0
sync_log_buff_interval=10
sync_binlog_buff_interval=10
sync_stat_file_interval=300
thread_stack_size=512KB
upload_priority=10
if_alias_prefix=
check_file_duplicate=0
file_signature_method=hash
key_namespace=FastDFS
keep_alive=0
use_access_log = false
rotate_access_log = false
access_log_rotate_time=00:00
rotate_error_log = false
error_log_rotate_time=00:00
rotate_access_log_size = 0
rotate_error_log_size = 0
log_file_keep_days = 0
file_sync_skip_invalid_record=false
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.domain_name=
http.server_port=88 #设置storage的http 端口号,和stroage-nginx的http端口相关
2.5.4 启动fdfs_storaged服务器
[root@myhost fdfs]# /etc/init.d/fdfs_storaged start
Starting fdfs_storaged (via systemctl): [ 确定 ]
[root@myhost fdfs]# /etc/init.d/fdfs_storaged status
● fdfs_storaged.service - LSB: FastDFS storage server
Loaded: loaded (/etc/rc.d/init.d/fdfs_storaged; bad; vendor preset: disabled)
Active: active (running) since 二 2020-06-09 14:21:28 CST; 5h 35min ago
Docs: man:systemd-sysv-generator(8)
Process: 21849 ExecStart=/etc/rc.d/init.d/fdfs_storaged start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/fdfs_storaged.service
└─21852 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
6月 09 14:21:28 dscq-122 systemd[1]: Starting LSB: FastDFS storage server...
6月 09 14:21:28 dscq-122 fdfs_storaged[21849]: Starting FastDFS storage server:
6月 09 14:21:28 dscq-122 systemd[1]: Started LSB: FastDFS storage server.
说明:storage服务下的data下有256个1级目录,每级目录下又有256个2级子目录,总共65536个文件,新写的文件会以hash的方式被路由到其中某个子目录下,然后将文件数据直接作为一个本地文件存储到该目录中。那么最后我们再看一下storage服务的端口监听情况。
[root@myhost fdfs]# netstat -lntup |grep fdfs
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 1523/fdfs_trackerd
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 1552/fdfs_storaged
2.6 检查fastdfs的tracker与storage是否整合成功
上面可以看到此时已经正常监听tracker的22122端口和storage的23000端口,至此storage服务器就已经配置完成,确定了storage服务器启动成功后,还有一项工作就是看看storage服务器是否已经登记到tracker服务器(也可以理解为tracker与storage是否整合成功),运行以下命令:
[root@myhost fdfs]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2020-06-08 13:58:56] DEBUG - base_path=/home/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.2.122:22122
group count: 1
Group 1:
group name = group1
disk total space = 148,991 MB
disk free space = 148,279 MB
trunk free space = 0 MB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 88
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
Storage 1:
id = 192.168.2.122
ip_addr = 192.168.2.122 ACTIVE
http domain =
version = 6.06
join time = 2020-06-08 13:56:08
up time = 2020-06-08 13:56:08
total storage = 148,991 MB
free storage = 148,279 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 88
current_write_path = 0
source storage id =
if_trunk_server = 0
connection.alloc_count = 256
connection.current_count = 0
connection.max_count = 0
total_upload_count = 0
success_upload_count = 0
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 = 0
success_set_meta_count = 0
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 = 0
success_upload_bytes = 0
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 = 0
success_file_open_count = 0
total_file_read_count = 0
success_file_read_count = 0
total_file_write_count = 0
success_file_write_count = 0
last_heart_beat_time = 2020-06-08 13:58:39
last_source_update = 1970-01-01 08:00:00
last_sync_update = 1970-01-01 08:00:00
last_synced_timestamp = 1970-01-01 08:00:00
看到192.168.2.122 ACTIVE 字样即可说明storage服务器已经成功登记到了tracker服务器,同理别忘了添加开机启动,打开/etc/rc.d/rc.local并将如下配置追加到文件中:
/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_storaged start
至此,我们就已经完成了fastdfs的全部配置,此时也就可以用客户端工具进行文件上传下载的测试了。
2.7 测试fastdfs客户端工具进行文件上传下载
2.7.1 编辑客户端client.conf配置文件
测试时需要设置客户端的配置文件,编辑/etc/fdfs目录下的client.conf 文件
[root@myhost fdfs]# vi /etc/fdfs/client.conf
[root@myhost fdfs]# egrep -v '^$|#' /etc/fdfs/client.conf
connect_timeout = 5
network_timeout = 60
base_path = /home/fastdfs/fastdfs_tracker #tracker服务器文件路径
tracker_server = 192.168.2.122:22122 #tracker服务IP地址和端口号
log_level = info
use_connection_pool = false
connection_pool_max_idle_time = 3600
load_fdfs_parameters_from_tracker = false
use_storage_id = false
storage_ids_filename = storage_ids.conf
http.tracker_server_port = 89
#tracker 服务的 http.server_port 端口号,必须和tracker配置文件里的设置对应起来
2.7.2 准备需要上传的图片
配置完成后就可以模拟文件上传了,先给/home/tools/目录下放一张图片(202004115.png)
[root@myhost tools]# pwd
/home/tools
[root@myhost tools]# ll 202004115.png
总用量 654264
-rw-r--r--. 1 root root 10467 6月 8 13:27 202004115.png
[root@myhost tools]# ll /usr/bin/fdfs*
-rwxr-xr-x. 1 root root 362380 6月 8 13:40 /usr/bin/fdfs_appender_test
-rwxr-xr-x. 1 root root 362157 6月 8 13:40 /usr/bin/fdfs_appender_test1
-rwxr-xr-x. 1 root root 349045 6月 8 13:40 /usr/bin/fdfs_append_file
-rwxr-xr-x. 1 root root 348657 6月 8 13:40 /usr/bin/fdfs_crc32
-rwxr-xr-x. 1 root root 349072 6月 8 13:40 /usr/bin/fdfs_delete_file
-rwxr-xr-x. 1 root root 349807 6月 8 13:40 /usr/bin/fdfs_download_file
-rwxr-xr-x. 1 root root 349766 6月 8 13:40 /usr/bin/fdfs_file_info
-rwxr-xr-x. 1 root root 369199 6月 8 13:40 /usr/bin/fdfs_monitor
-rwxr-xr-x. 1 root root 349276 6月 8 13:40 /usr/bin/fdfs_regenerate_filename
-rwxr-xr-x. 1 root root 1280576 6月 8 13:40 /usr/bin/fdfs_storaged
-rwxr-xr-x. 1 root root 372292 6月 8 13:40 /usr/bin/fdfs_test
-rwxr-xr-x. 1 root root 367413 6月 8 13:40 /usr/bin/fdfs_test1
-rwxr-xr-x. 1 root root 512595 6月 8 13:40 /usr/bin/fdfs_trackerd
-rwxr-xr-x. 1 root root 349999 6月 8 13:40 /usr/bin/fdfs_upload_appender
-rwxr-xr-x. 1 root root 351019 6月 8 13:40 /usr/bin/fdfs_upload_file
2.7.3 通过执行客户端上传命令尝试上传图片
[root@myhost tools]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/tools/202004115.png
group1/M00/00/00/CscpQF7d1gGAFNLvAAAo4zbLT5g645.png
如果给我们返回了一个路径,就表示我们的文件已经上传成功了,当文件存储到某个子目录后,即认为该文件存储成功,接下来会为该文件生成一个文件名,文件名由group、存储目录、两级子目录、fileid、文件后缀名(由客户端指定,主要用于区分文件类型)拼接而成。同时在之前配置的storage服务器的实际文件存储路径中也可以根据返回的路径找到实际文件。
[root@myhost 00]# pwd
/home/fastdfs/fastdfs_storage_data/data/00/00
[root@myhost 00]# ll
总用量 12
-rw-r--r--. 1 root root 10467 6月 8 14:09 CscpQF7d1gGAFNLvAAAo4zbLT5g645.png
2.7.4 查看上传的图片新的信息
[root@myhost 00]# /usr/bin/fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/CscpQF7d1gGAFNLvAAAo4zbLT5g645.png
GET FROM SERVER: false
file type: normal
source storage id: 0
source ip address: 192.168.2.122
file create timestamp: 2020-06-08 14:09:05
file size: 10467
file crc32: 919293848 (0x36cb4f98)
2.7.5 下载图片
不需要跟保存路径,默认下载到当前目录
[root@myhost 00]# cd /home/tools
[root@myhost tools]# /usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/CscpQF7d1gGAFNLvAAAo4zbLT5g645.png
[root@myhost tools]# ll
总用量 654276
-rw-r--r--. 1 root root 10467 6月 8 13:27 202004115.png
-rw-r--r--. 1 root root 10467 6月 8 14:13 CscpQF7d1gGAFNLvAAAo4zbLT5g645.png
2.7.6 查看存储节点状态
[root@myhost tools]# /usr/bin/fdfs_monitor /etc/fdfs/client.conf
[2020-06-08 14:20:02] DEBUG - base_path=/home/fastdfs/fastdfs_tracker, connect_timeout=5, 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.2.122:22122
group count: 1
Group 1:
group name = group1
disk total space = 148,991 MB
.
.
.
.
.
.
三、安装fastdfs-nginx-module
3.1 准备fastdfs-nginx-module软件安装包
[root@myhost tools]# pwd
/home/tools
[root@myhost tools]# ll
总用量 377856
-rwxr-xr-x. 1 root root 10467 6月 9 14:03 202004115.png
drwxrwxr-x. 12 root root 4096 12月 31 07:36 fastdfs-6.06
-rwxr-xr-x. 1 root root 809328 6月 9 14:03 fastdfs-6.06.tar.gz
-rwxr-xr-x. 1 root root 19952 6月 9 14:03 fastdfs-nginx-module-1.22.tar.gz
drwxrwxr-x. 5 root root 4096 6月 9 14:14 libfastcommon-1.0.43
-rwxr-xr-x. 1 root root 166526 6月 9 14:03 libfastcommon-1.0.43.tar.gz
3.2 解压fastdfs-nginx-module软件安装包
[root@myhost tools]# tar xf fastdfs-nginx-module-1.22.tar.gz
[root@myhost tools]# cd fastdfs-nginx-module-1.22
[root@myhost fastdfs-nginx-module-1.22]# ll
总用量 8
-rw-rw-r--. 1 root root 3036 11月 19 2019 HISTORY
-rw-rw-r--. 1 root root 2001 11月 19 2019 INSTALL
drwxrwxr-x. 2 root root 104 11月 19 2019 src
[root@myhost fastdfs-nginx-module-1.22]# cd src/
[root@myhost src]# pwd
/home/tools/fastdfs-nginx-module-1.22/src
[root@myhost src]# ll
总用量 84
-rw-rw-r--. 1 root root 43507 11月 19 2019 common.c
-rw-rw-r--. 1 root root 3995 11月 19 2019 common.h
-rw-rw-r--. 1 root root 848 11月 19 2019 config
-rw-rw-r--. 1 root root 3725 11月 19 2019 mod_fastdfs.conf
-rw-rw-r--. 1 root root 28668 11月 19 2019 ngx_http_fastdfs_module.c
3.3 修改fastdfs-nginx-module软件安装包里面的config文件
[root@myhost src]# ll /usr/local/include/fast*
ls: 无法访问/usr/local/include/fast*: 没有那个文件或目录
[root@myhost src]# ll -d /usr/include/fast*
drwxr-xr-x. 2 root root 4096 6月 8 13:36 /usr/include/fastcommon
drwxr-xr-x. 2 root root 4096 6月 8 13:40 /usr/include/fastdfs
[root@myhost src]# cat config
ngx_addon_name=ngx_http_fastdfs_module
if test -n "${ngx_module_link}"; then
ngx_module_type=HTTP
ngx_module_name=$ngx_addon_name
ngx_module_incs="/usr/local/include"
ngx_module_libs="-lfastcommon -lfdfsclient"
ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
ngx_module_deps=
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
. auto/module
else
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/local/include" ########需要修改这一行,修改成:/usr/include ##########
CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi
四、配置nginx为storage server提供http访问接口
4.1 安装nginx(nginx_storage)的依赖库
在安装nginx之前需要先安装一些模块依赖的lib库
[root@myhost src]# cd /home/tools/
[root@myhost tools] # yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
4.2 创建nginx用户
[root@myhost nginx-1.16.1]# useradd nginx -s /sbin/nologin -M
[root@myhost nginx-1.16.1]# id nginx
uid=1004(nginx) gid=1004(nginx) 组=1004(nginx)
4.3 准备并解压nginx(nginx_storage)安装包
[root@myhost tools]# tar xf nginx-1.16.1.tar.gz
[root@myhost tools]# cd nginx-1.16.1
[root@myhost nginx-1.16.1]# ll
总用量 756
drwxr-xr-x. 6 test 1001 4096 6月 8 14:29 auto
-rw-r--r--. 1 test 1001 296463 8月 13 2019 CHANGES
-rw-r--r--. 1 test 1001 452171 8月 13 2019 CHANGES.ru
drwxr-xr-x. 2 test 1001 4096 6月 8 14:29 conf
-rwxr-xr-x. 1 test 1001 2502 8月 13 2019 configure
drwxr-xr-x. 4 test 1001 68 6月 8 14:29 contrib
drwxr-xr-x. 2 test 1001 38 6月 8 14:29 html
-rw-r--r--. 1 test 1001 1397 8月 13 2019 LICENSE
drwxr-xr-x. 2 test 1001 20 6月 8 14:29 man
-rw-r--r--. 1 test 1001 49 8月 13 2019 README
drwxr-xr-x. 9 test 1001 84 6月 8 14:29 src
4.4 编译安装nginx(nginx_storage)
[root@myhost nginx-1.16.1]#
./configure --user=nginx \
--group=nginx \
--prefix=/usr/local/nginx_storage \
--with-http_ssl_module \
--with-http_stub_status_module \
--add-module=/home/tools/fastdfs-nginx-module-1.22/src
[root@myhost nginx-1.16.1]# echo $?
0
[root@myhost nginx-1.16.1]# make && make install
[root@myhost nginx-1.16.1]# echo $?
0
4.5 编辑修改nginx(nginx_storage)配置文件
[root@myhost nginx-1.16.1]# cd /usr/local/nginx_storage/conf/
[root@myhost conf]# vi nginx.conf
[root@myhost conf]# egrep -v "#|^$" nginx.conf
use root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 88; #这里修改成storage服务的http.server_port=8888
server_name localhost;
location / {
if ($args ~ type=download){
add_header Content-Disposition "attachment;";
}
root /home/fastdfs/fastdfs_storage_data/data; #文件实际存储路径
ngx_fastdfs_module; #模块名称
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@myhost conf]# chown -R nginx:nginx /usr/local/nginx_storage
4.6 拷贝fastdfs的配置文件
将Fastdfs软件包里面的http.conf和mime.types拷贝到/etc/fdfs目录下。
[root@myhost conf]# cd /home/tools
[root@myhost tools]# cp -r /home/tools/fastdfs-6.06/conf/http.conf /etc/fdfs/
[root@myhost tools]# cp -r /home/tools/fastdfs-6.06/conf/mime.types /etc/fdfs/
4.7 拷贝fastdfs-nginx-module的配置文件mod_fastdfs.conf
[root@myhost tools]# cp -r /home/tools/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
[root@myhost src]# cd /etc/fdfs/
[root@myhost fdfs]# ll
总用量 84
-rw-r--r--. 1 root root 337 6月 8 14:01 client.conf
-rw-r--r--. 1 root root 1909 6月 8 13:40 client.conf.sample
-rw-r--r--. 1 root root 965 6月 8 14:40 http.conf
-rw-r--r--. 1 root root 31172 6月 8 14:41 mime.types
-rw-r--r--. 1 root root 3725 6月 8 14:44 mod_fastdfs.conf
-rw-r--r--. 1 root root 1287 6月 8 13:54 storage.conf
-rw-r--r--. 1 root root 10246 6月 8 13:40 storage.conf.sample
-rw-r--r--. 1 root root 620 6月 8 13:40 storage_ids.conf.sample
-rw-r--r--. 1 root root 1621 6月 8 13:55 tracker.conf
-rw-r--r--. 1 root root 9138 6月 8 13:40 tracker.conf.sample
4.8 编辑拷贝的mod_fastdfs.conf配置文件
[root@myhost fdfs]# vi /etc/fdfs/mod_fastdfs.conf
[root@myhost fdfs]# egrep -v '^$|#' /etc/fdfs/mod_fastdfs.conf
#include http.conf #这一行必须存在,导入引用文件
connect_timeout=2
network_timeout=30
base_path=/home/fastdfs/fastdfs_storage #设置storage数据文件和日志目录
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=192.168.2.122:22122 #tracker服务的IP地址以及端口号
storage_server_port=23000 #storage服务的端口号
group_name=group1
url_have_group_name = true #文件url 中是否有 group 名
store_path_count=1
store_path0=/home/fastdfs/fastdfs_storage_data #文件实际存储路径
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 3 #设置组的个数,默认为0,事实上这次只使用了group1
#接下来就需要在文件尾部追加这3个group setting:
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/fastdfs/fastdfs_storage_data
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/home/fastdfs/fastdfs_storage_data
[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/home/fastdfs/fastdfs_storage_data
4.9 创建文件实际存储目录的软链接
访问后面的目录就相当于访问前面的目录
#ln -s /home/fastdfs/fastdfs_storage_data/data /home/fastdfs/fastdfs_storage_data/data/M00
ln -s /home/fastdfs/fastdfs_storage_data /home/fastdfs/fastdfs_storage_data/M00
4.10 启动nginx_storage
[root@myhost local]# /usr/local/nginx_storage/sbin/nginx -t #检查语法
ngx_http_fastdfs_set pid=21835
nginx: the configuration file /usr/local/nginx_storage/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx_storage/conf/nginx.conf test is successful
[root@myhost local]# /usr/local/nginx_storage/sbin/nginx
ngx_http_fastdfs_set pid=5049
[root@myhost local]# netstat -lntup |grep nginx
tcp 0 0 0.0.0.0:88 0.0.0.0:* LISTEN 5050/nginx: master
4.11 测试storage的http访问:浏览器访问ip+http端口号
[root@myhost local]# firewall-cmd --zone=public --permanent --add-port=23000/tcp && firewall-cmd --reload
success
success
[root@myhost local]# firewall-cmd --zone=public --permanent --add-port=22122/tcp && firewall-cmd --reload
success
success
[root@myhost local]# firewall-cmd --zone=public --permanent --add-port=88/tcp && firewall-cmd --reload
success
success
[root@myhost local]# firewall-cmd --zone=public --permanent --add-port=89/tcp && firewall-cmd --reload
success
success
访问地址:http://192.168.2.122:88/group1/M00/00/00/CscpQF7d1gGAFNLvAAAo4zbLT5g645.png
五、配置nginx为tracker server提供http访问接口
5.1 安装nginx(nginx_tracker)的依赖库(单机不需要这一步)
[root@myhost ~]# yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
- 1
5.2 重新解压一个nginx(nginx_tracker)安装包
[root@myhost src]# cd /home/tools/
[root@myhost tools]# tar xf nginx-1.16.1.tar.gz
[root@myhost tools]# cd nginx-1.16.1
[root@myhost nginx-1.16.1]# ll
总用量 756
drwxr-xr-x. 6 test 1001 4096 6月 8 14:29 auto
-rw-r--r--. 1 test 1001 296463 8月 13 2019 CHANGES
-rw-r--r--. 1 test 1001 452171 8月 13 2019 CHANGES.ru
drwxr-xr-x. 2 test 1001 4096 6月 8 14:29 conf
-rwxr-xr-x. 1 test 1001 2502 8月 13 2019 configure
drwxr-xr-x. 4 test 1001 68 6月 8 14:29 contrib
drwxr-xr-x. 2 test 1001 38 6月 8 14:29 html
-rw-r--r--. 1 test 1001 1397 8月 13 2019 LICENSE
drwxr-xr-x. 2 test 1001 20 6月 8 14:29 man
-rw-r--r--. 1 test 1001 49 8月 13 2019 README
drwxr-xr-x. 9 test 1001 84 6月 8 14:29 src
5.3 编译安装nginx(nginx_tracker)
[root@myhost nginx-1.16.1]#
./configure --user=nginx \
--group=nginx \
--prefix=/usr/local/nginx_tracker \
--with-http_ssl_module \
--with-http_stub_status_module \
--add-module=/home/tools/fastdfs-nginx-module-1.22/src
[root@myhost nginx-1.16.1]# echo $?
0
[root@myhost nginx-1.16.1]# make && make install
[root@myhost nginx-1.16.1]# echo $?
0
5.5 编辑修改nginx(nginx_tracker)配置文件
tracker服务的nginx修改listen端口为tracker配置文件中的http.server_port=89端口,并将upstream指向storage的nginx地址。
[root@myhost nginx-1.16.1]# cd /usr/local/nginx_tracker/conf/
[root@myhost conf]# egrep -v "#|^$" nginx.conf
user root;
worker_processes 1;
events {
worker_connections 102400;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
upstream fdfs_group1 {
server 127.0.0.1:88; #负载均衡是访问的实际地址是storage的http.server_port:88
}
server {
listen 89; #tracker服务的http端口号,访问这个端口的时候会自动去访问上面负载的实际地址storage_nginx的http地址。
server_name localhost;
location /group1/M00 {
proxy_pass http://fdfs_group1;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@myhost conf]# chown -R nginx:nginx /usr/local/nginx_tracker
5.6 启动nginx_tracker
[root@myhost conf]# /usr/local/nginx_tracker/sbin/nginx -t
nginx: the configuration file /usr/local/nginx_tracker/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx_tracker/conf/nginx.conf test is successful
[root@myhost conf]# /usr/local/nginx_tracker/sbin/nginx
[root@myhost conf]# netstat -lntup |grep nginx
tcp 0 0 0.0.0.0:88 0.0.0.0:* LISTEN 3279/nginx: master
tcp 0 0 0.0.0.0:89 0.0.0.0:* LISTEN 6458/nginx: master
5.7 测试tracker的http访问:浏览器访问ip+http端口号
http://192.168.2.122:89/group1/M00/00/00/CscpQF7d1gGAFNLvAAAo4zbLT5g645.png
http://192.168.2.122:88/group1/M00/00/00/CscpQF7d1gGAFNLvAAAo4zbLT5g645.png