服务器中搭建FastDFS

由于换电脑的原因 图片丢失了,将就看吧 ε=(´ο`*)))唉

1、安装

1.1、安装之前需要准备的包

  1. fastdf-5.111.tar.gz 核心文件
  2. fastdfs-nginx-module-1.20.tar.gznginx联合的模快
  3. libfastcommon-1.0.35.tar.gz必要的运行包
  4. nginx-1.18、0nginx的安装包

1.2、文件上传

1.3、安装工具

  1. gcc

    yum install -y gcc gcc-g++ 编译工具

  2. libevent

    yum install -y libevent运行时需要

1.4、安装 libfastcommon

cd /root/download
tar -zxvf libfastcommon-1.0.35.tar.gz
cd libfastcommon-1.0.35
./make.sh
./make.sh install

1.5、 安装fastdfs

1.5.1、安装相关依赖库

yum install -y perl
yum install -y pcre
yum install -y pcre-devel
yum install -y zlib
yum install -y zlib-devel
yum install -y openssl
yum install -y openssl-devel

1.5.2、开始安装

cd /root/download
tar -zxvf fastdfs-5.11.tar.gz
cd fastdfs-5.11
./make.sh &&./make.sh install

安装完成之后

ll /etc/init.d/ | grep fdfs查看可执行脚本后面有用

2、准备配置文件

配置文件默认在 /etc/fdfs下面

cd /etc/fdfs
下面有几个sample文件、复制一份并将sample去掉
cp client.conf.sample client.conf
cp storage.conf.sample storage.conf
cp storage_ids.conf.sample storage_ids.conf
cp tracker.conf.sample  tracker.conf

然后修改存放数据和日志的文件夹

mkdir -p /root/fastdfs/tracker

mkdir -p /root/fastdfs/storage

2.1、配置tracker

2.1.1、修改tracker.conf

cd /etc/fdfs/
vim tracker.conf
base_path = /home/yuqing/fastdfs 改为 base_path = /root/fastdfs/tracker
启动tracker
service fdfs_trackerd start
启动之后会在 /root/fastdfs/tracker文件下生成两个目录一个是日志一个是数据

2.2配置storage

cd /etc/fdfs
vim storage.conf
group_name=group1 #配置组名
base_path=/home/yuqing/fastdfs 改为: base_path=/root/fastdfs/storage
#store存放文件的位置(store_path)
store_path0=/home/yuqing/fastdfs 改为: store_path0=/root/fastdfs/storage
#如果有多个挂载磁盘则定义多个store_path,如下
#store_path1=.....
#store_path2=......
#配置tracker服务器:IP
tracker_server=172.17.4.99:22122
#如果有多个则配置多个tracker
#tracker_server=117.48.203.126:22122
# 启动服务
service fdfs_storaged start
# 启动完成之后进入storage/data目录下显示目录如下

如果不出现data目录则有可能是tracker_server填写的地址搞错了, 一定是ifconfig里面显示的地址,因为有可能不是服务器的地址 而是服务器所在局域网的地址

2.3、使用fastdfs自带工具测试一下

cd /etc/fdfs
vim client.conf
touch echo"hello fastdfs">index.html

改为如下图所示

放一张图片到download目录下面

运行测试程序,读取/etc/fdfs/client.conf 文件,上传到download目录下面的文件

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/dowload/t2.jpg 
# 结果如下图所示则正确

http://xxx/group1/M00/00/00/rBEEY19PdNCAGjV4AAB3F_Congg482.jpg

group1/M00/00/00/wKjAgV9Q0GyAMXIAAAAAAAAAAAA60.html

3、与nginx整合

3.1、安装Nginx并整合

安装相关依赖库

yum install -y perl&&yum install -y pcre&&yum install -y pcre-devel&&yum install -y zlib&&yum install -y zlib-devel&&yum install -y openssl&&yum install -y openssl-devel

3.2、安装nginx-module模块

cd /root/download
tar -zxvf fastdfs-nginx-module-1.20.tar.gz
cd fastdfs-nginx-module-1.20/src
vim config
# 修改config文件,将文件中的所有 /usr/local/ 路径改为 /usr/

3.3、修改fastdfs-nginx-module配置

# 将fastdfs-nginx-module/src下的mod_fastdfs.conf拷贝至/etc/fdfs/下
cp mod_fastdfs.conf /etc/fdfs/
# 并修改 /etc/fdfs/mod_fastdfs.conf 的内容
vim /etc/fdfs/mod_fastdfs.conf
#######################文件内容###########################
tracker_server=172.17.4.99:22122
url_have_group_name=true #url中包含group名称
store_path0=/root/fastdfs/storage #指定文件存储路径

3.4、进入之前解压的fastdfs目录下,把http.conf、mime.conf移动至/etc/fdfs

cd /root/download/fastdfs-5.11/conf
cp http.conf mime.types /etc/fdfs/

3.5、安装nginx

cd /root/download
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0/
# 加入模块命令配置
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/root/download/fastdfs-nginx-module-1.20/src
# 编译nginx并安装
make && make install

3.6、修改nginx配置

cd /opt/nginx/conf
vim nginx.conf
# 启动之后需要修改配置的话 使之生效
./usr/bin/nginx -s reload

location ~/group([0-9]) {
    #root   html;
    #index  index.html index.htm;
    ngx_fastdfs_module;
}

3.7、启动nginx

cd /usr/bin/
./nginx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值