CentOS7安装fastdfs(单机部署)

CentOS7安装fastdfs(单机部署)

相关介绍及安装

centos 7.x
libfatscommon FastDFS分离出的一些公用函数包
FastDFS FastDFS本体
fastdfs-nginx-module FastDFS和nginx的关联模块
nginx nginx1.15.4

安装编译环境

yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y

磁盘存放目录

说明 位置
所有安装包 /usr/local/src
数据存储位置 /home/dfs/
#data/logs都存在了dfs
mkdir /home/dfs #创建数据存储目录
cd /usr/local/src #切换到安装目录准备下载安装包

安装libfatscommon

git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
./make.sh && ./make.sh install #编译安装

安装FastDFS

cd ../ #返回上一级目录
git clone https://github.com/happyfish100/fastdfs.git --depth 1
cd fastdfs/
./make.sh && ./make.sh install #编译安装
#配置文件准备
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 #客户端文件,测试用
cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ #供nginx访问使用
cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ #供nginx访问使用

安装fastdfs-nginx-module

cd ../ #返回上一级目录
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs

安装nginx

wget http://nginx.org/download/nginx-1.15.4.tar.gz #下载nginx压缩包
tar -zxvf nginx-1.15.4.tar.gz #解压
cd nginx-1.15.4/
#添加fastdfs-nginx-module模块
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ 
make && make install #编译安装

单机部署配置

tracker配置

#服务器ip为 192.168.0.104

vim /etc/fdfs/tracker.conf

#需要修改的内容如下
port=22122  # tracker服务器端口(默认22122,一般不修改)
base_path=/home/dfs  # 存储日志和数据的根目录

storage配置

vim /etc/fdfs/storage.conf

#需要修改的内容如下
port=23000  # storage服务端口(默认23000,一般不修改)
base_path=/home/dfs  # 数据和日志文件存储根目录
store_path0=/home/dfs  # 第一个存储目录
tracker_server=192.168.0.104:22122  # tracker服务器IP和端口
http.server_port=8888  # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)

配置nginx访问

vim /etc/fdfs/mod_fastdfs.conf

#需要修改的内容如下
tracker_server=192.168.0.104: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;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
    }
}

启动

关闭防火墙

不关闭防火墙的话,无法远程访问。

systemctl stop firewalld.service

启动tracker

/etc/init.d/fdfs_trackerd start

启动storage

/etc/init.d/fdfs_storaged start

启动nginx

/usr/local/nginx/sbin/nginx

测试

给CentOS虚拟机上传图片

xhsell6插件下载及上传

#安装插件
yum -y install lrzsz

#上传文件
rz -y

我的操作

[root@bogon home]# mkdir picture
[root@bogon home]# rz -y

[root@bogon home]# ll
总用量 364
-rw-r--r--. 1 root root 369495 3月  16 15:00 63d9f2d3572c11df45aea5666e2762d0f703c27c.jpg
drwxr-xr-x. 4 root root     30 3月  16 14:59 dfs
drwxr-xr-x. 2 root root      6 3月  16 15:04 picture
drwxr-xr-x. 3 root root     19 3月   9 16:26 software

mv命令移动和重命名

要把home下的jpg图片移动到picture文件夹下,并重命名为zly.jpg

[root@bogon home]# mv 63d9f2d3572c11df45aea5666e2762d0f703c27c.jpg picture/
[root@bogon home]# ll
总用量 0
drwxr-xr-x. 4 root root 30 3月  16 14:59 dfs
drwxr-xr-x. 2 root root 58 3月  16 15:05 picture
drwxr-xr-x. 3 root root 19 3月   9 16:26 software
[root@bogon home]# cd picture/
[root@bogon picture]# ll
总用量 364
-rw-r--r--. 1 root root 369495 3月  16 15:00 63d9f2d3572c11df45aea5666e2762d0f703c27c.jpg
[root@bogon picture]# mv 63d9f2d3572c11df45aea5666e2762d0f703c27c.jpg zly.jpg
[root@bogon picture]# ls
zly.jpg

配置client

vim /etc/fdfs/client.conf

#需要修改的内容如下
base_path=/home/dfs
tracker_server=192.168.0.104:22122    #tracker服务器IP和端口

#保存后测试,返回ID表示成功 如:group1/M00/00/00/wKgAaFyMoNKAUNcVAAWjVxW4v70993.jpg
fdfs_upload_file /etc/fdfs/client.conf /home/picture/zly.jpg 

nginx访问

访问:http://192.168.0.104:8888/group1/M00/00/00/wKgAaFyMoNKAUNcVAAWjVxW4v70993.jpg

在这里插入图片描述

group1/M00/00/00/wKgAaFyMoNKAUNcVAAWjVxW4v70993.jpg 这个group1是配置文件/etc/fdfs/mod_fastdfs.conf中默认配置

# the group name of the local storage server
group_name=group1

相关命令

防火墙

#不关闭防火墙的话无法使用
systemctl stop firewalld.service #关闭
systemctl restart firewalld.service #重启

tracker

/etc/init.d/fdfs_trackerd start #启动tracker服务
/etc/init.d/fdfs_trackerd restart #重启动tracker服务
/etc/init.d/fdfs_trackerd stop #停止tracker服务
chkconfig fdfs_trackerd on #自启动tracker服务

storage

/etc/init.d/fdfs_storaged start #启动storage服务
/etc/init.d/fdfs_storaged restart #重动storage服务
/etc/init.d/fdfs_storaged stop #停止动storage服务
chkconfig fdfs_storaged on #自启动storage服务

nginx

/usr/local/nginx/sbin/nginx #启动nginx
/usr/local/nginx/sbin/nginx -s reload #重启nginx
/usr/local/nginx/sbin/nginx -s stop #停止nginx

参考文章地址:https://github.com/happyfish100/fastdfs/wiki

发布了37 篇原创文章 · 获赞 22 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/stormkai/article/details/88600370