1、安装编译工具及库文件
# wget
sudo yum install wget
# c++环境
sudo yum install gcc-c++
# FastDFS依赖libevent库
sudo yum -y install libevent perl
2. 安装libfastcommon
libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS运行所需要的一些基础库。
sudo mkdir -p /usr/java
cd /usr/java
sudo wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz -O libfastcommon-1.0.39.tar.gz
sudo tar -zxvf libfastcommon-1.0.39.tar.gz
cd libfastcommon-1.0.39
sudo ./make.sh && sudo ./make.sh install
ln -s /usr/lib64/libfastcommon.so /usr/lib/
3.同时安装tracker和storage
cd /usr/java
sudo wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz -O fastdfs-5.11.tar.gz
sudo tar -zxvf fastdfs-5.11.tar.gz
sudo cd fastdfs-5.11
sudo ./make.sh && sudo ./make.sh install
# 把安装的文件移动到自定义的文件夹中
sudo mkdir -p /usr/java/fastdfs/
sudo ln -s /etc/fdfs /usr/java/fastdfs/conf
sudo cp conf/mime.types conf/http.conf /etc/fdfs
# 修改配置
cd /usr/java/fastdfs/conf
sudo cp tracker.conf.sample tracker.conf
sudo gedit tracker.conf
* base_path=/home/fastdfs
# 启动(也是重启)
sudo mkdir -p /home/fastdfs
sudo /usr/bin/fdfs_trackerd /usr/java/fastdfs/conf/tracker.conf restart
4.安装storage
注意: 如果本服务器上已经安装过tracker,则只需修改storage配置即可
cd /usr/java/fastdfs/conf
sudo cp storage.conf.sample storage.conf
sudo gedit storage.conf
* group_name=group1
* base_path=/home/fastdfs
* store_path0=/home/fastdfs/fdfs_storage
#如果有多个挂载磁盘则定义多个store_path,如下
#store_path1=......
#store_path2=......
* tracker_server=centos-100:22122 #配置tracker服务器:IP注意此IP不能是127.0.0.1
#如果有多个则配置多个tracker
#tracker_server=.....
sudo sudo mkdir -p /home/fastdfs/fdfs_storage
# 启动(也是重启)
sudo /usr/bin/fdfs_storaged /usr/java/fastdfs/conf/storage.conf restart
5.测试
FastDFS安装成功可通过/usr/fastdfs/bin/fdfs_test测试上传、下载等操作。
# 修改配置
cd /usr/java/fastdfs/conf
sudo cp client.conf.sample client.conf
sudo gedit client.conf
* base_path=/home/fastdfs
* tracker_server=centos-100:22122
使用格式:
- /usr/bin/fdfs_test 客户端配置文件地址 upload 上传文件
/usr/bin/fdfs_test /usr/java/fastdfs/conf/client.conf upload 1.jpg
结果
访问地址就是:
http://192.168.200.100/group1/M00/00/00/wKjIZFyD8smAL87NAADtXa53YW0569_big.PNG
因为未与nginx整合,所以暂时不能访问
6.添加到服务
chkconfig fdfs_storaged on
chkconfig fdfs_trackerd on
7、CentOS 7 安装 FastDFS
1、配置 fastdfs-nginx-module
cd /usr/java
sudo wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz -O fastdfs-nginx-module-1.20.tar.gz
sudo tar -zxvf fastdfs-nginx-module-1.20.tar.gz
sudo mv fastdfs-nginx-module-1.20 fastdfs-nginx-module
sudo gedit fastdfs-nginx-module/src/config
* ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
* CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
致命错误:common_define.h:没有那个文件或目录 在这里折磨了好久好久~
8、CentOS 7 安装 Nginx
# 1、安装编译工具、库文件及PCRE库
sudo yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
sudo yum install -y pcre pcre-devel
# 2、安装PCRE库
sudo mkdir -p /usr/java
cd /usr/java
sudo wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
sudo ./configure --prefix=/usr/java/pcre
sudo make && sudo make install
# 查看pcre版本
pcre-config --version
# 3、安装 Nginx
sudo mkdir -p /usr/java
cd /usr/java
sudo wget http://nginx.org/download/nginx-1.14.2.tar.gz
sudo tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
sudo ./configure --prefix=/usr/java/nginx --with-http_stub_status_module --with-http_ssl_module
# sudo --add-module=/usr/java/fastdfs-nginx-module/src #fastdfs和nginx整合模块
# sudo --add-module=/usr/java/ngx_cache_purge #fastdfs集群需要用到
# sudo --with-pcre=/usr/pcre #就用默认的,不指定自定义的pcre
sudo make && sudo make install
cd .. && rm -rf nginx-1.14.2
# 查看nginx版本
/usr/java/nginx/sbin/nginx -v
# 4、配置
sudo cp /usr/java/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
sudo gedit /etc/fdfs/mod_fastdfs.conf
* tracker_server=centos-200:22122
* url_have_group_name = true
* store_path0=/home/fastdfs/fdfs_storage
cd /usr/java/fastdfs-5.11/conf/
sudo cp -f http.conf mime.types /etc/fdfs/
sudo ln -s /home/fastdfs/fdfs_storage/data/ /home/fastdfs/fdfs_storage/data/M00
sudo gedit /usr/java/nginx/conf/nginx.conf
* server {
* listen 80;
* server_name localhost;
* location ~/group([0-9])/M00 {
#跨域
* add_header Access-Control-Allow-Origin *;
* add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
* add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-* Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
* if ($request_method = 'OPTIONS') {
* return 204;
* }
* root /home/fastdfs/fdfs_storage/data;
* ngx_fastdfs_module;
* }
}
# 开启
sudo /usr/java/nginx/sbin/nginx
# 重启
sudo /usr/java/nginx/sbin/nginx -t
8、测试
当前路径自行存放一张命名为1.PNG的图片
/usr/bin/fdfs_test /usr/java/fastdfs/conf/client.conf upload /usr/java/1.PNG
成功显示
[panqt@centos-200 ~]$ /usr/bin/fdfs_test /usr/java/fastdfs/conf/client.conf upload /usr/java/1.PNG
This is FastDFS client test program v5.11
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-03-12 09:54:55] DEBUG - base_path=/home/fastdfs, 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.200.200, port=23000
group_name=group1, ip_addr=192.168.200.200, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKjIyFyHEW-ABA8KAADtXa53YW0385.PNG
source ip address: 192.168.200.200
file timestamp=2019-03-12 09:54:55
file size=60765
file crc32=2927059309
example file url: http://192.168.200.200/group1/M00/00/00/wKjIyFyHEW-ABA8KAADtXa53YW0385.PNG
访问路径记得加上端口:http://192.168.200.200:80/group1/M00/00/00/wKjIyFyHEW-ABA8KAADtXa53YW0385.PNG
网友评论