1.准备两台服务器分别作为tracker和storage
192.168.96.121 tracker
192.168.96.100 storage
这两台机器要能编译c源码,需要安装有make和gcc
2.核心安装
拷贝文件夹libfastcommon到/usr/local/fastdfs中,进入文件夹运行make.sh和make.sh install
3.创建软链接
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/local/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
4.安装主程序
拷贝FastDFS到/usr/local/fastdfs目录下,进入FastDFS,执行make.sh 和make.sh install
默认安装在/usr/bin中
5.tracker配置
在/etc/fdfs文件夹内
cp tracker.conf.sample tracker.conf
修改tracker.conf,将base_path指定为自定义目录(/fastfdfs/tracker),然后手动创建这个目录
这个目录就是data和logs所在的目录
启动tracker:/etc/init.d/fdfs_tracker start
6.storage配置
同理,cp storage.conf.sample storage.conf
修改storage.conf
base_path=/home/yuqing/fastdfs -> base_path=/fastdfs/storage/base (自定义目录)
store_path0=/home/yuqing/fastdfs -> store_path0=/fastdfs/storage/store(自定义目录)
tracker_server=192.168.2.109:22122 -> tracker_server=tracker服务IP:22122
创建自定义目录,运行
7.安装nginx插件实现上传图片的预览
需要nginx和fastdfs-nginx-module的源码
首先要更改配置文件vi /usr/local/fastdfs/fastdfs-nginx-module/src/config
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/include/fastcommon/"
在nginx源码目录下,首先运行配置
./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/fastdfs-nginx-module/src
之后make && make install
创建临时目录mkdir -p /var/temp/nginx
配置cp /usr/local/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
参考修改值:
connect_timeout=10
tracker_server=192.168.2.109:22122
url_have_group_name = true
store_path0=/fastdfs/storage/store
cp /usr/local/fastdfs/FastDFS/conf/http.conf /etc/fdfs/
cp /usr/local/fastdfs/FastDFS/conf/mime.types /etc/fdfs/
ln -s /fastdfs/storage/store/data/ /fastdfs/storage/store/data/M00
修改nginx配置文件cd /usr/local/nginx/conf
user root; # Nginx需要访问linux文件系统,必须有文件系统的权限。User root代表nginx访问文件系统的权限是root用户权限。如果不开启权限,可能有404访问错误。
server{
listen 8888; # storage配置中,有http.server_port=8888的配置信息,必须一致。配置文件是/etc/fdfs/storaged.conf
server_name localhost;
location ~/group([0-9])/M00{
ngx_fastdfs_module;
}
}
启动nginx,大功告成!