yum install -y gcc gcc-c++
yum -y install libevent
wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz #FastDFS安装包
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz #libfastcommon安装包
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz #
当然也可以装一个下载一个,为了方便一些,我以单个下载安装为例。
安装FastDFS还需要安装libfastcommon作为前提条件,首先准备安装包FastDFS和libfastcommon。
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
tar-zxvf V1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh
./make.sh install
cp /usr/lib64/libfastcommon.so /usr/lib
FastDFS包含tracker、Storage
wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
tar -zxvf V5.11.tar.gz
cd fastdfs-5.11/
./make.sh
./make.sh install
cp tracker.conf.sample tracker.conf
vim tracker.conf
base_path=/home/yuqing/fastdfs
base_path=/data/fastdfs
注意:在启动tracker时,如果没有/data/fastdfs这个目录会启动失败,需要手动添加目录
mkdir -p /data/fastdfs
启动tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
设置开机自动启动,编辑文件
vim /etc/rc.d/rc.local
添加:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
以上操作已经完成了tracker的配置。启动命令我们可以优化一下,通过建立软链接的方式:
ln -s /usr/bin/fdfs_trackerd /usr/local/bin/
ln -s /usr/bin/stop.sh /usr/local/bin/
ln -s /usr/bin/restart.sh /usr/local/bin/
重启服务器测试一下:
service fdfs_trackerd restart
查看一下监听端口:
netstat -unltp | grep fdfs
cp storage.conf.sample storage.conf
vim storage.conf
base_path=/home/yuqing/fastdfs
修改为:base_path=/data/fastdfs/storage
store_path0=/home/yuqing/fastdfs
修改为:store_path0=/data/fastdfs/storage
tracker_server=192.168.209.121:22122
修改为:本机IP:22122
注意:在
/data/fastdfs
目录下没有storage
文件夹,此时需要手动创建
cd /data/fastdfs
#进入目录
mkdir storage
#创建文件
启动Storage
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
设置开机自动启动,编辑文件
vim /etc/rc.d/rc.local
添加:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
以上操作已经完成了Storage的配置。当然启动命令还是可以优化的,还是通过软链接的方式:
ln -s /usr/bin/fdfs_storaged /usr/local/bin/
重启服务器测试一下:
service fdfs_storaged restart
查看一下监听端口:
netstat -unltp | grep fdfs
测试文件上传需要做的事情
fastdfs安装成功可通过/usr/bin/fdfs_test测试上传、下载等操作
拷贝client.conf
cp client.conf.sample client.conf
编辑
vim client.conf
将
base_path=/home/yuqing/fastdfs
修改和tracker.conf文件中base_path一样的配置路径,如:base_path=/data/fastdfs
tracker_server=192.168.0.197:22122
修改为本机IP:22122
上传文件测试
使用格式:
/usr/bin/fdfs_test + 客户端配置文件地址 + upload + 上传文件
例如将,/img/test.jpg 上传,键入命令:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /img/test.jpg
文件上传成功后,输出http文件访问路径:
http://192.168.48.132/group1/M00/00/00/wKgwhFvEkZCAD_-1AAIWPJ2Hf5Y850.jpg
文件保存路径:
/data/fastdfs/storage/data/00/00/wKgShlu_gyGALPf_AAGttmZnfCs194.jpg
由于现在还没有和nginx整合无法使用http下载
FastDFS和nginx整合
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
tar -zxvf V1.20.tar.gz
fastdfs-nginx-module
移动到/usr/local
目录mv fastdfs-nginx-module /usr/local/
cd fastdfs-nginx-module/src/
ngx_module_incs="/usr/local/include"
CORE_INCS="$CORE_INCS /usr/local/include"
修改为:
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
简单说就是把/usr/local/include
,修改为/usr/include
,切记一定要加上/usr/include/fastcommon/
,这个坑踩了好久,据了解是版本问题导致的!!!!
cp mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
:base_path=/tmp 修改为 base_path=/data/fastdfs
tracker_server=tracker:22122 修改为 tracker_server= 本机:22122
store_path0=/home/yuqing/fastdfs 修改为 store_path0=/data/fastdfs/storage
url_have_group_name=false 修改为 url_have_group_name=true
cp /usr/lib64/libfdfsclient.so /usr/lib
1、yum install gcc-c++
2、yum install -y pcre pcre-devel
3、yum install -y zlib zlib-devel
4、yum install -y openssl openssl-devel
下载nginx安装包
wget https://nginx.org/download/nginx-1.8.1.tar.gz
解压
tar -zxvf nginx-1.8.1.tar.gz
进入源码目录
cd nginx-1.8.1
创建nginx所需安装目录
mkdir -p /var/temp/nginx/client
执行
./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --add-module=/usr/local/fastdfs-nginx-module/src
执行完毕后会生成一个MakeFile文件,然后就就可在该路径下进行编译和安装了
编译:make
安装: make install
重要操作:
虽然nginx安装成功了,但是会出现无法访问的问题,一个超级大的坑。
解决方式:进入fastdfs源码目录,源码的存放位置
cd /opt/fastdfs-5.11/conf/
将该子目录中的http.conf、mime.types拷贝到/etc/fdfs
cp http.conf /etc/fdfs
cp mime.types /etc/fdfs
vim /usr/local/nginx/conf/nginx.conf
location /group1/M00/{
ngx_fastdfs_module;
}
如图:
重新加载nginx配置文件
cd /usr/local/nginx/sbin
./nginx -s reload
启动nginx
cd /usr/local/nginx/sbin
./nginx
如果出现下图表示nginx搭建成功了:
访问之前测试时生成的链接就可以看到图片了,这样算是完成FastDFS+nginx的整合了。
一个需要注意的小问题:
如何机器重启nginx会出现启动失败的情况,错误信息如下:
nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)
解决方式:
1、在nginx安装目录,创建logs文件夹,我的安装目录是/usr/local/nginx/
,直接在这个目录下创建logs文件夹
mkdir logs
2、修改nginx配置文件,vim /usr/local/nginx/conf/nginx.conf
:
把#pid logs/nginx.pid;
的注释删除,路径修改为创建logs的路径,即
pid /usr/local/nginx/logs/nginx.pid;
OK!!!
偶!对了还有防火墙的问题,我想你能自己解决!!!
转自:扑棱扑棱的小菜鸟
原文:https://www.cnblogs.com/qq128/p/13489600.html