不积跬步无以至千里

记录精彩的程序人生

  • 首页
  • Java
  • Golang
  • PHP
  • Python
  • Nodejs
  • Lua
  • Docker
  • DevOps
  • 文章归档
  • 默认分类
  • 关于
  • 标签

  • 搜索
PostgreSQL hbase 时间同步 nexus 开机启动 nexus, 开机启动 jenkins安装配置 gitlab安装配置 gitlab安装 文件系统 fastdfs gcc切换 gcc升级 mysql8 交换空间 虚拟内存 tcp thrift lua tag test VPN SoftEtherVPN homebrew asm spring tomcat maven jdk ios mac 图案字符 figlet mysql半同步复制 mysql主从同步 一主多从 一主一从 主从同步 反向代理 密码重置 test 虚拟机扩容 swap 虚拟空间 docker ldocker grpc-gateway protobuf 微服务 go grp GRPC 授权登录 OAuth2.0 SOA supervisord supervisor RPC CentOS rabbitmq 环境变量 php-fpm php.ini error php7 lnmp 编译安装 mysql nginx linux java php python redis 字符串操作 mysql5.7 Solo

Centos安装、配置、分布式部署文件系统FastDfs

发表于 2021-11-04 | 分类于 DevOps | 0 | 阅读次数 2196

FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。

FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。

环境准备

系统:Centos 7
服务器:

  • 2台trakcer(192.168.200.90/91)
  • 4台storage(192.168200.95/96/97/98)

软件包:

  • fastdfs源码
  • libfastcommon
  • nginx

安装FastDfs(所有机器)

以下安装、配置是对一台服务器进行操作,待安装、配置完成后再把环境批量部署到其他服务器

  1. 安装依赖包
yum -y install gcc gcc-c++ libstdc++-devel pcre-devel zlib-devel wget make
yum -y groupinstall 'Development Tools' 
  1. 安装libfastcommon类库
cd ~/soft
git clone git@github.com:happyfish100/libfastcommon.git
mv libfastcommon/ /usr/local
cd /usr/local/libfastcommon
./make.sh
./make.sh install
  1. 安装FastDfs
cd ~/soft
git clone git@github.com:happyfish100/fastdfs.git
mv fastdfs /usr/local
cd /usr/local/fastdfs
./make.sh
./make.sh install

安装成功后在/usr/bin目录会生成fdfs_开头的fastdfs命令工具。
所有配置文件在/etc/fdfs目录下。
tracker需要tracker.conf配置文件,storage需要storage.conf配置文件。

配置tracker(192.168.200.90/91)

  1. 创建日志、数据存放目录
mkdir /root/fastdfs
  1. 修改/etc/fdfs/tracker.conf文件
vi /etc/fdfs/tracker.con

修改配置项 base_path = /root/fastdfs
其他参数重点关注:

#启用配置文件
disabled=false
#设置tracker的端口号
port=22122
#设置tracker的数据文件和日志目录(需手动创建)
base_path=/root/fastdfs
#设置http端口号
http.server_port=9090
  1. 启动tracker
fdfs_tracker /etc/fdfs/tracker.conf restart

没有报错,查看端口22122是否开始监听,确认启动是否成功。

[root@localhost soft]# ps -aux | grep fdfs
root      2267  0.0  0.2  89832  4916 ?        Sl   06:12   0:00 fdfs_trackerd /etc/fdfs/tracker.conf start
[root@localhost soft]# netstat -tpnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      2267/fdfs_trackerd  

也可以查看tracker的日志是否启动成功

[root@localhost soft]# cat /root/fastdfs/logs/trackerd.log
[2021-11-03 06:12:34] INFO - FastDFS v6.07, base_path=/root/fastdfs, run_by_group=...

至此,一个单机的tracker配置就完成了,Tracker也成功启动~, 接下来要做的就是完成Storage的配置~

配置storage(192.168.200.95/96/97/98)

将存储节点分为两个组,其中
group1(196.168.200.95/96),group2 (196.168.200.97/98)

  1. 创建存储、配置目录
mkdir /root/fastdfs
  1. 修改/etc/fdfs/storage.conf文件
vi /etc/fdfs/storage.con

修改配置项 base_path = /root/fastdfs, group_name=group1
主要配置项修改如下:

group_name=group1                   # 组名(第一组为group1,第二组为group2,依次类推...)
base_path=/root/fastdfs             # 上一步创建的数据和日志文件存储根目录
store_path0=/root/fastdfs           #第一个存储目录,第二个存储目录起名为:store_path1=xxx,其它存储目录名依次类推...
store_path_count=1                  # 存储路径个数,需要和store_path个数匹配
tracker_server=192.168.200.90:22122          # 上面配置的tracker服务器IP和端口
tracker_server=192.168.200.91:22122          # 上面配置的tracker服务器IP和端口
  1. 启动storage
fdfs_storaged /etc/fdfs/storage.conf start

查看启动项和日志

[root@localhost ~]# ps aux | grep fdfs
root      2293  0.1  3.2 414444 67204 ?        Sl   06:41   0:00 fdfs_storaged /etc/fdfs/storage.conf start
[root@localhost ~]# netstat -tpnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      2293/fdfs_storaged  

23000端口和进程已经启动

至此,tracker、storage单机完成配置并成功启动!
接下来,继续完成Nginx和fastdfs-nginx-module的安装和配置

在storage上安装nginx和fastdfs-nginx-module

先分别下载nginx和fastdfs-nginx-module源码,之后分别安装。
1、下载nginx和fastdfs-nginx-module

cd /usr/local
git clone git@github.com:happyfish100/fastdfs-nginx-module.git
cd ~/soft
git clone git@github.com:nginx/nginx.git
  1. 配置软连接
ln -sv /usr/include/fastcommon /usr/local/include/fastcommon 
ln -sv /usr/include/fastdfs /usr/local/include/fastdfs 
ln -sv /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so

安装nginx的时候,添加 fastdfs-nginx-module-master模块,如: ./configure --add-module=/usr/local/fastdfs-nginx-module/src/

  1. 安装nginx
cd ~/soft/nginx
./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module/src
make 
make install

安装成功后查看版本信息:

[root@localhost ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
configure arguments: --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module/src
  1. 配置fastdfs-nginx-module
    进入fastdfs-nginx-module的src目录,将md_fastdfs.conf配置文件拷贝到/etc/fdfs/目录中
cd /usr/local/fastdfs-nginx-module/src
cp mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf

重点配置项如下(一般只需改动如下参数):

base_path=/root/fastdfs           #保存日志目录
tracker_server=192.168.200.90:22122 #tracker服务器IP和端口
tracker_server=192.168.200.91:22122 #tracker服务器IP和端口
storage_server_port=23000         #storage服务器的端口号
group_name=group1                 #当前服务器的group名,这里设置group1
url_have_group_name = true        #文件url中是否有group名
store_path_count=1                #存储路径个数,需要和store_path个数匹配
store_path0=/root/fastdfs         #存储路径
group_count = 2                   #设置组的个数

在末尾增加2个组的具体信息:

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

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

建立M00至存储目录的符号连接:

ln -s /root/fastdfs/data /root/fastdfs/data/M00
ll /root/fastdfs/data/M00
  1. 配置nginx
    编辑/usr/local/nginx/conf配置文件目录下的nginx.conf,设置添加storage信息并保存。
vim /usr/local/nginx/conf/nginx.conf

将server段中的listen端口号改为8080,启动用户user使用root。

user root
listen   8080;

在server段中添加:

location ~/group[1-2]/M00 {
    root /root/fastdfs/data;
    ngx_fastdfs_module;
}

复制fastdfs中的http.conf、mime.types文件到/etc/fdfs

cp /usr/local/fastdfs/conf/http.conf /usr/local/fastdfs/conf/mime.types /etc/fdfs/

至此,storage上的nginx以及其插件fastdfs-nginx-module模块设置完成。

  1. 启动nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=2386
[root@localhost ~]# netstat -tpnl | grep nginx
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      2387/nginx: master

注意:如果防火墙开启需要打开8080端口或者直接关闭防火墙

将nginx设置为开机启动:

vim /etc/rc.d/rc.local

rc.local文件后添加nginx启动命令:

/usr/local/nginx/sbin/nginx

在tracker上安装nginx

在tracker上安装的nginx主要为了提供http访问的反向代理、负载均衡访问storage以及缓存服务。

  1. nginx安装方法和前面在storage上安装nginx步骤一样的,安装完成之后需要配置如下。
vim /usr/local/nginx/conf/nginx.conf
  1. 配置tracker负载均衡
worker_processes  4;                  #根据CPU核心数而定
events {
    worker_connections  65535;        #最大链接数
    use epoll;                        #新版本的Linux可使用epoll加快处理性能
}
http {
    #设置group1的服务器
    upstream fdfs_group1 {
        server 192.168.200.95:8080 weight=1 max_fails=2 fail_timeout=30s;
        server 192.168.200.96:8080 weight=1 max_fails=2 fail_timeout=30s;
    }
    #设置group2的服务器
    upstream fdfs_group2 {
        server 192.168.200.97:8080 weight=1 max_fails=2 fail_timeout=30s;
        server 192.168.200.98:8080 weight=1 max_fails=2 fail_timeout=30s;
    }

   server {
       #设置服务器端口
        listen       8080;
       #设置group1的负载均衡参数
        location /group1/M00 {
            proxy_pass http://fdfs_group1;
        }
        #设置group2的负载均衡参数
        location /group2/M00 {
            proxy_pass http://fdfs_group2;
        }
      }

    }
  1. 启动tracker上的nginx
[root@localhost soft]# /usr/local/nginx/sbin/nginx
[root@localhost soft]# netstat -tpnl | grep nginx
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      2387/nginx: master

测试上传

  1. 在tracker上配置客户端配置文件client.conf
vim /etc/fdfs/client.conf

配置项修改如下:

base_path=/root/fastdfs                   #日志存放路径
tracker_server=192.168.200.90:22122 # tracker服务器ip和端口         
tracker_server=192.168.200.91:22122 # tracker服务器ip和端口
http.tracker_server_port=8080 # tracker服务器nginx端口
  1. 上传

使用/usr/local/bin/fdfs_upload_file上传一个文件,程序会自动返回文件的URL。

[root@localhost tmp]# fdfs_upload_file /etc/fdfs/client.conf /root/tmp/sync.png
group2/M00/00/00/wKjIYWGB0SSAEvdNAADPiyvZKmo270.png

然后使用浏览器访问:

http://192.168.200.90:8080/group2/M00/00/00/wKjIYWGB0SSAEvdNAADPiyvZKmo270.png

参考:
http://www.ityouknow.com/fastdfs/2017/10/10/cluster-building-fastdfs.html
https://www.cnblogs.com/chiangchou/p/fastdfs.html
https://github.com/happyfish100/fastdfs/wiki/
http://www.ityouknow.com/fastdfs/2018/01/06/distributed-file-system-fastdfs.html
https://zhuanlan.zhihu.com/p/81357349

# fastdfs # 文件系统
Centos7升级、切换gcc版本
Centos安装Gitlab、Jenkins、Nexus实现持续集成-gitlab安装、配置、错误锦集
  • 文章目录
  • 站点概览
ken

ken

记录精彩的程序人生

498 日志
9 分类
77 标签
RSS
Creative Commons
Links
  • 酷壳
0%
© 2010 — 2025 ken
由 Halo 强力驱动
鄂ICP备18013899号-1