软件包下载地址:
https://sourceforge.net/projects/fastdfs/files/
https://github.com/happyfish100/
nginx.org #下载nginx的
基础环境
IP | 操作系统 |
192.168.56.121(edu-dfs-tracker-01) | CentOS Linux release 7.3.1611 (Core) |
192.168.56.125(edu-dfs-storage-01) | CentOS Linux release 7.3.1611 (Core) |
2.防火墙关闭 selinux关闭
3.主机名解析
[root@edu-dfs-tracker-01 src]# cat /etc/hosts 192.168.56.121 edu-dfs-tracker-01 192.168.56.125 edu-dfs-storage-01
4.上传所需要的安装包 看主机名哪台服务器
tracker:
[root@edu-dfs-tracker-01 src]# ll total 504 -rw-r--r-- 1 root root 336001 Jan 1 10:17 fastdfs-5.05.tar.gz -rw-r--r-- 1 root root 171755 Jan 1 10:21 libfastcommon-master.zip [root@edu-dfs-tracker-01 src]#
storage:
[root@edu-dfs-storage-01 src]# ll total 1312 -rw-r--r-- 1 root root 336001 Jan 1 10:17 fastdfs-5.05.tar.gz -rw-r--r-- 1 root root 17510 Jan 1 10:03 fastdfs-nginx-module_v1.16.tar.gz -rw-r--r-- 1 root root 171755 Jan 1 10:21 libfastcommon-master.zip -rw-r--r-- 1 root root 804164 Jan 1 10:08 nginx-1.6.2.tar.gz [root@edu-dfs-storage-01 src]#
5.基础环境安装 不安装后面报错
yum -y install perl perl-devel make gcc-c++ gcc cmake
6.安装公共的common库
两台服务器都得安装座一样的操作
cd /usr/local/src unzip libfastcommon-master.zip cd libfastcommon-master ./make.sh ./make.sh install ##### [root@edu-dfs-tracker-01 libfastcommon-master]# ./make.sh install mkdir -p /usr/lib64 mkdir -p /usr/lib install -m 755 libfastcommon.so /usr/lib64 install -m 755 libfastcommon.so /usr/lib mkdir -p /usr/include/fastcommon install -m 644 common_define.h hash.h chain.h logger.h base64.h shared_func.h pthread_func.h ini_file_reader.h _os_define.h sockopt.h sched_thread.h http_func.h md5.h local_ip_func.h avl_tree.h ioevent.h ioevent_loop.h fast_task_queue.h fast_timer.h process_ctrl.h fast_mblock.h connection_pool.h fast_mpool.h fast_allocator.h fast_buffer.h skiplist.h multi_skiplist.h flat_skiplist.h skiplist_common.h system_info.h fast_blocked_queue.h php7_ext_wrapper.h id_generator.h char_converter.h char_convert_loader.h /usr/include/fastcommon [root@edu-dfs-tracker-01 libfastcommon-master]#
7.做软连接:fastdfs主程序设置的lib路径是/usr/local/lib 单默认并不是所以软连接
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
8.安装fastdfs
两台都需要安装
cd /usr/local/src tar xf fastdfs-5.05.tar.gz cd fastdfs-5.05 ./make.sh ./make.sh install
9.fastdfs安装后文件说明
9.1 服务脚本
[root@edu-dfs-tracker-01 ~]# ll /etc/init.d/ |grep dfs -rwxr-xr-x 1 root root 1186 Jan 1 18:57 fdfs_storaged -rwxr-xr-x 1 root root 1186 Jan 1 18:57 fdfs_trackerd [root@edu-dfs-tracker-01 ~]#
9.2 配置文件样例
[root@edu-dfs-tracker-01 ~]# cd /etc/fdfs/ [root@edu-dfs-tracker-01 fdfs]# ll total 20 -rw-r--r-- 1 root root 1461 Jan 1 18:57 client.conf.sample -rw-r--r-- 1 root root 7829 Jan 1 18:57 storage.conf.sample -rw-r--r-- 1 root root 7102 Jan 1 18:57 tracker.conf.sample [root@edu-dfs-tracker-01 fdfs]#
9.3命令工具在/usr/bin 下
[root@edu-dfs-tracker-01 bin]# pwd /usr/bin [root@edu-dfs-tracker-01 bin]# ll |grep dfs -rwxr-xr-x 1 root root 322736 Jan 1 18:57 fdfs_appender_test -rwxr-xr-x 1 root root 322512 Jan 1 18:57 fdfs_appender_test1 -rwxr-xr-x 1 root root 309368 Jan 1 18:57 fdfs_append_file -rwxr-xr-x 1 root root 308696 Jan 1 18:57 fdfs_crc32 -rwxr-xr-x 1 root root 309392 Jan 1 18:57 fdfs_delete_file -rwxr-xr-x 1 root root 310160 Jan 1 18:57 fdfs_download_file -rwxr-xr-x 1 root root 309752 Jan 1 18:57 fdfs_file_info -rwxr-xr-x 1 root root 327672 Jan 1 18:57 fdfs_monitor -rwxr-xr-x 1 root root 1132136 Jan 1 18:57 fdfs_storaged -rwxr-xr-x 1 root root 332680 Jan 1 18:57 fdfs_test -rwxr-xr-x 1 root root 331896 Jan 1 18:57 fdfs_test1 -rwxr-xr-x 1 root root 466000 Jan 1 18:57 fdfs_trackerd -rwxr-xr-x 1 root root 310352 Jan 1 18:57 fdfs_upload_appender -rwxr-xr-x 1 root root 311376 Jan 1 18:57 fdfs_upload_file [root@edu-dfs-tracker-01 bin]#
10 修改启动配置文件 两台机器都得替换
sed -i "s#/usr/local/bin#/usr/bin#g" /etc/init.d/fdfs_trackerd sed -i "s#/usr/local/bin#/usr/bin#g" /etc/init.d/fdfs_storaged
11.tarcker节点的配置192.168.56.121
[root@edu-dfs-tracker-01 tracker]# cd /etc/fdfs/ [root@edu-dfs-tracker-01 fdfs]# ls client.conf.sample storage.conf.sample tracker.conf tracker.conf.sample [root@edu-dfs-tracker-01 fdfs]# co tracker.conf.sample tracker.conf [root@edu-dfs-tracker-01 fdfs]# vi tracker.conf #配置文件讲解具体去官网看 base_path=/fastdfs/tracker [root@edu-dfs-tracker-01 fdfs]#mkdir -p /fastdfs/tracker 启动tracker节点: /etc/init.d/fdfs_trackerd start [root@edu-dfs-tracker-01 fdfs]# ps -ef |grep fdfs root 18420 1 0 20:09 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf root 18436 10218 0 20:26 pts/0 00:00:00 grep --color=auto fdfs [root@edu-dfs-tracker-01 fdfs]# [root@edu-dfs-tracker-01 fdfs]# cd /fastdfs/tracker/ [root@edu-dfs-tracker-01 tracker]# ll total 0 drwxr-xr-x 2 root root 80 Jan 1 20:10 data #自动生成的两个文件 drwxr-xr-x 2 root root 25 Jan 1 20:09 logs [root@edu-dfs-tracker-01 tracker]# 加入开机启动 [root@edu-dfs-tracker-01 tracker]# echo "/etc/init.d/fdfs_trackerd start">>/etc/rc.local
12.修改storage节点
[root@edu-dfs-storage-01 storage]# cd /etc/fdfs/ [root@edu-dfs-storage-01 fdfs]# cp storage.conf.sample storage.conf vi sotrage.conf port=23000 #不需要修改 http.server_port=8888 #不需要修改 这两个端口防火墙要打开 tracker_server=192.168.56.121:22122 #修改成tracker的ip store_path0=/fastdfs/storage #自定义目录 base_path=/fastdfs/storage #自定义目录 echo "/etc/init.d/fdfs_storaged status" >>/etc/rc.local
13.测试是否能正产上传文件在 tracker接点上
[root@edu-dfs-tracker-01 fdfs]# cd /etc/fdfs/ [root@edu-dfs-tracker-01 fdfs]# cp client.conf.sample client.conf [root@edu-dfs-tracker-01 fdfs]# vi client.conf base_path=/fastdfs/tracker #修改这两处 tracker_server=192.168.56.121:22122 #storage服务器 [root@edu-dfs-storage-01 00]# pwd /fastdfs/storage/data/00/00 [root@edu-dfs-storage-01 00]# ls #为空 #tracke服务器 #测试上传一个文件 [root@edu-dfs-tracker-01 fdfs]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/fastdfs-5.05.tar.gz group1/M00/00/00/wKg4fVhpIm-AcfEhAAUggSnIHZU.tar.gz #返回文件存储的路径 [root@edu-dfs-tracker-01 fdfs]# #storage服务器 [root@edu-dfs-storage-01 00]# pwd /fastdfs/storage/data/00/00 [root@edu-dfs-storage-01 00]# ll total 332 -rw-r--r-- 1 root root 336001 Jan 1 23:38 wKg4fVhpIm-AcfEhAAUggSnIHZU.tar.gz 可以看出上传文件成功
14.在每个存储的节点安装nginx
说明:fastdfs通过tracker服务器,将文件放在storage服务器存储,但是同组存储服务器之间需要进行文件复制,有同步的延迟,假设tracker服务器将文件上传到了 192.168.4.125,上传成功已经返回客户端,此时fstdfs存储集群的机制将会将这个文件同步到存储服务器组192.168.4.126,在文件还没完全复制的情况下,客户端如果可以用这个ID在192.168.4.126上取文件,就是出现无法访问的错误。而fastdfs-nginx-module可以重定向文件链接到源服务器取文件,避免客户端由于复制延迟导致的文件而无法访问。(解压后再安装nginx的时候加载此模块)
14.1 解压fastdfs-nginx-module 待会安装nginx用
[root@edu-dfs-storage-01 src]# cd /usr/local/src/ [root@edu-dfs-storage-01 src]#tar xf fastdfs-nginx-module_v1.16.tar.gz [root@edu-dfs-storage-01 src]# cd fastdfs-nginx-module/src/ [root@edu-dfs-storage-01 src]# ls common.c common.h config mod_fastdfs.conf ngx_http_fastdfs_module.c [root@edu-dfs-storage-01 src]# [root@edu-dfs-storage-01 src]# vi config CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
14.2安装nginx
yum -y install openssl openssl-devel pcre* zlib libtool autoconf automke [root@edu-dfs-storage-01 src]# cd /usr/local/src/ [root@edu-dfs-storage-01 src]# tar xf nginx-1.6.2.tar.gz [root@edu-dfs-storage-01 src]# cd nginx-1.6.2 [root@edu-dfs-storage-01 nginx-1.6.2]# ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ [root@edu-dfs-storage-01 nginx-1.6.2]# make && make install
14.3拷贝nginx-module配置文件 storage服务器
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ vim /etc/fdfs/mod_fastdfs.conf 其余的默认 connect_timeout=10 url_have_group_name = true store_path0=/fastdfs/storage tracker_server=192.168.56.121:22122
14.3拷贝fastdfs中的配置文件
[root@edu-dfs-storage-01 data]# cp /usr/local/src/fastdfs-5.05/conf/http.conf /etc/fdfs/ [root@edu-dfs-storage-01 data]# cp /usr/local/src/fastdfs-5.05/conf/mime.types /etc/fdfs/
14.4 做软连接
ln -s /fastdfs/storage/data /fastdfs/storage/data/M00
15.修改nginx的配置文件
[root@edu-dfs-storage-01 conf]# pwd /usr/local/nginx/conf vim nginx.conf 修改如下位置 user root; listen 8888; location ~/group(0-9)/M00 { ngx_fastdfs_module; }
16启动nginx
[root@edu-dfs-storage-01 M00]# /usr/local/nginx/sbin/nginx -t ngx_http_fastdfs_set pid=20642 nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@edu-dfs-storage-01 M00]# /usr/local/nginx/sbin/nginx ngx_http_fastdfs_set pid=20643 [root@edu-dfs-storage-01 M00]# echo "/usr/local/nginx/sbin/nginx ">>/etc/rc.local
17.测试浏览器下载上传的文件
tracker服务器上传一个文件 [root@edu-dfs-tracker-01 fdfs]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/fastdfs-5.05.tar.gz group1/M00/00/00/wKg4fVhpNdSATeHdAAUggSnIHZU.tar.gz [root@edu-dfs-tracker-01 fdfs]# 浏览器下载
OK fastdfs 单机版部署完毕
下篇 fastdfs集群的部署