当前位置:首页 > 技术文章 > 正文内容

轻量级分布式文件系统FastDFS安装和调试

arlanguage3个月前 (02-01)技术文章29

fastdfs 安装

wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

wget http://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz

wget http://nginx.org/download/nginx-1.4.5.tar.gz

wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz

1. 安装libevent(5.X非必须步骤)

wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

tar -zvxf libevent-2.0.21-stable.tar.gz

cd libevent-2.0.21-stable

./configure --prefix=/usr (必须安装到这里)

make && make install

ln -s /usr/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

ps : 我没有安装在那里貌似也可以

./configure --prefix=/usr/local/libevent-2.0.21-stable

make && make install

ln -s /usr/local/libevent-2.0.21-stable/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

2. 安装FastDFS

tar zxvf FastDFS_v5.01.tar.gz

cd FastDFS

vi make.sh (修改"#WITH_LINUX_SERVICE=1"为WITH_LINUX_SERVICE=1)

./make.sh

./make.sh install

3. Storage上安装nginx的附加模块

wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz

tar -zxvf fastdfs-nginx-module_v1.15.tar.gz

安装 ngx_cache_purge-2.1 和 ngx_slowfs_cache-1.9 模块

unzip ngx_slowfs_cache-master.zip

unzip ngx_cache_purge-master.zip

编译nginx

./configure --prefix=/usr/local/nginx-1.4.2 --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_mp4_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_dav_module --with-http_flv_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --add-module=../ngx_cache_purge-master --add-module=../ngx_slowfs_cache-master --add-module=/root/soft/fastdfs-nginx-module/src

make && make install

问题 : service nginx restart 成功 但项目失败 完成下方配置 就可以了

下方的一些参数配置需要编辑/etc/fdfs 一些配置文件

mkdir -p /data/fastdfs/tracker

mkdir -p /data/fastdfs/storage

/*

cp /root/soft/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

vi /etc/fdfs/mod_fastdfs.conf

修改内容为下方信息

base_path=/data/fastdfs

tracker_server=192.168.1.168:22122

store_path0=/data/images

*/

4. 配置tracker

vi /etc/fdfs/tracker.conf

base_path=/data/fastdfs/tracker

启动:service fdfs_trackerd restart

这里 tracker.conf 配置结束了

5. 配置storage

vi /etc/fdfs/storage.conf

group_name=group1 ==> 此台storage server所属的服务器组名。

base_path=/data/fastdfs/storage ==> 放置data和log的目录。此路径必须保证存在。

store_path0=/data/fastdfs/storage ==> 放置文件的目录,此路径必须保证存在.

tracker_server=192.168.112.131:22122 ==> 可以添加多个tracker_server,如下行

tracker_server=192.168.112.131:22122

http.disabled=true ==> 关闭内置的web server,如果有就设置,否则就不用设置。

http.server_port=80 ==> web server的端口改成8080(与nginx 端口一致)

这里 storage.conf 配置结束了

cp /root/soft/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

vi /etc/fdfs/mod_fastdfs.conf

base_path=/data/fastdfs/storage ==>放置log的目录,与storage中的配置保持一致。

tracker_server=192.168.112.131:22122

#tracker_server=192.168.112.131:22122

group_name=group1 ==> 此台storage server所属的服务器组名。

url_have_group_name = false ==> 在URL中包含group名称。一定要设置true 如果设置成true 可以在nginx 中 location 中设置

store_path0=/data/fastdfs/storage ==> 放置文件的目录,与storage中保持一致

response_mode=proxy ==> 对文件同步延迟的处理方式,通过redirect跳转和proxy代理两种方式解决

group_count=0 ==> group的个数,在本示例中有两个group,所以设为2,如果只有一个group则设置为0,而不是为1

启动:service fdfs_storaged restart

开放端口

# fdfs

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT

这里fastdfs 配置结束了

接下来配置nginx php关联 fastdfs

6. nginx配置

server节点添加:

vi /usr/local/nginx/conf/nginx.conf

location ~ /M00

{

# slowfs_cache fastcache;

# slowfs_cache_key $uri;

# slowfs_cache_valid 1d;

# add_header X-Cache '$slowfs_cache_status from $host';

# expires max;

if ($request_filename ~ [a-zA-Z0-9]+-([0-9]+)-([0-9]+).(gif|GIF|jpg|JPG|jpeg|JPEG|bmp|BMP|png|PNG)) {

rewrite ^(.*)-[0-9]+-[0-9]+.(gif|GIF|jpg|JPG|jpeg|JPEG|bmp|BMP|png|PNG)$ $1.$2 break;

}

ngx_fastdfs_module;

}

7. php配置

cd /root/soft/FastDFS/php_client

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make && make install

ls /usr/local/php-5.4.17/lib/php/extensions/no-debug-non-zts-20100525/

*添加fastdfs 扩展 或者直接执行 cat fastdfs_client.ini >>
/usr/local/php/etc/php.ini 这个会自定将扩展模块加入到php.ini

[fastdfs]

extension=fastdfs_client.so

fastdfs_client.base_path = /data/fastdfs/tracker

fastdfs_client.connect_timeout = 2

fastdfs_client.network_timeout = 60

fastdfs_client.log_level = info

fastdfs_client.log_filename =

fastdfs_client.http.anti_steal_secret_key =

fastdfs_client.tracker_group_count = 1

fastdfs_client.tracker_group0 = /etc/fdfs/client.conf

fastdfs_client.use_connection_pool = false

fastdfs_client.connection_pool_max_idle_time = 3600

vi /etc/fdfs/client.conf

base_path=/data/fastdfs/tracker

tracker_server=192.168.112.131:22122

service php-fpm restart

重启php进程

运行测试吧:php fastdfs_test.php

8. 测试方法

1) 查看集群情况

/usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf

2)/usr/local/bin/fdfs_test conf/client.conf upload ~/11.png

1) 上传一个文件:

$tracker = fastdfs_tracker_get_connection();

var_dump($tracker);

if (!fastdfs_active_test($tracker))

{

error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());

exit(1);

}

$storage = fastdfs_tracker_query_storage_store();

if (!$storage)

{

error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());

exit(1);

}

$file_info = fastdfs_storage_upload_by_filename("/zxy.jpg", null, array(), null, $tracker, $storage);

2) 下载一个文件

$group_name="group0";

$filename="M00/00/00/wKgBpFNN-T6AQZKtAAH4P9ysWgA950.jpg";

fastdfs_storage_download_file_to_file($group_name,$filename, "test.jpg");

3) 删除一个文件

$group_name="group0";

$filename="M00/00/00/wKgAUE5zkhH8yBZwAAGH3hvfjJA398.jpg";

echo fastdfs_storage_delete_file($group_name, $filename);>

扫描二维码推送至手机访问。

版权声明:本文由AR编程网发布,如需转载请注明出处。

本文链接:http://www.arlanguage.com/post/1960.html

标签: geoip nginx
分享给朋友:

“轻量级分布式文件系统FastDFS安装和调试” 的相关文章

Linux下各种连接数配置及高并发Nginx优化

前言在性能测试过程中,经常会接触到链接数相关的问题,那就是一台服务器最多能支持多少链接数呢?有的朋友可能会说是65535,因为操作系统有65535个端口,那么这个答案准确吗?首先先了解下如何标识一个链接,操作系统是通过一个四元组来标识一个TCP链接:{本地ip,本地port,远程ip,远程port}...

Nginx配置七层负载均衡

Nginx 一般用于七层负载均衡,其吞吐量有一定限制。为了提升系统整体吞吐量,会在 DNS 与 Nginx 之间引入接入层,比如使用LVS(软负载均衡器)、F5(硬负载均衡器)做四层负载均衡。整体的请求流转如下图所示,即首先 DNS 解析到 LVS/F5,然后 LVS/F5 转发给 Nginx,再由...

一般人绝对无法发现的nginx锅

nginx热启动:nginx -s reloadPS:要在/etc/profile环境变量PATH里配置nginx的路径。配置完执行 source /etc/profile 让变量生效。 一次部署,同样的前端代码,放到了nginx里面运行,但是有一个模块全部页面都报这个错误,其他模块正常展示。以前遇...

安卓手机上安装Linux开源模拟器-Termux

什么是TermuxTermux是一款基于 Android 平台的开源 Linux 终端模拟器,使用 pkg(apt) 进行软件包的管理。最重要的是,它无需手机 root 权限,因此,绝大多数 Android 都可以运行。Termux本质上是一个终端模拟器加上一套Linux的最小系统。这里的系统指的是...

如何构建企业级Docker Registry Server

很多人问我,虚拟机镜像和docker镜像的区别是什么?其实区别非常明显,我们可以通过阅读Dockerfile文件就可以知道这个镜像都做了哪些操作,能提供什么服务;但通过虚拟机镜像,你能一眼看出来虚拟机镜像里面多做了哪些操作,能提供什么服务吗?更突出的是我们都说是mysql镜像,Wordpress镜像...

安装Nginx并启用stream模块

下载Nginx源代码:您可以从Nginx官方网站(https://nginx.org)下载最新的稳定版本的Nginx源代码。解压源代码:使用以下命令解压下载的源代码压缩包:tar -zxvf nginx-<version>.tar.gz进入解压后的目录:使用以下命令进入解压后的Nginx...