FastDFS 安装

FastDFS 安装

1.安装版本

FastDFS_v5.05 下载地址: https://github.com/happyfish100/FastDFS

fastdfs-nginx-module_v1.16

libfastcommonV1.0.7

2.安装环境

FastDFS 是 C 语言开发, 安装 FastDFS 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果 没有 gcc 环境,需要安装

# gcc
yum install gcc-c++

FastDFS 依赖 libevent

# libevent 
yum -y install libevent

安装 libfastcommon , libfastcommon 是 FastDFS 官方提供的,libfastcommon 包含了 FastDFS 运行所需 要的一些基础库

#将 libfastcommonV1.0.7.tar.gz 拷贝至/usr/local/下
cd /usr/local
tar -zxvf libfastcommonV1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh
./make.sh install

注意:libfastcommon 安装好后会自动将库文件拷贝至 /usr/lib64 下,由于 FastDFS 程序引用 /usr/lib 目录所以需要将 /usr/lib64 下的库文件拷贝至 /usr/lib 下。文件名称:libfastcommon.so

3.tracker 编译安装

3.1:安装

#将 FastDFS_v5.05.tar.gz 拷贝至/usr/local/下
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh 编译
./make.sh install 安装

安装成功将安装目录下的 conf 下的文件拷贝到 /etc/fdfs/ 下,进入/etc/fdfs/

3.2:修改配置文件

tracker.conf

vim /etc/fdfs/tracker.conf 
# 修改的内容如下:
port=22122 										# tracker服务器端口(默认22122) 
base_path=/home/fastdfs 						# 存储日志和数据的根目录

##################说明

disabled=false  #当前配置是否可用 false:可用 true:不可用
bind_addr=  #是否绑定IP,不设置为不绑定
port=22122  #默认的端口 不冲突的话不要修改
connect_timeout=30  #针对socket套接字函数connect的连接超时时间设置  
network_timeout=60  #设置网络超时,单位秒,发送或接收数据时,如果在超时时间之后依然不能进行,则本次网络通讯失败  
base_path= /home/fastdfs/log  #日志文件 可根据需要修改
max_connections=256  #服务器支持的最大连接数
accept_threads=1  #工作线程数,通常设置为CPU数量
store_lookup=2  #上传组(卷)的方式:0轮询,1:指定,2:负载平衡(剩余空间最大选择)
store_group=group1#组名称很重要 如果上一参数选择1方式,即制定组名,当前参数用来设置指定的组,如果选择其他方式,当前参数无效  
store_server==#########:22122 #服务器IP:端口 ,IP根据本机IP来填写
store_path=0 
http.server_port=9090 #http端口,使用Nginx来访问则不需要这个

3.3:启动

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

4.storage安装

storage和tracker安装的方式一样,只是配置文件不同

4.1:修改配置文件

storage.conf

vim /etc/fdfs/storage.conf 
group_name=group1 #组名称很重要,如果tracker.conf配置为指定组名的话要和tracker.conf配置的相同
base_path= /home/fastdfs/log  #storaged服务日志目录
store_path0= /home/fastdfs/data #文件数据存放目录
tracker_server=#########:22122 #服务器IP:端口 ,IP根据本机IP来填写 ,如果有多个则配置多个
http.server_port=9091 #http端口,使用Nginx来访问则不需要这个

4.2:启动

 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

5.上传文件测试

通过 fdfs_test 程序

FastDFS 安装成功可通过 /usr/bin/fdfs_test 程序来测试上传、下载等操作。

#修改/etc/fdfs/client.conf
vim /etc/fdfs/client.conf
base_path=/home/fastdfs
tracker_server=192.168.101.3:22122
tracker_server=192.168.101.4:22122
####
#使用 /usr/bin/fdfs_test 客户端配置文件地址 upload 上传文件
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/tomcat.png

Nginx 安装

在 storage server 上安装 nginx 的目的是对外通过 http 访问 storage server 上的文件。使用 nginx 的模块fastdfs-nginx-module 的作用是通过 http 方式访问 storage 中 的文件,当 storage 本机没有要找的文件时向源 storage 主机代理请求文件。

1.安装fastdfs-nginx-module

1.1:fastdfs-nginx-module_v1.16.tar.gz 传 至 fastDFS 的 storage 服务器 的 /usr/local/ 下,执行如下命令:

cd /usr/local
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
cd fastdfs-nginx-module/src

1.2: 修改 config 文件将 /usr/local/ 路径改为 /usr/ 如下:

ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

1.3: 将 fastdfs-nginx-module/src 下的 mod_fastdfs.conf 拷贝至 /etc/fdfs/

cp mod_fastdfs.conf  /etc/fdfs/

修改 mod_fastdfs.conf内容

connect_timeout=10                  		# 客户端访问文件连接超时时长(单位:秒)
base_path=base_path=/home/fastdfs                      		# 临时目录
tracker_server=########:22122  	# tracker服务IP和端口
storage_server_port=23000           		# storage服务端口
url_have_group_name=true            		# 访问链接前缀加上组名
store_path0=/home/fastdfs/fdfs_storage        		# 文件存储路径

##需要将libfdfsclient.so复制到/usr/lib
#将 libfdfsclient.so 拷贝至/usr/lib下 
cp /usr/lib64/libfdfsclient.so /usr/lib/

2.安装Nginx

2.1:将 nginx-1.8.0.tar.gz 拷贝到 /usr/local 下 解压 nginx-1.8.0.tar.gz 进入 nginx-1.8.0 目录,执行如下配置命令:

./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 ##FastDFS-nginx-module的目录
#编译&&安装
make && make install

2.2:进入 /usr/local/nginx/conf 文件下,修改配置文件nginx.conf

server {
 listen 80;
 server_name 192.168.124.61;
 location /group1/M00/ {
    root /home/fastdfs/fdfs_storage/data;
    ngx_fastdfs_module;
  }
}

说明: server_name 指定本机 ip location /group1/M00/:group1 为 nginx 服务 FastDFS 的分组名称,M00 是 FastDFS 自动生成编号,对应 store_path0=/home/FastDFS/fdfs_storage,如果 FastDFS 定义 store_path1,这里就是 M01

2.3:nginx负载均衡配置,用在多个storage服务时

upstream storage_server_group1{
	server 192.168.124.61:9001 weight=10;
	server 192.168.124.62:9001 weight=10;
}
server {
	listen 9001;
	server_name localhost;
	location /group1{
	proxy_redirect off;
	proxy_set_header Host $host;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For 				$proxy_add_x_forwarded_for;
	proxy_pass http://storage_server_group1;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值