本篇是将tracker和storage安装在同一台服务器上,同时在该服务器上安装nginx。
fastdfs-master.zip
fastdfs-nginx-module-master.zip
libfastcommon-master.zip
// 配置tracker所需的base_path:/opt/fdfs/tracker;
mkdir -p /opt/fdfs/tracker
chmod 755 /opt/fdfs/tracker
// 配置storage所需的日志目录:/opt/fdfs/storage/info
mkdir -p /opt/fdfs/storage/info
chmod 755 /opt/fdfs/storage/info
// 配置storage所需的存储目录:/opt/fdfs/storage/data
mkdir -p /opt/fdfs/storage/data
chmod 755 /opt/fdfs/storage/data
unzip libfastcommon-master.zip
cd libfastcommon-master
./make.sh
./make.sh install
cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
编辑tracker.conf,修改以下几项配置
base_path=/opt/fdfs/tracker
http.server_port=8080 //根据实际端口配置
store_group=group1
//在配置文件最后添加
#include http.conf
cd /etc/fdfs/
cp storage.conf.sample storage.conf
编辑storage.conf,修改如下几项配置
group_name=group1 //必须跟tracker.conf里的store_group保持一致
base_path=/opt/fdfs/storage/info
store_path0=/opt/fdfs/storage/data
tracker_server=XXX.XXX.XXX.XXX:22122 //根据实际的tracker所在IP配置
http.server_port=8089 //根据实际情况配置端口
//在配置文件最后添加
#include http.conf
cd /etc/fdfs/
cp client.conf.sample client.conf
编辑client.conf,修改如下几项配置
base_path=/opt/fdfs/storage/info
tracker_server=XXX.XXX.XXX.XXX:22122
启动tracker
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
启动storage
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart
检查启动是否成功
ps -ef|grep fdfs
检查tracker和storage的日志
tailf /opt/fdfs/tracker/logs/trackerd.log
tailf /opt/fdfs/storage/info/logs/storaged.log
测试上传
/usr/local/bin/fdfs_upload_file /etc/fdfs/client.conf xxx.zip
测试删除
/usr/local/bin/fdfs_delete_file /etc/fdfs_client.conf group1/M00/00/00/XXX.zip
查看文件信息
/usr/local/bin/fdfs_file_info /etc/fdfs_client.conf group1/M00/00/00/XXX.zip
停止 tracker
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop
停止 storage
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf stop
查看集群状况
/usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf
编译FastDFS时出现#Error port me
原因:libfastcommon版本比较旧导致,到github上下载最新版本。
启动trackerd出现 g_current_time
原因:由于libfastcommon库配置异常。重新按照配置软连接方式重新配置一遍
安装Nginx包括为tracker安装和为storage安装。
- 为tracker安装Nginx是为了提供http访问的反向代理、负载均衡以及缓存服务;
- 为storage安装Nginx是为了提供http的访问服务,同时解决group中storage服务器的同步延迟问题。
我们只考虑在同一台机器上安装tracker和storage的情况下,只在同服务器上安装一套nginx并进行配置。
上传nginx-1.11.3.tar.gz
,pcre-8.40.tar.gz
,ngx_cache_purge-2.3.tar.gz
,fastdfs-nginx-module-master.zip
上传到/home/install/nginx/目录下
安装nginx之前必须先安装pcre。可以直接升级。
unzip pcre-8.40.zip
cd pcre-8.40
./configure --prefix=/usr/local/pcre
make && make install
tar xzvf nginx-1.11.3.tar.gz
unzip fastdfs-nginx-module-master.zip
tar xzvf nginx-1.11.13.tar.gz
tar xzvf ngx_cache_purge-2.3.tar.gz
cd nginx-1.11.3
./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.40 --add-module=../ngx_cache_purge-2.3 --add-module=../fastdfs-nginx-module-master/src/ --with-http_stub_status_module --with-http_ssl_module
make && make install
为FastDFS的tracker做负载均衡和缓存
proxy_temp_path /usr/local/nginx/var/temp
proxy_cache_path /usr/local/nginx/var/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g
upstream fdfs_group {
server xxx.xxx.xxx.xxx:8080 weight=1 max_fails=2;
}
server {
listen 8088;
server_name localhost;
location /group1/M00{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;
proxy_cache_valid 200 304 12h;
proxy_cache_key $uri$is_args$args;
proxy_pass http://fdfs_group;
expires 30d;
}
location ~/purge(/.*) {
allow 127.0.0.1;
allow xxx.xxx.xxx.xxx/24;
deny all;
proxy_cache_purge cache_one $1$is_args$args;
}
error_page 500 502 503 504 /50x.html
location = /50x.html {
root html;
}
}
为FastDFS的storage提供http下载
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.htm index.html;
}
location ~/gropu1/M00 {
root /opt/fdfs/storage/data/data;
ngx_fastdfs_module;
}
}
将/usr/local/fdfs/fastdfs-master/conf
目录下的http.conf
、mime.types
两个文件拷贝到/etc/fdfs/
目录下,否则nginx启动会报错。
将/home/install/nginx/fastdfs-nginx-module-master/src
目录下的mod_fastdfs.conf
拷贝到/etc/fdfs/
目录下。
编辑mod_fastdfs.conf文件
base_path=/opt/fdfs/storage/info
tracker_server=xxx.xxx.xxx.xxx:22122
url_have_group_name=true
store_path0=/opt/fdfs/storage/data
http.need_find_content_type=true
ln -s /opt/fdfs/storage/data/data/ /opt/fdfs/storage/data/data/M00
重启nginx
nginx -s reload