linux 环境搭建其二 :安装 fastdfs + nginx

本文详细介绍FastDFS的安装配置过程,包括依赖环境搭建、FastDFS各组件配置及测试等关键步骤,帮助读者快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

fastfds 配置步骤

1 gcc 编译器安装
查看是否安装
# whereis gcc
安装
# yum install gcc
# yum install gcc-c++

2 安装工具包
pcre
# whereis pcre
# yum -y install pcre pcre-devel
zlib
# whereis zlib
# yum -y install zlib zlib-devel
openssl
# whereis openssl
# yum -y install openssl openssl-devel
libfastcommon
下载链接
git clone https://github.com/happyfish100/libfastcommon.git // 如果提示你没有下载git, 先去下载git
编译 安装
# ./make.sh && ./make.sh install
查看 libfastcommon.so 是不是放到 /usr/lib64 文件夹下 , 是的话 修改软链接
# 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/libfdfsclient.so /usr/local/lib/libfdfsclient.so
# ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

4 fastdfs
地址 https://github.com/happyfish100/fastdfs/releases
找到版本 ,我自己下载的 V5.11
下载
# wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
解压
# tar -zxvf V5.11.tar.gz
# cd fastdfs-5.11
编译 安装
# ./make.sh
# ./make.sh install
没有报错就说明安装成功了,在log中我们可以发现安装路径:
安装成功后 /etc/fdfs 文件夹下 就会生成4个.sample文件

创建存储文件夹
fastdfs 存储文件夹 目录结构
/opt 			#根目录
/opt/fastdfs/track 	#tracker文件配置路径
/opt/fastdfs/storage   #storage配置路径
/opt/fastdfs/storage_data # 存儲路徑
/opt/fastdfs/client    #client路径

5 配置 tracker,Storage,Clent,HTTP

进入/etc/fdfs目录。会看到三个.sample后缀的文件
# cd /etc/fdfs
# ls
复制三个文件
# cp tracker.conf.sample tracker.conf # 配置跟踪文件
# cp storage.conf.sample storage.conf # 配置跟踪文件
# cp client.conf.sample client.conf # 配置跟踪文件


1)配置Tracker服务
进入conf配置文件
# vim /etc/fdfs/tracker.conf
修改下面的参数
# port=22122 
# base_path=/opt/fastdfs/track	
# http.server_port=6666 # 端口

配置好之后 修改软引用
# ln -s /usr/bin/fdfs_trackerd /usr/local/bin
# ln -s /usr/bin/stop.sh /usr/local/bin
# ln -s /usr/bin/restart.sh /usr/local/bin
启动 Tracker 服务器
# service fdfs_trackerd start
查看服务是否跑起来
# netstat -unltp|grep fdfs
配置开机启动 
# vim /etc/rc.d/rc.local
追加
# service fdfs_trackerd start
检查rc.local 文件的权限
# ll /etc/rc.d/rc.local
如果权限太低就添加权限
# chmod +x /etc/rc.d/rc.local

2)配置storage
进入conf配置文件
# vim /etc/fdfs/storage.conf
修改参数
disabled=false #启用配置文件(默认启用)
group_name=group1 #组名,根据实际情况修改
base_path=/opt/fastdfs/storage #指定日志位置  
store_path0=/opt/fastdfs/storage_data #指定数据位置  
tracker_server=192.168.1.210:22122  #指定tracker服务器地址  
http.server_port=8888
建立软链接
# ln -s /usr/bin/fdfs_storaged /usr/local/bin
启动服务
# service fdfs_storaged start
检查是否成功
# ps -ef|grep fdfs
1.检查是否存在很多录, 如果有说明创建成功,跳过2
# cd /opt/fastdfs/storage_data/data
2.如果没有,检查日志文件,排查错误原因
# cd /opt/fastdfs/storage_data/log
# cat storaged.log

建立 tracker 和 storage 的联系
# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
在日志中见到 192.168.1.210  ACTIVE 说明成功

添加开机启动
# vim /etc/rc.d/rc.local
追加配置
# service fdfs_storaged start

3)配置client
 
# vim /etc/fdfs/client.conf  
修改参数
# base_path=/opt/fastdfs/track
# tracker_server=192.168.1.210:22122
# http.tracker_server_port=6666

8 测试上传功能

上传测试,自己要在/opt/fastdfs 中添加要上传的文件
# /usr/bin/fdfs_upload_file  /etc/fdfs/client.conf  /opt/fastdfs/1.jpg 
执行成功之后会返回一个路径,到路径中就可以找到图片
# cd /opt/fastdfs/storage_data/data/00/00  

9 安装 nginx 和 fastdfs-nginx-module,pcre,zlib

1)未安装nginx
下载
# wget  https://nginx.org/download/nginx-1.10.1.tar.gz
# tar -zxvf nginx-1.10.1.tar.gz

安装Nginx
# cd nginx-1.10.1
# ./configure --prefix=/usr/local/nginx
# make && make install


查找安装路径
# whereis nginx

启动,停止 nginx
# cd /usr/local/nginx/sbin/nginx
# ./nginx #启动
# ./nginx -s stop #此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程
# ./nginx -s quit #:此方式停止步骤是待nginx进程处理任务完毕进行停止。
# ./nginx -s reload

查看进程
# ps aux|grep nginx
设置开机启动
# vim /etc/rc.local
# /usr/local/nginx/sbin/nginx
设置执行权限
# chmod 755 rc.local

2)安装 fastdfs-nginx-module
下载
# wget https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip

解压
# unzip 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
修改名称
# mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1  fastdfs-nginx-module-master
编译安装
# ./configure --add-module=/usr/local/fastdfs-nginx-module-master/src
# make
# make install
查看插件是否安装完成
#  /usr/local/nginx/sbin/nginx -V

10 配置fastdfs-nginx-module 和 Nginx

1)复制conf文件

# cp -r /usr/local/fastdfs-5.11/conf/http.conf /etc/fdfs/
# cp -r /usr/local/fastdfs-5.11/conf/mime.types /etc/fdfs/
# cp -r /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
  1. 配置刚刚拷贝好的 mod-fastdfs.conf
    # vim /etc/fdfs/mod_fastdfs.conf

修改conf

base_path=/opt/fastdfs/storage #保存日志目录
tracker_server=192.168.1.210:22122  #tracker服务器的IP地址以及端口号
storage_server_port=23000 #storage服务器的端口号
url_have_group_name = true  #文件 url 中是否有 group 名
store_path0=/opt/fastdfs/storage_data  # 存储路径
group_count = 3 

接下来就需要在文件尾部追加这3个group setting:

[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/opt/fastdfs/storage_data

[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/opt/fastdfs/storage_data

[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/opt/fastdfs/storage_data

建立软链接

# ln  -s  /opt/fastdfs/storage_data/data  /opt/fastdfs/storage_data/data/M00
# cd /usr/local/nginx/conf
# vim nginx.conf

加入

listen       9999;

location ~/group1/M00 {
	root /opt/fastdfs/storage/data;
	ngx_fastdfs_module;
}

启动nginx

# /usr/local/nginx/sbin/nginx

访问 http://192.168.1.210:9999/ 可以看到nginx主页

以上是安装storage服务器,接下来看tracker服务器的nginx安装
5) 最后一步是修改 /etc/fdfs/client.conf

base_path=/opt/fastdfs/storage  #日志存放路径
tracker_server=192.168.1.210:22122  #tracker 服务器 IP 地址和端口号
http.tracker_server_port=6666  # tracker 服务器的 http 端口号,必须和tracker的设置对应起来

12 上传测试
上传文件

# /usr/bin/fdfs_upload_file  /etc/fdfs/client.conf  /opt/fastdfs/2.jpg

复制日志中的url 用浏览器打开,前缀是ip 地址

13 关闭防火墙

# vim /etc/sysconfig/iptables
加入这一行
# -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
# service iptables restart

14 nginx 加入的插件
如果你面前的nginx是原先有别人安装好的, 你自己要重新加入插件之前, 查看版本, 然后把原来的版本记下来, 然后重新 执行
./configure --prefix=/usr/local/nginx2 --sbin-path=/usr/local/nginx2/nginx --conf-path=/usr/local/nginx2/nginx.conf --pid-path=/usr/local/nginx2/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.32 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.0.1t --add-module=/usr/local/fastdfs-nginx-module-master/src

15 查看图片的目录

#  http://192.168.1.210/group1/M00/00/00/wKgB0lrO_oeAQXGrAAMe3Ek_BLQ467.jpg

原文地址:https://blog.youkuaiyun.com/wlwlwlwl015/article/details/52619851

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值