FastDFS安装和测试

准备安装包:
FastDFS_v5.08.tar.gz
fastdfs-nginx-module_v1.16.tar.gz
libevent-2.0.22-stable.tar.gz
libfastcommon-master.zip

1.2 安装依赖

FastDFS运行需要一些依赖,在课前资料提供的虚拟中已经安装好了这些依赖,如果大家想要从头学习,可以按下面方式安装:

1.2.1 安装GCC依赖

GCC用来对C语言代码进行编译运行,使用yum命令安装:

sudo yum -y install gcc
1.2.2 安装unzip工具

unzip工具可以帮我们对压缩包进行解压

 yum install -y unzip zip
1.2.3 安装libevent
 yum -y install libevent
1.2.4 安装Nginx所需依赖
 yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
1.2.5 安装libfastcommon-master

这个没有yum包,只能通过编译安装:

  • 解压刚刚上传的libfastcommon-master.zip

    unzip libfastcommon-master.zip
    
  • 进入解压完成的目录:

    cd libfastcommon-master
    
  • 编译并且安装:

    先执行 chmod u+x make.sh 在执行下面

    sudo ./make.sh 
    sudo ./makesh install
    

到这里为止,所有依赖都已经安装完毕,接下来我们安装FastDFS:

1.3 安装FastDFS

1.3.1 编译安装

这里我们也采用编译安装,步骤与刚才的编译安装方式一样:

  • 解压

    tar -xvf FastDFS_v5.08.tar.gz
    
  • 进入目录

    cd FastDFS
    
  • 编译并安装

     ./make.sh 
     ./make.sh install
    
  • 校验安装结果

1)安装完成,我们应该能在/etc/init.d/目录,通过命令ll /etc/init.d/ | grep fdfs看到FastDFS提供的启动脚本:

 [root@VM_0_8_centos FastDFS]# ll /etc/init.d/ | grep fdfs 
-rwxr-xr-x  1 root root   918 Oct  7 17:18 fdfs_storaged
-rwxr-xr-x  1 root root   920 Oct  7 17:18 fdfs_trackerd

其中:

  • fdfs_trackerd 是tracker启动脚本
  • fdfs_storaged 是storage启动脚本

2)我们可以在 /etc/fdfs目录,通过命令查看到以下配置文件模板:

[root@VM_0_8_centos FastDFS]# cd /etc/fdfs/
[root@VM_0_8_centos fdfs]# ll
total 20
-rw-r--r-- 1 root root 1461 Oct  7 17:18 client.conf.sample
-rw-r--r-- 1 root root 7927 Oct  7 17:18 storage.conf.sample
-rw-r--r-- 1 root root 7200 Oct  7 17:18 tracker.conf.sample

其中:

  • tarcker.conf.sample 是tracker的配置文件模板
  • storage.conf.sample 是storage的配置文件模板
  • client.conf.sample 是客户端的配置文件模板
1.3.2 启动tracker

FastDFS的tracker和storage在刚刚的安装过程中,都已经被安装了,因此我们安装这两种角色的方式是一样的。不同的是,两种需要不同的配置文件。

我们要启动tracker,就修改刚刚看到的tarcker.conf,并且启动fdfs_trackerd脚本即可。

  • 编辑tracker配置

首先我们将模板文件进行赋值和重命名:

 cp tracker.conf.sample tracker.conf
 vim tracker.conf

打开tracker.conf,修改base_path配置:
#tracker的数据和日志存放目录

base_path=/leyou/fdfs/tracker  
  • 创建目录

刚刚配置的目录可能不存在,我们创建出来

 mkdir -p /leyou/fdfs/tracker
  • 启动tracker

    我们可以使用 sh /etc/init.d/fdfs_trackerd 启动,不过安装过程中,fdfs已经被设置为系统服务,我们可以采用熟悉的服务启动方式:
    #启动fdfs_trackerd服务,停止用stop

 service fdfs_trackerd start 

如果不能启动,或提示用systemctl可改用命令:

systemctl start fdfs_trackerd
#另一种启动方式
fdfs_trackerd /etc/fdfs/tracker.conf restart

另外,我们可以通过以下命令,设置tracker开机启动:

 chkconfig fdfs_trackerd on
1.3.3 启动storage

我们要启动tracker,就修改刚刚看到的tarcker.conf,并且启动fdfs_trackerd脚本即可。

  • 编辑storage配置

首先我们将模板文件进行赋值和重命名:

 cp storage.conf.sample storage.conf
 vim storage.conf

打开storage.conf,修改base_path配置:
找到下面几个修改

#storage的数据和日志存放目录
base_path=/leyou/fdfs/storage 
#storage的上传文件存放路径
store_path0=/leyou/fdfs/storage 
#下面地址是自己服务器的ip加上22122端口,#tracker的地址
tracker_server=192.168.56.101:22122 
  • 创建目录

刚刚配置的目录可能不存在,我们创建出来

mkdir -p /leyou/fdfs/storage
  • 启动storage

    我们可以使用 sh /etc/init.d/fdfs_storaged 启动,同样我们可以用服务启动方式:
    #启动fdfs_storaged服务,停止用stop

service fdfs_storaged start  
#上面启动不了用下面的
fdfs_storaged /etc/fdfs/storage.conf restart

另外,我们可以通过以下命令,设置tracker开机启动:

chkconfig fdfs_storaged on

最后,通过ps -ef | grep fdfs 查看进程:

[root@VM_0_8_centos ~]# ps -ef | grep fdfs
root     22507 22466  0 10:56 pts/4    00:00:00 grep --color=auto fdfs
root     25157     1  0 Oct07 ?        00:00:06 fdfs_trackerd /etc/fdfs/tracker.conf restart
root     25840     1  0 Oct07 ?        00:00:23 fdfs_storaged /etc/fdfs/storage.conf start

最后是

cd /etc/fdfs/
cp client.conf.sample client.conf

2 编辑client.conf文件

vim /etc/fdfs/client.conf

文件中找到下面几个修改内容:

base_path=/tmp
#下面地址是自己服务器的ip加上22122端口
tracker_server=192.168.56.101:22122

测试模拟上传

放一张图(ddd.png)到/tmp目录下,然后执行下面的命令

[root@VM_0_8_centos ~]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /tmp/ddd.png 
group1/M00/00/00/rBEACF2bOZWAOJMPAAC_EB3RR74643.png
[root@VM_0_8_centos ~]# 

成功返回后。返回图片id:

group1/M00/00/00/rBEACF2bOZWAOJMPAAC_EB3RR74643.png

group1:组信息

M00:对应store_path0,也就是/leyou/fdfs/storage

/00/00/:磁盘路径

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值