fastdfs搭建

 

centos7.5

yum源阿里云

废话不多,直接开干

 

 

 

mkdir /software

 

cd /software/

 

 安装GCC

yum -y install wget httpd-tools vim

yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake

 

下载fastdfs安装包及nginx安装包及nginx模块

wget  https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz

wget  https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz

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

wget  https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz

解压安装包到 /soft

tar -xf V1.0.43.tar.gz -C /soft

tar -xf V1.22.tar.gz -C /soft

tar -xf V6.06.tar.gz -C /soft

tar -xf nginx-1.12.2.tar.gz -C /soft

安装libfastcommon

cd /soft

[root@169web soft]# cd libfastcommon-1.0.43/

进入解压的 libfastcommon-1.0.43目录,编译&安装

./make.sh

./make.sh install

最后,libfastcommon.so文件到usr/lib下 ,请按照自己的实际文件路径修改被复制路径

[root@169web libfastcommon-1.0.43]# cp src/libfastcommon.so  /usr/lib (提示覆盖y覆盖)

 

安装FastDFS

[root@169web libfastcommon-1.0.43]#

 cd /soft/fastdfs-6.06/

./make.sh

./make.sh install

 

 

安装成功后将目录conf内的文件拷贝到/etc/fdfs目录下

[root@169web fastdfs-6.06]# cp conf/* /etc/fdfs/

安装tracker

进入/etc/fdfs目录,修改tracker.conf文件。如果不存在,就拷贝tracker.conf.sample文件为tracker.conf,然后再修改:

[root@169web fastdfs-6.06]# cd /etc/fdfs/

[root@169web fdfs]# vim tracker.conf

base_path=/home/yuqing/fastdfs >>> base_path=/var/log/fastdfs (注解:日志文件)

 

http.server_port=8080 >>> http.server_port=7008 (注解:端口,80是方便默认)

 

store_group=group1 (注解:组名)

 

[root@169web fdfs]# mkdir /var/log/fastdfs

[root@169web fdfs]# fdfs_trackerd /etc/fdfs/tracker.conf start

[root@169web fdfs]# netstat -unltp | grep trackerd

 

 

安装storage

由于storage和tracker运行的都是fastDFS程序,每一台服务器都部署一台fasfDFS,一台服务器是tracker,一台是storage

修改storage.conf文件。如果不存在,就拷贝storage.conf.sample文件为storage.conf,然后再修改:

vim storage.conf

base_path=/home/yuqing/fastdfs >>> base_path=/var/log/storage (日志路径)

 

store_path0=/home/yuqing/fastdfs >>> store_path0=/home/data/storage  (实际储存文件路径,可以配置多个)

 

tracker_server=192.168.209.121:22122 >>> tracker_server=192.168.0.12:22122 (连接tracker服务器地址)

 

group_name=group1 (必须和tracker的组名相同)

http.server_port=80 (这个端口也要改)

 其中,如果/var/log/storage/home/data/storage不存在,就创建该目录 

[root@169web fdfs]# mkdir /var/log/storage

[root@169web fdfs]# mkdir -p /home/data/storage

[root@169web fdfs]# fdfs_storaged /etc/fdfs/storage.conf start

[root@169web fdfs]# netstat -unltp | grep storaged

 

 

最后,查看trackerstorage是不是在通信:

fdfs_monitor /etc/fdfs/storage.conf

如下提示,出现ACTIVE,表示二者均正常启动,至此就可以进行上传文件测试了。

 

测试图片上传

Tracker和storage都已经安装完成,使用命令测试文件上传:
FastDFS提供一个文件上传命令:usr/bin/fdfs_test 测试文件上传。测试上传需要连接tracker服务器,连接storage服务器。因此需要指定一个配置文件:client.conf配置文件,通过Client.conf连接tracker服务器。

修改/etc/fdfs下client.conf

base_path= /var/log/client (日志目录)

 

tracker_server=192.168.0.12:22122  (tracker端口)

创建 /var/log/client

[root@169web fdfs]# mkdir /var/log/client

 

测试命令

fdfs_test /etc/fdfs/client.conf upload anti-steal.jpg

如下图返回地址则成功

 

 

安装nginx

 

[root@169web soft]# cd nginx-1.12.2/

./configure

make

make install

修改fastdfs-nginx-module-1.22/src/config文件。把里面的这两个改成下面其他不动

[root@197test soft]# vim fastdfs-nginx-module-1.22/src/config

ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"

CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

 

拷贝usr/lib64目录下库文件libfdfsclient.so 

cp /usr/lib64/libfdfsclient.so /usr/lib

因为我原来就安装了nginx所以只添加模块就好,不需要安装nginx只需要新添加nginx模块,如果原来没有nginx直接跳过绿色段落就好

nginx -V  #查看nginx安装路径及已有模块

进入nginx源码路径

cd /root/nginx-1.12.2/

 

 

make (只make千万别make install)

nginx -s stop

mv /usr/sbin/nginx  /usr/sbin/nginx.bak

cp objs/nginx  /usr/sbin/

nginx

nginx -V查看模块是否添加成功

 

 

 [root@169web soft]# cd nginx-1.12.2/

[root@169web nginx-1.12.2]# ./configure --add-module=/soft/fastdfs-nginx-module-1.22/src

make && make install

/usr/local/nginx/sbin/nginx -V

 

复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改[root@169web soft]# cp fastdfs-nginx-module-1.22/src/mod_fastdfs.conf  /etc/fdfs/

 

 

进入/etc/fdfs/修改mod_fastdfs.conf如下配置,其他默认

 

# 连接超时时间

connect_timeout=10

 

# Tracker Server

tracker_server=192.168.0.12:22122

 

# StorageServer 默认端口

storage_server_port=23000

 

# 如果文件ID的uri中包含/group**,则要设置为true

url_have_group_name = true

 

# Storage 配置的store_path0路径,必须和storage.conf中的一致

store_path0=/home/data/storage

 

# the base path to store log files

base_path=/var/log/storage

配置iNginx ,进入/usr/local/nginx/conf目录下修改nginx.conf

注意:无论你在哪解压安装的。必须进这个目录/usr/local/nginx/conf下修改nginx.conf

vim nginx.conf

 

 

server {

        listen       808;

        server_name  localhost;

        location ~/group([0-9])/M00 {

            ngx_fastdfs_module;

        }

}

 

注意:

listen 80 端口值是要与 /etc/fdfs/storage.conf 中的 http.server_port=80 (前面改成80了)相对应。如果改成其它端口,则需要统一,同时在防火墙中打开该端口。因为我自一台机器上搭建的所以不需要统一

 

location 的配置,如果有多个group则配置location ~/group([0-9])/M00 ,没有则不用配group。

 

在文件存储目录下创建软连接,将其链接到实际存放数据的目录,注意这个文件存储的位置后面多个data目录是系统自动生成的

ln -s /home/data/storage/data /home/data/storage/data/M00

记得云服务的安全组 和防火墙设置需要方通 808、22122、 23000

 

直接启动

/usr/local/nginx/sbin/nginx

上传张网络图片

[root@169web soft]# fdfs_upload_file /etc/fdfs/client.conf /root/g.jpg

group1/M00/00/00/wKgADF-EIn6AAY3uAAUGZd8mvsM115.jpg

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值