1、关闭selinux
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@host-2 ~]# sed -i '1,$ s/enforcing/disabled/g' /etc/selinux/config [root@host-2 ~]# reboot
2、卸载防火墙
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@host-2 ~]# rpm -qa | grep "iptables" | xargs rpm -e --nodeps [root@host-2 ~]# rpm -qa | grep "firewall" | xargs rpm -e --nodeps
3、配置本地源
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
sh-4.2# cat /etc/yum.repos.d/GuGe.repo [GuGe] name=GuGe baseurl=ftp://192.168.1.125 gpgcheck=0 enable=1 # 我这里仅适用了官方自带的ISO镜像源
4、安装相关插件
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@host-2 ~]# yum -y install gcc gcc-c++ wget make pcre pcre-devel zlib zlib-devel unzip perl # 安装libfastcommon [root@host-2 ~]# wget https://codeload.github.com/happyfish100/libfastcommon/zip/master -P /opt/ [root@host-2 ~]# unzip -d /opt/ /opt/master [root@host-2 ~]# cd /opt/libfastcommon-master/ [root@host-2 libfastcommon-master]# ./make.sh && ./make.sh install
5、部署Fastdfs
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@host-2 ~]# wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz -P /opt/ [root@host-2 ~]# tar -zxf /opt/FastDFS_v5.08.tar.gz -C /opt/ [root@host-2 ~]# cd /opt/FastDFS [root@host-2 FastDFS]# ./make.sh && ./make.sh install # 检查安装状况 [root@host-2 FastDFS]# ll /etc/init.d/ | grep fdfs -rwxr-xr-x 1 root root 918 Mar 21 23:32 fdfs_storaged -rwxr-xr-x 1 root root 920 Mar 21 23:32 fdfs_trackerd [root@host-2 FastDFS]# ll /etc/fdfs/ -rw-r--r-- 1 root root 1461 Mar 21 23:32 client.conf.sample -rw-r--r-- 1 root root 7927 Mar 21 23:32 storage.conf.sample -rw-r--r-- 1 root root 7200 Mar 21 23:32 tracker.conf.sample [root@host-2 FastDFS]# ll /usr/bin|grep fdfs -rwxr-xr-x 1 root root 319736 Mar 21 23:32 fdfs_appender_test -rwxr-xr-x 1 root root 319512 Mar 21 23:32 fdfs_appender_test1 -rwxr-xr-x 1 root root 306368 Mar 21 23:32 fdfs_append_file -rwxr-xr-x 1 root root 306032 Mar 21 23:32 fdfs_crc32 -rwxr-xr-x 1 root root 306432 Mar 21 23:32 fdfs_delete_file -rwxr-xr-x 1 root root 307168 Mar 21 23:32 fdfs_download_file -rwxr-xr-x 1 root root 306752 Mar 21 23:32 fdfs_file_info -rwxr-xr-x 1 root root 320576 Mar 21 23:32 fdfs_monitor -rwxr-xr-x 1 root root 1112336 Mar 21 23:32 fdfs_storaged -rwxr-xr-x 1 root root 329680 Mar 21 23:32 fdfs_test -rwxr-xr-x 1 root root 324800 Mar 21 23:32 fdfs_test1 -rwxr-xr-x 1 root root 451536 Mar 21 23:32 fdfs_trackerd -rwxr-xr-x 1 root root 307360 Mar 21 23:32 fdfs_upload_appender -rwxr-xr-x 1 root root 308376 Mar 21 23:32 fdfs_upload_file # 配置tracker [root@host-2 FastDFS]# cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf [root@host-2 FastDFS]# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf # 将/etc/fdfs/tracker.conf文件中下列参数行按照实际情况修改 base_path=/data/fastdfs/tracker # 将/etc/fdfs/client.conf文件中下列参数行按照实际情况修改 base_path=/data/fastdfs/tracker tracker_server=192.168.1.166:22122 # 启动追踪端 [root@host-2 ~]# mkdir -p /data/fastdfs/tracker [root@host-2 ~]# /etc/init.d/fdfs_trackerd start # 配置storage [root@host-2 ~]# cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf # 将/etc/fdfs/storage.conf文件中下列参数行按照实际情况修改 base_path=/data/fastdfs/storage tracker_server=192.168.1.166:22122 store_path0=/data/fastdfs/storage # 启动存储端 [root@host-2 ~]# mkdir -p /data/fastdfs/storage [root@host-2 ~]# /etc/init.d/fdfs_storaged start # 安装nginx与Fastdfs关联模块 [root@host-2 ~]# tar -zxf /opt/fastdfs-nginx-module_v1.16.tar.gz -C /opt/ [root@host-2 ~]# vi /opt/fastdfs-nginx-module/src/config # vi中执行下列命令 %s+/usr/local/+/usr/+g [root@host-2 ~]# cp /opt/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ [root@host-2 ~]# vi /etc/fdfs/mod_fastdfs.conf # 将/etc/fdfs/mod_fastdfs.conf文件中下列参数行按照实际情况修改 tracker_server=192.168.1.140:22122 url_have_group_name = true store_path0=/data/fastdfs/storage
6、部署nginx
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@host-2 ~]# wget http://nginx.org/download/nginx-1.14.2.tar.gz -P /opt/ [root@host-2 ~]# tar -zxf /opt/nginx-1.14.2.tar.gz -C /opt/ [root@host-2 ~]# cd /opt/nginx-1.14.2 [root@host-2 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx/ --add-module=../fastdfs-nginx-module/src/ [root@host-2 nginx-1.14.2]# make && make install [root@host-2 nginx-1.14.2]# cp /opt/FastDFS/conf/http.conf /etc/fdfs/ [root@host-2 nginx-1.14.2]# cp /opt/FastDFS/conf/mime.types /etc/fdfs/ [root@host-2 nginx-1.14.2]# cp /usr/local/nginx/sbin/nginx /etc/init.d/ [root@host-2 nginx-1.14.2]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak [root@host-2 nginx-1.14.2]# vi /usr/local/nginx/conf/nginx.conf # nginx在Fastdfs中的应用配置 user root; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8888; server_name localhost; location ~/group[0-9]/ { ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
7、启动测试
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@host-2 nginx-1.14.2]# /etc/init.d/nginx [root@host-2 nginx-1.14.2]# fdfs_upload_file /etc/fdfs/client.conf 1.jpg # Fastdfs上传之后的存储路劲 group1/M00/00/00/wKgBjFyUTgqAGqxUAANc7hfggwA483.jpg [root@host-2 nginx-1.14.2]# curl -Is http://192.168.1.140:8888/group1/M00/00/00/wKgBjFyUTgqAGqxUAANc7hfggwA483.jpg # 返回200状态则表示一切顺利
8、设置守护进程
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@host-2 nginx-1.14.2]# echo "/etc/init.d/fdfs_trackerd start" >> /etc/rc.local [root@host-2 nginx-1.14.2]# echo "/etc/init.d/fdfs_storaged start" >> /etc/rc.local [root@host-2 nginx-1.14.2]# echo "/etc/init.d/nginx" >> /etc/rc.local [root@host-2 nginx-1.14.2]# chmod a+x /etc/rc.local
注意事项
1、不能用sh解释器来执行安装操作,必须用bash
2、Fastdfs所需要相关的包已经存放到博客园(https://files.cnblogs.com/files/guge-94/FastDFS.zip)
3、我在自己的服务器上面做实验,安装之后必须重启Fastdfs的操作系统;在公司环境并没有这个情况。没有防火墙和selinux,没有安全策略,没想明白这个问题。