1. 下载软件并进行初步安装 1.1 下载安装文件 FastDFS 5.x 取消了对 libevent 的依赖,添加了对 libfastcommon 的依赖。
本部署说明用到的软件版本:
直接使用Github源码下载:
https://github.com/happyfish100
将仓库中四个源码全部下载下来:
libfastcommon 1.29
fastdfs 5.08
fastdfs-nginx-module 1.18
fastdfs-client-java 1.25
fastdht 2.01
1.2 安装 fastdfs 软件 在每一台tracker和storage服务器上执行
1 2 3 4 5 [root@localhost ~]# unzip libfastcommon-master.zip [root@localhost ~]# unzip fastdfs-master.zip [root@localhost ~]# yum install -y gcc perl # 安装依赖的软件包 [root@localhost ~]# cd libfastcommon-master && ./make.sh && ./make.sh install [root@localhost ~]# cd ../fastdfs-master && ./make.sh && ./make.sh install
安装完成后,所有可执行文件在目录/usr/bin下,以fdfs_开头:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [root@localhost ~]# ls /usr/bin/fdfs_* /usr/bin/fdfs_appender_test /usr/bin/fdfs_monitor /usr/bin/fdfs_appender_test1 /usr/bin/fdfs_storaged /usr/bin/fdfs_append_file /usr/bin/fdfs_test /usr/bin/fdfs_crc32 /usr/bin/fdfs_test1 /usr/bin/fdfs_delete_file /usr/bin/fdfs_trackerd /usr/bin/fdfs_download_file /usr/bin/fdfs_upload_appender /usr/bin/fdfs_file_info /usr/bin/fdfs_upload_file
配置文件在目录/etc/fdfs下:
1 2 [root@localhost ~]# ls /etc/fdfs client.conf.sample storage.conf.sample tracker.conf.sample
2. 配置Tracker跟踪器 开放tracker监听端口访问(实验时防火墙全部关闭,未使用这部分配置)
1 2 firewall-cmd--zone=public--add-port=22122/tcp--permanent firewall-cmd--reload
2.1 修改配置文件 1 2 3 4 5 6 7 mkdir -p /data/fastdfs cd /etc/fdf scp tracker.conf.sample tracker.conf cp /home/ems/chenhj/fastdfs-master/conf/http.conf . #从安装包拷贝 cp /home/ems/chenhj/fastdfs-master/conf/mime.types . #从安装包拷贝 sed -i 's:base_path=.*:base_path=/data/fastdfs:g' tracker.conf sed -i 's:http.server_port=.*:http.server_port=80:g' tracker.conf
2.2 开启fdfs tracker服务 1 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
2.3 设置开机自启动(实验时未使用) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 bash -c 'cat > /usr/lib/systemd/system/fdfs_trackerd.service << EOF [Unit] Description=fastdfs tracker server After=network.target [Service] Type=forking PIDFile=/data/fastdfs/data/fdfs_trackerd.pid ExecStart=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf ExecReload=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart ExecStop=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop [Install] WantedBy=multi-user.target EOF' systemctl enable fdfs_trackerd.service systemctl start fdfs_trackerd.service
2.4 确认tracker是否启动成功 1 cat /data/fastdfs/logs/trackerd.log
2.5 安装并配置 nginx 反向代理 (使用EPEL安装的NGINX的版本偏低1.0.2,推荐使用最新版本nginx-1.11.2.tar.gz,并配置反向代理服务)安装过程参见《RHEL 6.4 - Santiago 源代码编译安装 Nginx 1.11.2》
2.6 配置反向代理 在第5步安装结束后,配置一下Nginx,开启一下反向代理功能。 打开 /usr/local/nginx/conf/nginx.conf,在 http {} 中添加:
1 2 3 4 upstream fdfs { server 192.168.179.141:80; server 192.168.179.142:80; }
在 server{} 中添加:
1 2 3 location /M00 { proxy_pass http://fdfs; }
3. Storage节点配置 3.1 开放tracker监听端口访问(实验时防火墙全部关闭,未使用这部分配置) 1 2 firewall-cmd--zone=public--add-port=23000/tcp--permanent firewall-cmd--reload
3.2 修改配置文件 1 2 3 4 5 6 7 8 mkdir -p /data/fastdfs cd /etc/fdfscp storage.conf.sample storage.conf cp /root/fastdfs/fastdfs/conf/http.conf . cp /root/fastdfs/fastdfs/conf/mime.types . sed -i 's:base_path=.*:base_path=/data/fastdfs:g' storage.conf sed -i 's:store_path0=.*:store_path0=/data/fastdfs:g' storage.conf sed -i 's/tracker_server=.*/tracker_server=192.168.179.140:22122/g' storage.conf sed -i 's:http.server_port=.*:http.server_port=80:g' storage.conf
3.3 开启fdfs storage服务 1 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
3.4 设置开机自启动(实验时未使用) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 bash -c 'cat > /usr/lib/systemd/system/fdfs_storaged.service << EOF [Unit] Description=fastdfs storage server After=network.target [Service] Type=forking PIDFile=/data/fastdfs/data/fdfs_storaged.pid ExecStart=/usr/bin/fdfs_storaged /etc/fdfs/storage.conf ExecReload=/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart ExecStop=/usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop [Install] WantedBy=multi-user.target EOF' systemctl enable fdfs_storaged.service systemctl start fdfs_storaged.service
3.5 确认storage是否启动成功 1 cat /data/fastdfs/logs/storaged.log
4. client客户端配置 4.1 client 客户端配置 在tracker, storage之外的一台主机上安装FastDFS,然后执行:
1 2 3 4 mkdir -p /data/fastdfs cd /etc/fdfscp client.conf.sample client.conf sed -i 's:base_path=.*:base_path=/data/fastdfs:g' client.conf sed -i 's/tracker_server=.*/tracker_server=192.168.179.140:22122/g' client.conf
4.2 FastDFS测试
1 2 3 4 joelhy@arminix: ~ $ fdfs_upload_file /etc/fdfs/client.conf pom.xmlgroup1/M00/00/00/wKhHf1S-oryAZCpgAAAE2uRlJkA126.xml group1/M00/00/00/wKhHf1S-oryAZCpgAAAE2uRlJkA126.xml
1 2 3 4 5 6 7 joelhy@arminix: ~ $ fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/wKhHf1S-oryAZCpgAAAE2uRlJkA126.xml source storage id:0 source ip address:192.168.71.127 file create timestamp:2015-01-2602:47:24 file size:1242 file crc32:3831834176 (0xE4652640)
1 2 3 4 joelhy@arminix: ~ $ fdfs_download_file /etc/fdfs/client.conf \ group1/M00/00/00/wKhHf1S-oryAZCpgAAAE2uRlJkA126.xml downtest.xml joelhy@arminix: ~ $ ls downtest.xml
5. storage server 安装 nginx 服务器 5.1 安装并配置 nginx 反向代理 (使用EPEL安装的NGINX的版本偏低1.0.2,推荐使用最新版本nginx-1.11.2.tar.gz,并配置反向代理服务) 安装过程参见《RHEL 6.4 - Santiago 源代码编译安装 Nginx 1.11.2》
在第4步结束后,采用下面方法编译、安装Nginx(带fastdfs-nginx-module)
安装Nginx和配置fastdfs-nginx-module
解压fastdfs-nginx-module-master.zip
1 unzip fastdfs-nginx-module-master.zip
修改配置文件 1 2 3 4 cp fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/ sed -i 's:base_path=.*:base_path=/data/fastdfs:g' mod_fastdfs.conf sed -i 's:store_path0=.*:store_path0=/data/fastdfs:g' mod_fastdfs.conf sed -i 's/tracker_server=.*/tracker_server=192.168.179.140:22122/g' mod_fastdfs.conf
开始安装nginx(—prefix指定nginx安装到哪里, —add-module指定fastdfs-nginx-module的目录) 如果使用Nginx的rewrite功能,请在此之前安装pcre-8.39.tar.gz
1 2 3 4 cd src ./configure --prefix=/usr/local/nginx --add-module=/home/ems/chenhj/fastdfs-nginx-module-master/src make make install
./configure —prefix=/usr/local/nginx —add-module=/home/ems/chenhj/fastdfs-nginx-module-master/src 执行完成后可以看到最后的输出:1 2 3 4 5 6 7 8 9 10 11 12 nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"
Storage服务器nginx配置 server{} 里添加1 2 3 4 location /M00 { root /data/fastdfs/data; ngx_fastdfs_module; }
测试配置的nginx 打开浏览器输入: http://127.0.0.1 ,能看到下面的界面表示安装成功了!
接下来测试fdfs上传的文件是否也能显示,首先在桌面上准备一张图片:2.jpg,输入下面的命令
1 fdfs_upload_file /etc/fdfs/client.conf /home/zq/Desktop/2.jpg
返回的文件信息是:group1/M00/00/00/wKjHglYsw5GABeZoAAAj7X7kWQc565.jpg 在浏览器输入:http://127.0.0.1/group1/M00/00/00/wKjHglYsw5GABeZoAAAjcd7X7kWQc565.jpg ,能看到如下的显示表示配置完成了:
至此配置完成了!