FastDFS实战使用-高性能文件服务器
文章目录
1.FastDFS介绍
2.安装环境
1.安装libevent
yum -y install libevent
2.安装fastdfs
准备三个安装包
[[email protected] fastDFS]# ls -l
total 432
-rw-r--r--. 1 root root 17510 Jan 10 22:20 fastdfs-nginx-module_v1.16.tar.gz
-rw-r--r--. 1 root root 345400 Jan 10 22:20 FastDFS_v5.05.tar.gz
-rw-r--r--. 1 root root 73148 Jan 10 22:20 libfastcommon-1.0.7.tar.gz
[[email protected] fastDFS]#
1.解压libfastcommon
tar -zxvf libfastcommon-1.0.7.tar.gz
make一下
[[email protected] fastDFS]# cd libfastcommon-1.0.7
[[email protected] libfastcommon-1.0.7]# ls
HISTORY INSTALL libfastcommon.spec make.sh README src
[[email protected] libfastcommon-1.0.7]# ./make.sh
如果报错,需要安装
yum install gcc
yum install perl
再make install一下
./make.sh install
执行一下命令
cd /usr/lib64/
ll libfast*
cp libfastcommon.so /usr/lib
2.安装Tracker服务
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS...
[make全家桶 略]
cd /usr/bin/
ll fdfs*
进入目录
[[email protected] bin]# cd /etc/fdfs/
[[email protected] fdfs]# ll
total 20
-rw-r--r--. 1 root root 1461 Jan 10 22:44 client.conf.sample
-rw-r--r--. 1 root root 7829 Jan 10 22:44 storage.conf.sample
-rw-r--r--. 1 root root 7102 Jan 10 22:44 tracker.conf.sample
[[email protected] fdfs]# ll fdfs
参考以下命令复制文件
[[email protected] fdfs]# cd ~
[[email protected] ~]# cd fastDFS/
[[email protected] fastDFS]# cd FastDFS
[[email protected] FastDFS]# ls
client conf fastdfs.spec init.d make.sh README.md stop.sh test
common COPYING-3_0.txt HISTORY INSTALL php_client restart.sh storage tracker
[[email protected] FastDFS]# cd conf/
[[email protected] conf]# ls
anti-steal.jpg client.conf http.conf mime.types storage.conf storage_ids.conf tracker.conf
[[email protected] conf]# cp * /etc/fdfs/
配置tracker服务
vim tracker.conf
修改以下内容
# the base path to store data and log files
base_path=/fastdfs/tracker
创建目录
cd /
mkdir /fastdfs/tracker -p
#创建storage文件夹
cd fastdfs/
mkdir storage
mkdir client
启动tracker服务
cd /usr/bin/
#启动
fdfs_trackerd /etc/fdfs/tracker.conf
#重启服务
#fdfs_trackerd /etc/fdfs/tracker.conf restart
3.安装storage服务
修改配置文件
cd /etc/fdfs/
vi storage.conf
修改以下
# the base path to store data and log files
base_path=/fastdfs/storage
修改图片路径
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/fastdfs/storage
#store_path1=/home/yuqing/fastdfs2
修改tracker的配置
这里写服务器ip即可
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.232.129:22122
修改组名
# in this case, use_storage_id must set to true in tracker.conf,
# and storage_ids.conf must be configed correctly.
group_name=cxl
启动storage
fdfs_storaged /etc/fdfs/storage.conf
查看进程
ps aux|grep stroage
3.使用client上传图片
cd /usr/fdfs/
vi client.conf
修改内容
# the base path to store log files
base_path=/fastdfs/client
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.232.129:22122
启动
cd /usr/bin/
fdfs_test /etc/fdfs/client.conf upload
# 这里会提示报错
上传一张用来模拟的图片
上传
/usr/bin/fdfs_test /etc/fdfs/client.conf upload 1547195788\(1\).jpg
会返回一堆东西
This is FastDFS client test program v5.05
Copyright (C) 2008, Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.
[2019-01-10 23:12:44] DEBUG - base_path=/fastdfs/client, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.232.129, port=23000
group_name=cxl, ip_addr=192.168.232.129, port=23000
storage_upload_by_filename
group_name=cxl, remote_filename=M00/00/00/wKjogVw4F7yAOXOjAAHNdSm0V_0973.jpg
source ip address: 192.168.232.129
file timestamp=2019-01-10 23:12:44
file size=118133
file crc32=699684861
example file url: http://192.168.232.129/cxl/M00/00/00/wKjogVw4F7yAOXOjAAHNdSm0V_0973.jpg
storage_upload_slave_by_filename
group_name=cxl, remote_filename=M00/00/00/wKjogVw4F7yAOXOjAAHNdSm0V_0973_big.jpg
source ip address: 192.168.232.129
file timestamp=2019-01-10 23:12:44
file size=118133
file crc32=699684861
example file url: http://192.168.232.129/cxl/M00/00/00/wKjogVw4F7yAOXOjAAHNdSm0V_0973_big.jpg
[[email protected] ~]#
可以看到地址是remote_filename=M00/00/00/wKjogVw4F7yAOXOjAAHNdSm0V_0973_big.jpg
如果想看到,需要配置nginx
图片存哪了?
4.配置nginx
1.解压fastdfs-nginx的压缩包
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
2.修改config配置文件
[[email protected] fastDFS]# cd fastdfs-nginx-module
[[email protected] fastdfs-nginx-module]# cd src/
[[email protected] src]# ls
common.c common.h config mod_fastdfs.conf ngx_http_fastdfs_module.c
[[email protected] src]# vim config
删除三个local
3.安装nginx
1.安装基本环境
yum install gcc-c++
yum install pcre pcre-devel
yum install zlib zlib-devel
yum install openssl
2.解压nginx
tar zxvf nginx-1.15.8.tar.gz
3.配置nginx
./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/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module= {{{你的fastdfs-nginx-module的路径}}}
make一下
make
make install