本次安装的版本是目前最新版本Version 5.11 2017-05-26,基于centos7+
所需安装包在附件中,版本如下:
- fastdfs-5.11
- fastdfs-nginx-module-1.20
- libfastcommon-1.36
- nginx-1.12.0
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 -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个配置:
1.disabled=false #默认开启
2.port=22122 #默认端口号
3.base_path=/usr/yong.cao/dev/fastdfs/fastdfs_tracker #我刚刚创建的目录
4.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
1.disabled=false
2.group_name=group1 #组名,根据实际情况修改
3.port=23000 #设置storage的端口号,默认是23000,同一个组的storage端口号必须一致
4.base_path=/usr/yong.cao/dev/fastdfs/fastdfs_storage #设置storage数据文件和日志目录
5.store_path_count=1 #存储路径个数,需要和store_path个数匹配
6.base_path0=/usr/yong.cao/dev/fastdfs/fastdfs_storage_data #实际文件存储路径
7.tracker_server=192.168.128.131:22122 #我CentOS7的ip地址
8.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
成功后可以看到:
ip_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]#
2.测试
前面两篇博文已对FastDFS的安装和配置,做了比较详细的讲解。FastDFS的基础模块都搭好了,现在开始测试下载。
2.1 配置客户端
同样的,需要修改客户端的配置文件:
vim /etc/fdfs/client.conf
- base_path=/usr/yong.cao/dev/fastdfs/fastdfs_tracker #tracker服务器文件路径
- tracker_server=192.168.128.131:22122 #tracker服务器IP地址和端口号
- http.tracker_server_port=6666 # tracker 服务器的 http端口号,必须和tracker的设置对应起来
通过ftp上传图片到CentOS:
img在我的windows上,我随便拖了一张图片上去。
[root@localhost ~]# ll /usr/yong.cao/ftp/
total 19320
-rw-r--r-- 1 root root 88623 Jun 13 22:33 593d8f1eN5b3b8133.jpg
drwxr-xr-x 10 root root 258 Jun 14 01:26 fastdfs-5.11
-rw-r--r-- 1 root root 421773 Jun 17 09:34 fastdfs-5.11.zip
-rw-r--r-- 1 root root 75491 Jun 17 09:34 fastdfs-client-java-master.zip
-rw-r--r-- 1 root root 22192 Jun 17 09:34 fastdfs-nginx-module-master.zip
drwxr-xr-x 5 root root 135 Jun 8 21:51 libfastcommon-master
-rw-r--r-- 1 root root 478888 Jun 17 09:34 libfastcommon-master.zip
-rw-r--r-- 1 root root 980831 Jun 17 09:34 nginx-1.12.0.tar.gz
-rw-r--r--. 1 root root 150 Jun 4 12:19 record.txt
-rw-r--r--. 1 root root 17699306 Jun 4 13:32 zookeeper-3.4.6.tar.gz
1.2 模拟上传
确定图片位置后,我们输入上传图片命令:
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/yong.cao/ftp/593d8f1eN5b3b8133.jpg #这后面放的是图片的位置
成功后会返回图片的路径:
[root@localhost ~]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/yong.cao/ftp/593d8f1eN5b3b8133.jpg
group1/M00/00/00/wKiAg1lE9WqAWu_ZAAFaL_xdW_s943.jpg
组名:group1
磁盘:M00
目录:00/00
文件名称:wKiAg1lE9WqAWu_ZAAFaL_xdW_s943.jpg
我们上传的图片会被上传到我们创建的storage_data目录下,让我们去看看:
[root@localhost fastdfs_storage_data]# cd /usr/yong.cao/dev/fastdfs/fastdfs_storage_data/data
[root@localhost data]# ls
00 0D 1A 27 34 41 4E 5B 68 75 82 8F 9C A9 B6 C3 D0 DD EA F7
01 0E 1B 28 35 42 4F 5C 69 76 83 90 9D AA B7 C4 D1 DE EB F8
02 0F 1C 29 36 43 50 5D 6A 77 84 91 9E AB B8 C5 D2 DF EC F9
03 10 1D 2A 37 44 51 5E 6B 78 85 92 9F AC B9 C6 D3 E0 ED FA
04 11 1E 2B 38 45 52 5F 6C 79 86 93 A0 AD BA C7 D4 E1 EE FB
05 12 1F 2C 39 46 53 60 6D 7A 87 94 A1 AE BB C8 D5 E2 EF FC
06 13 20 2D 3A 47 54 61 6E 7B 88 95 A2 AF BC C9 D6 E3 F0 FD
07 14 21 2E 3B 48 55 62 6F 7C 89 96 A3 B0 BD CA D7 E4 F1 FE
08 15 22 2F 3C 49 56 63 70 7D 8A 97 A4 B1 BE CB D8 E5 F2 FF
09 16 23 30 3D 4A 57 64 71 7E 8B 98 A5 B2 BF CC D9 E6 F3 M00
0A 17 24 31 3E 4B 58 65 72 7F 8C 99 A6 B3 C0 CD DA E7 F4
0B 18 25 32 3F 4C 59 66 73 80 8D 9A A7 B4 C1 CE DB E8 F5
0C 19 26 33 40 4D 5A 67 74 81 8E 9B A8 B5 C2 CF DC E9 F6
[root@localhost data]# cd 00
[root@localhost 00]# ls
00 0D 1A 27 34 41 4E 5B 68 75 82 8F 9C A9 B6 C3 D0 DD EA F7
01 0E 1B 28 35 42 4F 5C 69 76 83 90 9D AA B7 C4 D1 DE EB F8
02 0F 1C 29 36 43 50 5D 6A 77 84 91 9E AB B8 C5 D2 DF EC F9
03 10 1D 2A 37 44 51 5E 6B 78 85 92 9F AC B9 C6 D3 E0 ED FA
04 11 1E 2B 38 45 52 5F 6C 79 86 93 A0 AD BA C7 D4 E1 EE FB
05 12 1F 2C 39 46 53 60 6D 7A 87 94 A1 AE BB C8 D5 E2 EF FC
06 13 20 2D 3A 47 54 61 6E 7B 88 95 A2 AF BC C9 D6 E3 F0 FD
07 14 21 2E 3B 48 55 62 6F 7C 89 96 A3 B0 BD CA D7 E4 F1 FE
08 15 22 2F 3C 49 56 63 70 7D 8A 97 A4 B1 BE CB D8 E5 F2 FF
09 16 23 30 3D 4A 57 64 71 7E 8B 98 A5 B2 BF CC D9 E6 F3
0A 17 24 31 3E 4B 58 65 72 7F 8C 99 A6 B3 C0 CD DA E7 F4
0B 18 25 32 3F 4C 59 66 73 80 8D 9A A7 B4 C1 CE DB E8 F5
0C 19 26 33 40 4D 5A 67 74 81 8E 9B A8 B5 C2 CF DC E9 F6
[root@localhost 00]# cd 00
[root@localhost 00]# ls
wKiAg1lE9WqAWu_ZAAFaL_xdW_s943.jpg
果然通过刚刚返回的路径,我们成功找到了图片。
我们仔细看一下,实际文件存储路径下有创建好的多级目录。data下有256个1级目录,每级目录下又有256个2级子目录,总共65536个文件,新写的文件会以hash的方式被路由到其中某个子目录下,然后将文件数据直接作为一个本地文件存储到该目录中。
1.3 HTTP访问文件
我们去浏览器用http请求访问一下刚刚的图片:
这里写图片描述
我们发现,http不能直接访问到图片。这是为什么呢。
我去官网看了一原码,在HISTORY中发现,原来早在4.05的时候,就remove embed HTTP support
Version 4.05 2012-12-30
* client/fdfs_upload_file.c can specify storage ip port and store path index
* add connection pool
* client load storage ids config
* common/ini_file_reader.c does NOT call chdir
* keep the mtime of file same
* use g_current_time instead of call time function
* remove embed HTTP support
1.4 HTTP请求不能访问文件的原因
我们在使用FastDFS部署一个分布式文件系统的时候,通过FastDFS的客户端API来进行文件的上传、下载、删除等操作。同时通过FastDFS的HTTP服务器来提供HTTP服务。但是FastDFS的HTTP服务较为简单,无法提供负载均衡等高性能的服务,所以FastDFS的开发者——淘宝的架构师余庆同学,为我们提供了Nginx上使用的FastDFS模块(也可以叫FastDFS的Nginx模块)。
FastDFS通过Tracker服务器,将文件放在Storage服务器存储,但是同组之间的服务器需要复制文件,有延迟的问题.假设Tracker服务器将文件上传到了192.168.128.131,文件ID已经返回客户端,这时,后台会将这个文件复制到192.168.128.131,如果复制没有完成,客户端就用这个ID在192.168.128.131取文件,肯定会出现错误。这个fastdfs-nginx-module可以重定向连接到源服务器取文件,避免客户端由于复制延迟的问题,出现错误。
正是这样,FastDFS需要结合nginx,所以取消原来对HTTP的直接支持。
3. FastDFS的nginx模块安装
3.1安装nginx准备
安装需要的工具,之前就已经放到了ftp:
[root@localhost dev]# cd /usr/yong.cao/ftp/
[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
在安装nginx之前要安装nginx所需的依赖lib:
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
3.2 安装nginx并添加fastdfs-nginx-module
解压nginx,和fastdfs-nginx-module:
tar -zxvf nginx-1.12.0.tar.gz
unzip fastdfs-nginx-module-master.zip
解压后进入nginx目录编译安装nginx,并添加fastdfs-nginx-module:
./configure --prefix=/usr/local/nginx --add-module=/usr/yong.cao/dev/nginx/fastdfs-nginx-module-master/src #解压后fastdfs-nginx-module所在的位置
如果配置不报错的话,就开始编译:
make
make install
如果报错的话,很可能是版本的原因,在我的第二篇博文中提供了我测试成功不报错的版本下载。
nginx的默认目录是/usr/local/nginx,安装成功后查看:
[root@localhost nginx-1.12.0]# cd /usr/local/nginx
[root@localhost nginx]# ll
total 0
drwx------ 2 nobody root 6 Jun 14 01:58 client_body_temp
drwxr-xr-x 2 root root 333 Jun 16 21:42 conf
drwx------ 2 nobody root 6 Jun 14 01:58 fastcgi_temp
drwxr-xr-x 2 root root 40 Jun 14 01:31 html
drwxr-xr-x 2 root root 58 Jun 15 22:21 logs
drwx------ 2 nobody root 6 Jun 14 01:58 proxy_temp
drwxr-xr-x 2 root root 19 Jun 14 01:31 sbin
drwx------ 2 nobody root 6 Jun 14 01:58 scgi_temp
drwx------ 2 nobody root 6 Jun 14 01:58 uwsgi_temp
3.3 配置storage nginx
修改nginx.conf:
[root@localhost nginx]# cd conf/
[root@localhost conf]# ls
fastcgi.conf koi-win scgi_params
fastcgi.conf.default mime.types scgi_params.default
fastcgi_params mime.types.default uwsgi_params
fastcgi_params.default nginx.conf uwsgi_params.default
koi-utf nginx.conf.default win-utf
[root@localhost conf]# vim nginx.conf
单机版使用 一个 ngxin
作用
1.监听 stroge web服务
2.反向代理,提供对外80端口。
修改监听端口 listen 8888, 新增location, 再增加 反向代理,此处可以配置ng的负载均衡
# 监听 8888 端口
server {
listen 8888;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location ~/group([0-9])/M00 {
root /usr/yong.cao/dev/fastdfs/fastdfs_storage_data/data;
ngx_fastdfs_module;
}
location = /50x.html {
root html;
}
}
# 此处可以负载,只有一个组 只配置一个即可
upstream fdfs_group1 {
server 192.168.177.200:8888;
}
server {
listen 80;
server_name localhost;
location /group1/M00 {
proxy_pass http://fdfs_group1;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
然后进入FastDFS安装时的解压过的目录,将http.conf和mime.types拷贝到/etc/fdfs目录下:
[root@localhost fastdfs-5.11]# cd /usr/yong.cao/ftp/fastdfs-5.11/conf/
[root@localhost conf]# ls
anti-steal.jpg http.conf storage.conf tracker.conf
client.conf mime.types storage_ids.conf
cp http.conf /etc/fdfs/
cp mime.types /etc/fdfs/
另外还需要把fastdfs-nginx-module安装目录中src目录下的mod_fastdfs.conf也拷贝到/etc/fdfs目录下:
cp /usr/yong.cao/dev/nginx/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
对刚刚拷贝的mod_fastdfs.conf文件进行修改:
vim /etc/fdfs/mod_fastdfs.conf
base_path=/usr/yong.cao/dev/fastdfs/fastdfs_storage #保存日志目录
tracker_server=192.168.177.200:22122 #tracker服务器的IP地址以及端口号
storage_server_port=23000 #storage服务器的端口号
url_have_group_name = true #文件 url 中是否有 group 名
store_path0=/usr/yong.cao/dev/fastdfs/fastdfs_storage_data #存储路径
group_count = 3 #设置组的个数,事实上这次只使用了group1
在文件的最后,设置group
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/yuqing/fastdfs
store_path1=/usr/yong.cao/dev/fastdfs/fastdfs_storage_data
# group settings for group #2
# since v1.14
# when support multi-group, uncomment following section as neccessary
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/usr/yong.cao/dev/fastdfs/fastdfs_storage_data
[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/usr/yong.cao/dev/fastdfs/fastdfs_storage_data
创建M00至storage存储目录的符号连接:
ln -s /usr/yong.cao/dev/fastdfs/fastdfs_storage_data/data/ /usr/yong.cao/dev/fastdfs/fastdfs_storage_data/data/M00
启动nginx:
/usr/local/nginx/sbin/nginx
成功启动:
[root@localhost conf]# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=8142
这里写图片描述
恭喜你,storage的nginx已配置成功。接下来,我们还要继续配置tracker的nginx。
3.4 防火墙端口设置
成功了,为什么还要讲这个呢。因为有些同学到这里,还是不到访问,很可能是防火墙没有开启相应的端口。防火墙这个东西我建议大家还是不要关闭,虽然麻烦了一点。
查看已开启的端口:
[root@localhost nginx-1.12.0]# firewall-cmd --zone=public --list-ports
20880/tcp 80/tcp 2181/tcp 23000/tcp 22122/tcp 9999/tcp
[root@localhost nginx-1.12.0]#
在我的CentOS上这些端口都是开放的。
storage:20880
tracker:23000
这两个端口要开启,到时候下一篇讲fastdfs-client-javas可能会造成无法连接。
9999和80端口是提供给nginx访问的。
开放端口号命令:–permanent表示永久生效,不加的话,重启后不生效
firewall-cmd --zone=public --add-port=23000/tcp --permanent #开户端口号
CentOS7 防火墙相关命令:
systemctl enable firewalld.service #开启防火墙
systemctl stop firewalld.service #关闭防火墙(开机会仍会启动)
systemctl disable firewalld.service #禁用防火墙(开机后不再启动)
3.5 HTTP测试
现在我们再去访问一下,原来我们上传过的文件:
image.png
这个时候已经能成功访问。感谢你能坚持到现在,FastDFS已部署完成。
网友评论