FastDFS安装笔记 - CentOS7.x环境

官方安装参考:https://github.com/happyfish100/fastdfs/wiki/

【下载】

下载地址:https://github.com/happyfish100

版本选择:fastdfs-6.06 + libfastcommon-1.0.43 


# 安装相关工具和依赖
yum -y install gcc gcc-c++ make cmake automake autoconf libstdc++-devel pcre pcre-devel zlib-devel openssl openssl-devel libevent
yum -y install git  libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim 

# 也可以单独一个个安装:
yum -y install perl
yum -y groups install Development Tools 

yum -y install libevent
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
yum install zip unzip

【防火墙配置】

最后我们要访问服务器 首先要通过防火墙,最简单的方法直接关闭防火墙,暴露所有接口,当然也可以选择暴露你要用的接口,
这里我们选择最简单的,直接关闭,先查看一下是不是开启了。

# firewall-cmd --state          -- 查看默认防火墙状态
# systemctl stop firewalld.service    -- 停止firewall
# systemctl disable firewalld.service   -- 禁止firewall开机启动

最后在查看一下状态是否确定关闭了,简单暴力,当然仅限于懒人开发,真实环境肯定不能这么做

安装目录:/usr/local/soft/fastdfs/
**********************************************************************************************************************************************
【1.安装libfastcommon】

# tar -zxvf  libfastcommon-1.0.43.tar.gz

# cd libfastcommon-1.0.43
# 编译安装:
[root@centos01 libfastcommon-1.0.43]#  ./make.sh && ./make.sh install

# libfastcommon的默认安装路径是:/usr/lib64,而FastDFS主程序设置的安装目录为/usr/local/lib,所以需要创建libfastcommon的核心程序的软连接 (根据自己环境按需操作,可选)
# mkdir /usr/local/lib
# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
# ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
*******************************************************【2.安装FastDFS】****************************************************************
【2.安装FastDFS】

# tar -zxvf  fastdfs-6.06.tar.gz

# cd fastdfs-6.06

# 编译安装: ./make.sh && ./make.sh install
[root@centos01 fastdfs-6.06]# ./make.sh && ./make.sh install

# 编译安装过程中会自动创建如下目录:
mkdir -p /usr/bin
mkdir -p /etc/fdfs
mkdir -p /usr/lib64
mkdir -p /usr/lib
/usr/include/fastdfs

# 查看过滤:cd /etc/init.d/ && ls | grep fdfs
# 查看过滤:cd /usr/bin/  && ls | grep fdfs

# 服务脚本位置
/etc/init.d/fdfs_storaged
/etc/init.d/fdfs_trackerd

# 配置文件位置
/etc/fdfs/client.conf.sample
/etc/fdfs/storage.conf.sample
/etc/fdfs/storage_ids.conf.sample
/etc/fdfs/tracker.conf.sample

# 校正相关脚本文件路径,如果路径正确则无需修改
# vim /etc/init.d/fdfs_storaged   -- 进行相关路径确认与必要时的修改
# vim /etc/init.d/fdfs_trackerd  -- 进行相关路径确认与必要时的修改

*****************************************************【部署配置FastDFS跟踪器tracker】**************************************************
【部署配置FastDFS跟踪器tracker】

# 创建tracker文件夹:mkdir -p :递归创建目录,即使上级目录不存在,会按目录层级自动创建目录
# mkdir -p  /usr/local/soft/fastdfs/fdfa/tracker

# 修改配置文件:
# /etc/fdfs
# cp  /etc/fdfs/*  /usr/local/soft/fastdfs/config_bak/   -- 备份原始配置文件
# cp tracker.conf.sample tracker.conf  或者重命名文件:mv tracker.conf.sample tracker.conf
# 开始配置
# vim  /etc/fdfs/tracker.conf
# 修改base_path,指向自己创建的tracker文件夹:/usr/local/software/fastdfs/fdfa/tracker
# the base path to store data and log files
# base_path = /home/yuqing/fastdfs
base_path = /usr/local/soft/fastdfs/fdfa/tracker/

# 保存退出后启动 tracker:/etc/init.d/fdfs_trackerd /etc/fdfs/tracker.conf start
[root@izbp fdfs]# /etc/init.d/fdfs_trackerd start
Reloading systemd:                                         [  OK  ]
Starting fdfs_trackerd (via systemctl):                    [  OK  ]

# 启动成功后,tracker文件夹中会多出:data和logs两个文件夹

# 查看进程,确认tracker启动状态,使用命令ps -ef|grep fdfs、netstat -unltp | grep fdfs
# 查看端口22122是否开始监听,确认启动是否成功。
# ps -ef|grep fdfs
# netstat -unltp | grep fdfs

# 停止tracker命令:/etc/init.d/fdfs_trackerd stop

# 如果有需要(生产环境),也可以把tracker设置为开机启动
# vim /etc/rc.d/rc.local
# 在文件中添加:/etc/init.d/fdfs_trackerd start

至此,一个简单的tracker配置就完成了,tracker也成功启动

******************************************************【部署配置FastDFS存储器storage】***************************************************

【部署配置FastDFS存储器storage】

# 如果tracker与storage是部署在同一台服务器上,为避免冲突,先关闭tracker
# /etc/init.d/fdfs_trackerd stop
# 创建storage文件夹:
# mkdir -p  /usr/local/soft/fastdfs/fdfa/storage
# cd /etc/fdfs
# cp storage.conf.sample  storage.conf

# 配置storage.conf,主要配置参数:   base_path、store_path0、tracker_server、http.server_port
# vim /etc/fdfs/storage.conf

# /usr/local/software/fastdfs/fdfa/storage/

group_name = group1  
base_path = /usr/local/software/fastdfs/fdfa/storage/ 
store_path0 = /home/software/fastfdfs/fdfa/storage  
store_path_count = 1
tracker_server = 47.97.27.199:22122
http.server_port = 8888

注:注意对应的group_name

# 保存退出后启动storage:必须先启动tracker,再启动storage
# /etc/init.d/fdfs_trackerd start
# fdfs_storaged /etc/fdfs/storage.conf start

[root@centos01 fdfs]# /etc/init.d/fdfs_trackerd start
Starting fdfs_trackerd (via systemctl):                    [  OK  ]
[root@centos01 fdfs]# /etc/init.d/fdfs_storaged start
Starting fdfs_storaged (via systemctl):                    [  OK  ]

# 跟踪器storage正常启动成功后,storage目录下也会多出data 与 logs两个文件夹

******************************************************【配置client.conf与测试上传文件】******************************************************
【客户端配置:client.conf】
# 主要配置:base_path、tracker_server
# cp /etc/fdfs/client.conf.sample client.conf
# vim /etc/fdfs/client.conf
base_path = /usr/local/software/fastdfs/fdfa/tracker
tracker_server = 47.97.27.199:22122
# 保存退出

【测试FastDFS上传文件】

# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf  /_file_path/file_name
# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/software/tmp_file/Linux命令.txt 

[root@centos01 etc]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/software/tmp_file/beauty.jpg
group1/M00/00/00/L2Ebx17Mw5GAZtn1AAFe5ybxNag739.jpg


************************************************************【4.安装Nginx】***************************************************************
【4.安装Nginx】

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


*********************************************【安装fastdfs-nginx-module 并配置 nginx 访问】********************************************

【安装fastdfs-nginx-module 并配置 nginx 访问】

fastdfs-nginx-module模块只需要安装到storage上
为什么要在fastdfs的storage端,安装fastdfs-nginx-module?
答案:https://www.cnblogs.com/littleatp/p/4361318.html

# tar -zxvf fastdfs-nginx-module-1.22.tar.gz
# cd fastdfs-nginx-module-1.22

# 矫正config文件中的路径:去掉路径中的“local”
# vim /usr/local/software/fastdfs/fastdfs-nginx-module-1.22/src/config
ngx_module_incs="/usr/local/include" 改为:ngx_module_incs="/usr/include"

# wq保存退出

# 2.删除之前安装的nginx:整个/usr/local/nginx文件夹都要删除
# cd /usr/local/
# rm -rf /usr/local/nginx/

# 3.重新编译安装nginx
# ./configure --add-module=/usr/local/software/fastdfs/fastdfs-nginx-module-1.22/src/
# make && make install

# 4.复制mod_fastdfs.conf文件到目录:/etc/fdfs/
# cp /usr/local/software/fastdfs/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/

# 5.配置:/etc/fdfs/mod_fastdfs.conf
# vim /etc/fdfs/mod_fastdfs.conf
# 主要配置如下几个参数:tracker_server、url_have_group_name、store_path0

tracker_server=47.97.27.199:22122
url_have_group_name = true
store_path0=/usr/local/software/fastdfs/fdfa/storage
group_count = 1
# 在文件末尾加上组的详细信息
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/usr/local/software/fastdfs/fdfa/storage

# 6.复制/usr/local/software/fastdfs/fastdfs-6.06/conf目录下的http.conf、mime.types两个文件到/etc/fdfs目录下
[root@centos01 fdfs]# cp /usr/local/software/fastdfs/fastdfs-6.06/conf/http.conf /etc/fdfs/
[root@centos01 fdfs]# cp /usr/local/software/fastdfs/fastdfs-6.06/conf/mime.types /etc/fdfs/

# 7.创建软链接,在/usr/local/software/fastdfs/fdfa/storage/文件存储目录下创建软连接,将其连接到实际存储数据的目录
# ln -s /usr/local/software/fastdfs/fdfa/storage/data/  /usr/local/software/fastdfs/fdfa/storage/data/M00

#8.修改nginx配置:/usr/local/nginx/conf/nginx.conf

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

# 再开个同域名不同端口的项目,添加一个server配置:

URL匹配正则表达式:location ~/group([0-9])/M00   或 location ~/group([0-9])/M00

    server {
        listen       8888;
        server_name  localhost;
                                      
                                   
        location ~/group([0-9])/M00 {
            ngx_fastdfs_module;
        }
                                                                               
        error_page   500 502 503 504  /50x.html;
        
        location = /50x.html {
            root   html;
        }

    }

# 注意:nginx里面配置的端口要和/etc/fdfs/storage.conf文件中的http.server_port值保持一致

# 防火墙相关配置:添加端口22122,23000等

 firewall-cmd --zone=public --add-port=80/tcp --permanent  
#  firewall-cmd --zone=public --add-port=22122/tcp --permanent
#  firewall-cmd --zone=public --add-port=23000/tcp --permanent
#  firewall-cmd --zone=public --add-port=8888/tcp --permanent
# firewall-cmd --reload 
# firewall-cmd --list-port

# 重新启动或者加载nginx配置
# /usr/local/nginx/sbin/nginx -s reload

# 启动Nginx
[root@iZbp1c527y2uc9f7yez4g4Z fdfs]# /usr/local/nginx/sbin/nginx 
ngx_http_fastdfs_set pid=17098
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

# 从浏览器访问上传的文件,如果无法访问,将nginx、跟踪器、存储器全部重新启动一下再次尝试

http://ip:port/group1/M00/00/00/L2Ebx17M41GAKZ3UAAFe5ybxNag876.jpg


********************************************************************************

【编译安装后一些文件的默认位置】

/etc/rc.d/init.d/fdfs_trackerd
/usr/bin/fdfs_trackerd
/usr/local/soft/fastdfs/fastdfs-6.06/tracker/fdfs_trackerd
/usr/local/soft/fastdfs/fastdfs-6.06/init.d/fdfs_trackerd
/etc/rc.d/init.d/fdfs_storaged
/usr/bin/fdfs_storaged
/usr/local/soft/fastdfs/fastdfs-6.06/storage/fdfs_storaged
/usr/local/soft/fastdfs/fastdfs-6.06/init.d/fdfs_storaged


版权声明:本文为qq_19783793原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。