fdfs安装启动及性能优化

fsatDFS安装

1、使用 wget 命令下载压缩包,如果没有 wget 命令使用 yum 命令安装
yum install wget
2、下载 fastdfs
wget -c “https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz”
3、下载 libfastcommon
wget -c “https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz”
4、下载 fastdfs-nginx-module
wget -c “https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz”
5、下载 nginx
wget -c http://nginx.org/download/nginx-1.17.7.tar.gz
6、安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
7、测试环境关闭防火墙
systemctl stop firewalld.service
8、开机禁用防火墙
systemctl disable firewalld.service
9、查看防火墙状态
firewall-cmd --state

2、编译安装

2.1、编译安装 libfastcommon

1、进入解压后的目录
cd /root/download/libfastcommon-1.0.43
2、编译安装
./make.sh && ./make.sh install
3、检查
ls /usr/lib64|grep libfastcommon
ls /usr/lib|grep libfastcommon
出现libfastcommon.so即成功

2.2、编译安装 fastdfs

cd /root/download/fastdfs-6.06
2、编译安装
./make.sh && ./make.sh install
3、检查
ls /usr/bin|grep fdfs
4、启用配置文件
cd /etc/fdfs/
cp storage.conf.sample storage.conf
cp client.conf.sample client.conf
cp tracker.conf.sample tracker.conf
mkdir -p /fastdfs/tracker
5、修改 tracker.conf 文件
vi /etc/fdfs/tracker.conf
修改内容base_path = /fastdfs/tracker,将base_path 修改
6、启动 tracker 服务
/etc/init.d/fdfs_trackerd start
7、检查服务是否启动
ps -ef|grep fdfs
8、修改 storage.conf 文件
vi /etc/fdfs/storage.conf
修改内容base_path = /fastdfs/tracker,将base_path 修改
base_path = /fastdfs/tracker
store_path0 = /fastdfs/storage
tracker_server = 192.168.2.128:22122
9、创建目录
mkdir -p /fastdfs/storage
10、启动 storage 服务
/etc/init.d/fdfs_storaged start
12、编辑 client.conf 文件
vi /etc/fdfs/client.conf
tracker_server = 192.168.2.128:22122
base_path = /fastdfs/tracker
启动Storage
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
重启命令
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
测试文件上传
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/xxx.txt

三、storage服务安装nginx

解压
tar -zxvf nginx-1.19.0.tar.gz
进入解压目录
cd nginx-1.19.0
安装
./configure
make
make install

检查安装
/usr/local/nginx/sbin/nginx -v
启动nginx
/usr/local/nginx/sbin/nginx
检查启动状态
lsof -i:80
停止nginx
/usr/local/nginx/sbin/nginx -s stop
四、安装fastdfs-nginx-module
解压
tar -zxvf fastdfs-nginx-module-1.22.tar.gz
进入nginx安装目录,添加fastdfs-nginx-module模块
cd nginx-1.19.0
./configure --add-module=/root/fastdfs-nginx-module-1.22/src/
安装
make && make install
检查安装
/usr/local/nginx/sbin/nginx -V

复制mod_fastdfs.conf文件
cp /root/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
编辑mod_fastdfs.conf文件
vim /etc/fdfs/mod_fastdfs.conf

tracker_server=192.168.2.128:22122
store_path0=/fastdfs/storage
url_have_group_name = true

拷贝配置
cp /root/fastdfs-6.06/conf/http.conf /etc/fdfs/http.conf
cp /root/fastdfs-6.06/conf/mime.types /etc/fdfs/mime.types
编辑nginx配置文件
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;
}
}
启动nginx
/usr/local/nginx/sbin/nginx
测试上传一个文件,使用nginx访问
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/cwp/front.log
访问
curl http://127.0.0.1:8888/group1/M00/00/00/CmMTMGN8fOyANwnwAAAKfRfuBYM335.log
访问成功!

问题解决

fastdfs报错。tracker_proto.c, line: 50, server: 192.168.96.152:22122, response status 2
解决:
仔细检查/etc/fdfs/storage.conf 与/etc/fdfs/tracker.conf 这两个配置文件。尤其检查看 ip和端口号
命令
pkill -9 fdfs
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

FastDFS 如何优化性能

1.最大并发连接数

配置文件:tracker.conf 和 storage.conf
参数名:max_connections
缺省值:256,默认配置:1024

FastDFS为一个连接分配一个task buffer,为了提升分配效率,FastDFS采用内存池的做法。FastDFS老版本直接事先分配 max_connections 个buffer,这个做法显然不是太合理,在max_connections 设置过大的情况下太浪费内存。v5.04对预分配采用增量方式,tracker一次预分配1024个,storage一次预分配256个。

task buffer实际内存占用情况测算如下

改进前:max_connections * buffer_size
改进后:预分配buffer数 * buffer_size

使用v5.04及后续版本,可以根据实际需要将 max_connections 设置为一个较大的数值,比如 10240 或65535 甚至更大。

友情提示:此时需要将一个进程允许打开的最大文件数调大到超过max_connections,否则FastDFS server启动会报错。
2.最大工作线程数

配置文件:tracker.conf 和 storage.conf
参数名:work_threads
缺省值:4 

work threads主要负责网络IO处理,一个线程通过epoll这样的机制处理若干个网络连接。work threads理论上不会消耗太多CPU,不建议配置得过大。

为了减少CPU上下文切换的开销,以及不必要的资源消耗,不建议将本参数设置得过大。为了充分发挥出多个CPU的效能,系统中的线程数总和,建议不要超过CPU总数的2倍。

对于tracker server,公式为:
work_threads + 2 <= 2 * CPU总数

对于storage server,公式为:

work_threads + 1 + 本组storage server数 + (disk_reader_threads + disk_writer_threads) store_path_count <= 2 CPU总数

3. storage磁盘读写线程数

配置文件:storage.conf

1. disk_rw_separated:磁盘读写是否分离,缺省值为 true
2. disk_reader_threads:单个磁盘文件读取线程数,缺省值为 1
3. disk_writer_threads:单个磁盘文件写入线程数,缺省值为 1

注:单个(或一个)磁盘对应storage server的一个store path。

如果磁盘读写混合,单个磁盘读写线程总数为读取线程数 与 写入线程数之和。
对于单盘挂载方式,磁盘读写线程分别设置为 1 即可。
如果磁盘做了RAID,比如RAID5或RAID10,那么需要酌情加大读写线程数,这样才能最大程度地发挥磁盘IO能力。
4. storage同步延迟相关设置

配置文件:storage.conf

1. sync_binlog_buff_interval:将binlog buffer写入磁盘的时间间隔,单位为秒,取值大于0,缺省值为60,建议设置为1。

2. sync_wait_msec:如果没有需要同步的文件,对binlog进行轮询的时间间隔,单位为毫秒,取值大于0,缺省值为200,建议设置为50。

3. sync_interval:同步完一个文件后,休眠的毫秒数,缺省值为0,通常设置为0即可。
  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值