分布式存储fastdfs安装使用

1.下载地址https://github.com/happyfish100/fastdfs
https://github.com/happyfish100/fastdfs/wiki安装辅助说明文档
2.安装编译环境
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
三台主机:
172.18.224.100(tracker,client)
172.18.224.101(storage)
172.18.224.100(storage)
3.创建数据存储目录
mkdir /dfs
4.安装libfatscommon
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
./make.sh && ./make.sh install #编译安装
分布式存储fastdfs安装使用
5.安装FastDFS
git clone https://github.com/happyfish100/fastdfs.git --depth 1
./make.sh && ./make.sh install #编译安装
cd fastdfs/conf
分布式存储fastdfs安装使用
6.复制两个nginx访问时使用到的配置文件
cp http.conf /etc/fdfs/
cp mime.types /etc/fdfs/
7.
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客户端文件,测试用
8.172.18.224.100编辑/etc/fdfs/tracker.conf:
base_path=/dfs/tracker ###自己定义的tracker目录
mkdir /dfs/tracker start
/etc/init.d/fdfs_trackerd start
9.172.18.224.101,172.18.224.102 编辑/etc/fdfs/storage.conf
base_path=/dfs/storage ###storage主目录
store_path0=/dfs/storage/0 ###存贮目录
tracker_server=172.18.224.100:22122
http.server_port=8080 ##与tracker文件保持一致
/etc/init.d/fdfs_storaged start ##启动storaged
分布式存储fastdfs安装使用
10.查看fdfs是否安装成功:
fdfs_monitor /etc/fdfs/storage.conf分布式存储fastdfs安装使用
11.编辑client端配置文件:
vim /etc/fdfs/client.conf
base_path=/dfs/client
mkdir -pv /dfs/clinet
12.上传文件:
fdfs_upload_file
分布式存储fastdfs安装使用
fdfs_upload_file /etc/fdfs/client.conf /etc/fstab
查看文件信息fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/rBLgZVwwaiqAFIG_AAABOWqC2ow1549165
13.下载文件
fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/rBLgZVwwaiqAFIG_AAABOWqC2ow1549165 /tmp/fs
14.172.18.224.101,102安装fastdfs-nginx-module
git clone https://github.com/happyfish100/fastdfs-nginx-module.git
/root/fastdfs-nginx-module/src
cp mod_fastdfs.conf /etc/fdfs/
15.安装nginx:
yum install pcre-devel openssl-devel ##安装依赖包
wget http://nginx.org/download/nginx-1.15.4.tar.gz ##下载nginx
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ #添加fastdfs-nginx-module模块
make && make install #编译安装
16.配置nginx:
vim /etc/fdfs/mod_fastdfs.conf

需要修改的内容如下

tracker_server=192.168.52.1:22122 #tracker服务器IP和端口
url_have_group_name=true
store_path0=/home/dfs

配置nginx.config

vim /usr/local/nginx/conf/nginx.conf

添加如下配置

server {

listen       8888;    ## 该端口为storage.conf中的http.server_port相同
server_name  localhost;
location ~/group[0-9]/ {
    ngx_fastdfs_module;
}

}
如果服务器存在多个nginx:
/usr/local/nginx/sbin/nginx -c /usr/local/src/nginx-1.15.4/conf/nginc.conf

注意,必须要保证已经从fastdfs/conf复制了http.conf与mime.types文件至/etc/fdfs/

分布式存储fastdfs安装使用
17.使用curl命令验证fastdfs存储的文件是否可以通过http协议访问:
先随便上传一个文件 fdfs_upload_file /etc/fdfs/client.conf /etc/fstab

curl http://172.18.224.101:8888/group1/M00/00/00/rBLgZlwwd9OAWZztAAABOWqC2ow7681129
分布式存储fastdfs安装使用
验证成功。

上一篇:C++以空格为分隔符分隔string类型


下一篇:stringstream istringstream ostringstream 三者的区别