Linux系统:centos7下搭建Nginx和FastDFS文件管理中间件
本文源码:GitHub·点这里 || GitEE·点这里
一、FastDFS简介
1、基础概念
FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件上传、文件下载等,解决了大容量存储和负载均衡的问题。
2、环境概览
1、默认存在Gcc编译环境,Centos7虚拟机
2、安装LibFastCommon环境
3、FastDFS中间件安装
4、Nginx代理服务器安装
二、安装LibFastCommon
核心流程
下载->解压->编译->安装
## 下载
[root@localhost mysoft]# wget
https://github.com/happyfish100/libfastcommon/archive/V1.0.38.tar.gz
## 解压
[root@localhost mysoft]# tar -zxvf V1.0.38.tar.gz
[root@localhost mysoft]# cd libfastcommon-1.0.38/
## 编译
[root@localhost libfastcommon-1.0.38]# ./make.sh
## 安装
[root@localhost libfastcommon-1.0.38]# ./make.sh install
三、安装FastDFS
流程:下载->解压->编译->安装->创建相关路径->配置跟踪器->
配置数据存储->配置客户端->Nginx环境配置
1、基础安装步骤
## 下载
[root@localhost mysoft]# wget
https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
## 解压
[root@localhost mysoft]# tar -zxvf V5.11.tar.gz
## 编译
[root@localhost mysoft]# cd fastdfs-5.11/
[root@localhost fastdfs-5.11]# ./make.sh
## 安装
[root@localhost fastdfs-5.11]# ./make.sh install
2、创建相关路径
用处后续说明。
[root@localhost data]# mkdir -p /data/fastdfs/log
[root@localhost data]# mkdir -p /data/fastdfs/data
[root@localhost data]# mkdir -p /data/fastdfs/tracker
[root@localhost data]# mkdir -p /data/fastdfs/client
3、配置跟踪器
Tracker -- >> 跟踪器
1)查看配置文件
注意这里目录的转换,这里给的是样例,具体的配置还要自己动手。
[root@localhost fastdfs-5.11]# cd /etc/fdfs/
[root@localhost fdfs]# ll
total 24
client.conf.sample
storage.conf.sample
storage_ids.conf.sample
tracker.conf.sample
2)配置tracker.conf文件
[root@localhost fdfs]# cp tracker.conf.sample tracker.conf
[root@localhost fdfs]# vim tracker.conf
## 关注如下几个配置
## 存储数据和日志文件的基本路径
base_path=/data/fastdfs/tracker
## Http服务端口
http.server_port=80
## 默认提供服务端口
port=22122
3)启动跟踪器
## 启动
[root@localhost fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
## 查看状态
[root@localhost fdfs]# netstat -apn|grep fdfs
4、配置数据存储
1)查看配置文件
[root@localhost fastdfs-5.11]# cd /etc/fdfs/
[root@localhost fdfs]# ll
storage.conf.sample
2)配置storage.conf文件
[root@localhost fdfs]# cp storage.conf.sample storage.conf
[root@localhost fdfs]# vim storage.conf
## 关注如下几个配置
## storage存储data和log的跟路径
base_path=/data/fastdfs/data
## 默认组名
group_name=group1
## 默认端口,相同组的storage端口号必须一致
port=23000
## 配置一个存储路径
store_path_count=1
store_path0=/data/fastdfs/data
## 配置跟踪器IP和端口
tracker_server=192.168.72.130:22122
3)启动存储服务
## 启动
[root@localhost fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
## 查看进程
[root@localhost fdfs]# netstat -apn|grep fdfs
tcp 0:22122 LISTEN 4845/fdfs_trackerd
tcp 0:45422 SYN_SENT 5410/fdfs_storaged
## 查看启动日志
[root@localhost fdfs]# tail -f /data/fastdfs/data/logs/storaged.log
## 日志展示:单台FastDFS安装成功
set tracker leader: 192.168.72.130:22122
## 查看Storage和Tracker是否在通信
[root@localhost fdfs]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
Storage 1:
id = 192.168.72.130
ip_addr = 192.168.72.130 (localhost.localdomain) ACTIVE
5、配置客户端测试
1)查看配置文件
[root@localhost /]# cd /etc/fdfs
[root@localhost fdfs]# ll
total 40
client.conf.sample
2)配置client.conf文件
[root@localhost fdfs]# cp client.conf.sample client.conf
[root@localhost fdfs]# vim client.conf
## 关注如下几个配置
## client数据和日志目录
base_path=/data/fastdfs/client
## 配置跟踪器IP和端口
tracker_server=192.168.72.130:22122
3)客户端测试
调用客户端文件上传命令
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf
返回文件上传的相对路径和编号
group1/M00/00/00/wKhIgl0mmE-ATEXPAAQ2pIoAy98392.jpg
[root@localhost fdfs]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /data/img/img1.jpg
group1/M00/00/00/wKhIgl0mmE-ATEXPAAQ2pIoAy98392.jpg
这样FastDFS单台环境就安装好了,步骤有点繁杂,不过这就是生活。
文件成功上传storage服务器,但是还无法查看下载。需要安装Nginx服务器用来支持Http方式访问文件。
四、安装Nginx
1、下载解压Nginx
## 下载nginx
[root@localhost mysoft]# wget
http://nginx.org/download/nginx-1.15.2.tar.gz
## 解压nginx
[root@localhost mysoft]# tar -zxvf nginx-1.15.2.tar.gz
2、下载解压Fast-Nginx
## 下载fastdfs-nginx
[root@localhost mysoft]#wget
https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
## 解压fastdfs-nginx
[root@localhost mysoft]# mv 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip fast-nginx.zip
[root@localhost mysoft]# unzip fast-nginx.zip
[root@localhost mysoft]# mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1/
fastdfs-nginx-module
3、安装必须依赖
## pcre-devel 环境
[root@localhost nginx-1.15.2]# yum install -y pcre pcre-devel
## zlib-devel 环境
[root@localhost nginx-1.15.2]# yum install -y zlib zlib-devel
## openssl-devel 环境
[root@localhost nginx-1.15.2]# yum install -y openssl openssl-devel
4、配置安装
[root@localhost nginx-1.15.2]# ./configure --add-module=/usr/local/mysoft/fastdfs-nginx-module/src
[root@localhost nginx-1.15.2]# make && make install
5、错误解决
版本问题导致,Fast-Nginx必须使用这个修复版本。
make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] Error 1
make[1]: Leaving directory `/usr/local/mysoft/nginx-1.15.2'
make: *** [build] Error 2
6、查看安装结果
如下情况则表示安装成功了。
[root@localhost nginx-1.15.2]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.15.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
configure arguments: --add-module=/usr/local/mysoft/fastdfs-nginx-module/src
五、测试图片访问
1、配置客户端
## 移动配置文件
[root@localhost src]# pwd
/usr/local/mysoft/fastdfs-nginx-module/src
[root@localhost src]# ll
total 76
Apr 14 2017 mod_fastdfs.conf
[root@localhost src]# cp mod_fastdfs.conf /etc/fdfs/
[root@localhost fdfs]# pwd
/etc/fdfs
[root@localhost fdfs]# vim mod_fastdfs.conf
## 调整如下配置
## 链接超时
connect_timeout=20
## 配置跟踪器IP和端口
tracker_server=192.168.72.130:22122
## 路径包含group
url_have_group_name = true
# 必须和storage配置相同
store_path0=/data/fastdfs/data
2、完善FastDFS配置
[root@localhost fdfs]# cd /usr/local/mysoft/fastdfs-5.11/conf/
[root@localhost conf]# cp anti-steal.jpg http.conf mime.types /etc/fdfs/
3、配置Nginx
在Nginx的80服务端口下添加如下配置。注意这里的路径是Nginx安装自动生成的路径。
[root@localhost nginx]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.conf
server {
listen 80;
location ~/group([0-9])/M00 {
root /data/fastdfs/data;
ngx_fastdfs_module;
}
}
查看配置结果
[root@localhost conf]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.15.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
configure arguments: --add-module=/usr/local/mysoft/fastdfs-nginx-module/src
这样就配置成功了。
4、见证结束的时候
启动Nginx服务。
## 启动
/usr/local/nginx/sbin/nginx
## 停止
/usr/local/nginx/sbin/nginx -s stop
## 重启
/usr/local/nginx/sbin/nginx -s reload
5、访问上传图片
喵喵的,居然成功了,下篇文章见。
http://192.168.72.130
/group1/M00/00/00/wKhIgl0mmE-ATEXPAAQ2pIoAy98392.jpg
六、源代码地址
GitHub·地址
https://github.com/cicadasmile/linux-system-base
GitEE·地址
https://gitee.com/cicadasmile/linux-system-base

Linux系统:centos7下搭建Nginx和FastDFS文件管理中间件的更多相关文章
- linux系统centOS7下搭建redis集群中ruby版本过低问题的解决方法
问题描述: 在Centos7中,通过yum安装ruby的版本是2.0.0,但是如果有些应用需要高版本的ruby环境,比如2.2,2.3,2.4... 那就有点麻烦了,譬如:我准备使用redis官方给的 ...
- 在centos7下搭建nginx环境,并配置负载均衡,最终能达到通过域名直接访问的目的
1.关于nginx:个人理解的nginx它的主要用途就是负载均衡,当然可能还有其他一些功能可能我们不长用到,我们通过nginx可以干什么呢?为什么要引入它呢?原因是当有高并发访问服务器时,服务器可能会 ...
- CentOS7下搭建Nginx+PHP7的安装配置
一.安装编译工具及库文件: yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 环境要求 nginx是C ...
- centos7下搭建nginx+php7.1+mariadb+memcached+redis
一.环境准备 1.首先介绍一下环境,以及我们今天的主角们 我用的环境是最小化安装的centos7,mariadb(江湖传言mysql被oracle收购后,人们担心像java一样毁在oracle手上于是 ...
- linux系统虚拟机下安装nginx基础
虽然安装nginx什么的 .以及如何配置等等一系列的资料案例已经很多了 但是作为菜鸟的我还是搞了半天哈 官网上面也有.但是一些细节方面的并没有说明.导致踩了半天坑才搞好 本案例的系统环境 wi ...
- Linux系统:Centos7下搭建PostgreSQL关系型数据库
本文源码:GitHub·点这里 || GitEE·点这里 一.PostgreSQL简介 1.数据库简介 PostgreSQL是一个功能强大的开源数据库系统,具有可靠性.稳定性.数据一致性等特点,且可以 ...
- Linux系统centOS7在虚拟机下的安装及XShell软件的配置
前面的话 本文将详细介绍Linux系统centOS7在虚拟机下的安装 准备工作 [系统下载] 在安装centOS7之前,首先在官网下载合适的版本 然后,选择一个链接下载即可 [虚拟机配置] 接下来,需 ...
- Hyperledger超级账本在Centos7下搭建运行环境
超级账本(hyperledger)是Linux基金会于2015年发起的推进区块链数字技术和交易验证的开源项目,加入成员包括:荷兰银行(ABN AMRO).埃森哲(Accenture)等十几个不同利益体 ...
- linux系统CentOS7
linux系统CentOS7 到http://mirrors.sohu.com/mysql/下载想要的mysql版本 这里用到的是 mysql-5.6.33-linux-glibc2.5-x86_64 ...
随机推荐
- eclipse 代码问题总结
隐藏控件,在xml文件中写属性 android:visibility="gone"
- 关于JAVA的Random类的冷知识(转自菜鸟V)
JAVA的Random类(转) Random类 (java.util) Random类中实现的随机算法是伪随机,也就是有规则的随机.在进行随机时,随机算法的起源数字称为种子数(seed),在种子数的基 ...
- VS2019添加Link to SQL类之后,LinqDataSource配置数据源没有可选项
原创. 环境:visual studio 2019 ,.net framwork 4.0 问题: 1.新建Linq to SQL类后(.dbml文件),从服务器资源管理面板中数据库连接中,把表Mill ...
- Android Activity启动流程, app启动流程,APK打包流程, APK安装过程
1.Activity启动流程 (7.0版本之前) 从startActivity()开始,最终都会调用startActivityForResult() 在该方法里面会调用Instrumentation. ...
- spring boot 2 + shiro 实现简单的身份验证例子
Shiro是一个功能强大且易于使用的Java安全框架,官网:https://shiro.apache.org/. 主要功能有身份验证.授权.加密和会话管理.其它特性有Web支持.缓存.测试支持.允许一 ...
- SVN清理失败(clean up)或者(lock)问题进入死循环最终解决方案
解决方法: step1: 到 sqlite官网 (http://www.sqlite.org/download.html) 下载 sqlite3.exe step2: 将下载到的 sqlite3.ex ...
- python 内置函数zip,map,三元,lambda表达式
#内置函数zip(),将多个可迭代对象(集合等)按照顺序进行组合成tuple元祖,放在zip 对象进行存储,: #当参数为空时候,返回空 #如果 zip() 函数压缩的两个列表长度不相等,那么 zip ...
- IT兄弟连 HTML5教程 W3C盒子模型
日常生活中所见的盒子也就是能装东西的一种箱子,如果家里的东西很多,那么就需要按类别装到不同的箱子中.网页中的内容表现也是一样的,如果页面内容比较多,又想让页面更整洁.更美观.有很好的用户体验,则也需要 ...
- Jmeter常用的两大性能测试场景
一.阶梯式场景 该场景主要应用在负载测试里面,通过设定一定的并发线程数,给定加压规则,遵循“缓起步,快结束”的原则,不断地增加并发用户来找到系统的性能瓶颈,进而有针对性的进行各方面的系统优化. 使用到 ...
- Serverless 实战——使用 Rendertron 搭建 Headless Chrome 渲染解决方案
为什么需要 Rendertron? 传统的 Web 页面,通常是服务端渲染的,而随着 SPA(Single-Page Application) 尤其是 React.Vue.Angular 为代表的前端 ...