• FastDFS分布式存储


    FastDFS分布式存储

    fastdfs安装

    主机名 IP地址
    fastdfs01 10.0.1.130
    fastdfs02 10.0.1.131
    fastdfs03 10.0.1.132
    web01 10.0.1.7
    #所有服务器操作相同
    [root@fastdfs01 ~]# yum -y install make cmake gcc gcc-c++
    [root@fastdfs01 ~]# git clone https://github.com/happyfish100/libfastcommon.git
    [root@fastdfs01 ~]# mv libfastcommon /usr/local/src/
    [root@fastdfs01 ~]# cd /usr/local/src/
    [root@fastdfs01 src]# cd libfastcommon/
    [root@fastdfs01 libfastcommon]# ./make.sh 
    [root@fastdfs01 libfastcommon]# ./make.sh install
    [root@fastdfs01 src]# yum install gettext gettext-devel libXft libXft-devel libXpm libXpm-devel autoconf libxtst-devel zlib-devel libpng-devel  glib-devel
    [root@fastdfs01 src]# wget https://github.s3.amazonaws.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz
    [root@fastdfs01 src]# cd libevent-2.0.20-stable/
    [root@fastdfs01 libevent-2.0.20-stable]# ./configure && make && make install 
    [root@fastdfs01 src]# git clone https://github.com/happyfish100/fastdfs.git
    [root@fastdfs01 src]# cd fastdfs/
    [root@fastdfs01 fastdfs]# ./make.sh
    [root@fastdfs01 fastdfs]# ./make.sh install
    
    

    配置Fastdfs跟踪服务器Tracker(fastdfs01)

    #fastdfs01服务器
    [root@fastdfs01 init.d]# cd /etc/fdfs/
    [root@fastdfs01 fdfs]# cp tracker.conf.sample tracker.conf
    [root@fastdfs01 fdfs]# 
    [root@fastdfs01 fdfs]# vim tracker.conf
    disabled=false               //启用配置文件
    port=22122                   //tracker 的端口号,一般采用 22122 这个默认端口
    base_path=/fastdfs/tracker   //tracker 的数据文件和日志目录
    store_lookup=0              //采取轮巡方式选择要上传的组进行存储,默认2 选择最大空闲空间的组
    [root@fastdfs01 /]# mkdir -p /fastdfs/tracker
    [root@fastdfs01 /]# /etc/init.d/fdfs_trackerd start
    [root@fastdfs01 tracker]# netstat -lntup
    tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      8604/fdfs_trackerd  
    
    

    配置Fastdfs存储服务器Storage(fastdfs01、fastdfs02)

    #fastdfs01、fastdfs02服务器配置相同
    [root@fastdfs02 fastdfs]# cd /etc/fdfs/
    [root@fastdfs02 fdfs]# vim storage.conf
    disabled=false                          //启用配置文件
    group_name=group1                       //组名(第一组为 group1,第二组为 group2)
    port=23000                              //storage 的端口号,同一个组的 storage 端口号必须相同
    base_path=/fastdfs/storage              //设置 storage 的日志目录
    store_path0=/fastdfs/storage            //存储路径
    store_path_count=1                      //存储路径个数,需要和 store_path 个数匹配
    tracker_server=192.168.10.200:22122     //tracker 服务器的 IP 地址和端口
    tracker_server=192.168.1.201:22122      //多个 tracker 直接添加多条配置
    http.server_port=8888                   //设置 http 端口号
    [root@fastdfs02 fdfs]# mkdir -p /fastdfs/storage
    [root@fastdfs02 fdfs]# /etc/init.d/fdfs_storaged start
    

    配置客户端(web01)

    #web01服务器
    [root@web01 src]# cd /etc/fdfs/
    [root@web01 fdfs]# cp client.conf.sample client.conf
    [root@web01 fdfs]# vim client.conf
    base_path=/fastdfs/client
    tracker_server=10.0.1.130:22122
    [root@web01 fdfs]# mkdir -p /fastdfs/client
    
    #测试
    [root@web01 ~]# pwd
    /root
    [root@web01 ~]# ls
    1.png
    [root@web01 ~]# fdfs_upload_file /etc/fdfs/client.conf 1.png 
    group1/M00/00/00/CgABg11rmL6AY4HpAABAwsjutas743.png
    [root@web01 ~]# 
    
    

    在各个存储节点安装nginx

    fastdfs-nginx-module
    FastDFS 通过Tracker服务器,将文件放在Storage服务器存储,但是同组存储服务器之间需要进入文件复制,有同步延迟的问题。
    假设Tracker服务器将文件上传到了A机器上,上传成功后文件ID已经返回给客户端。此时FastDFS存储集群机制会将这个文件同步到同组存储B机器上,在文件还没有复制完成的情况下,客户端如果用这个文件ID在B机器上取文件,就会出现文件无法访问的错误。
    而fastdfs-nginx-module可以重定向文件连接到源服务器取文件,避免客户端由于复制延迟导致的文件无法访问错误。

    [root@fastdfs02 ~]# vim /etc/yum.repos.d/nginx.repo
    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    [root@fastdfs02 ~]# yum clean all
    [root@fastdfs02 ~]# yum makecache 
    [root@fastdfs02 ~]# yum -y install nginx
    [root@fastdfs02 ~]# git clone https://github.com/happyfish100/fastdfs-nginx-module.git
    [root@fastdfs02 ~]# wget https://nginx.org/download/nginx-1.16.1.tar.gz
    [root@fastdfs02 ~]# tar xf nginx-1.16.1.tar.gz 
    [root@fastdfs02 ~]# yum -y install pcre-devel openssl openssl-devel
    [root@fastdfs02 ~]# cd nginx-1.16.1/
    [root@fastdfs02 nginx-1.16.1]#  ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=/root/fastdfs-nginx-module/src/
    [root@fastdfs02 nginx-1.16.1]#  make
    [root@fastdfs02 nginx-1.16.1]# mv /usr/sbin/nginx /usr/sbin/nginx.bak
    [root@fastdfs02 nginx-1.16.1]# cd objs/
    [root@fastdfs02 objs]# cp nginx /usr/sbin/nginx
    [root@fastdfs02 ~]# cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
    [root@fastdfs02 ~]# vim /etc/fdfs/mod_fastdfs.conf 
    tracker_server=10.0.1.130:22122
    url_have_group_name = true
    store_path0=/fastdfs/storage
    
    [root@fastdfs02 ~]# cd /usr/local/src/fastdfs/conf/
    [root@fastdfs02 conf]# cp http.conf mime.types /etc/fdfs/
    [root@fastdfs02 conf]# ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
    [root@fastdfs02 conf]# vim /etc/nginx/conf.d/default.conf 
    server {
       listen 8888;
       server_name localhost;
       location /group1/M00 {
       ngx_fastdfs_module;
    }
    }
    [root@fastdfs02 conf]# systemctl restart nginx
    
    # 浏览器访问
    http://10.0.1.131:8888/group1/M00/00/00/CgABg11rmL6AY4HpAABAwsjutas743.png
    

    在跟踪节点服务器上安装Nginx

    [root@fastdfs01 ~]# vim /etc/yum.repos.d/nginx.repo
    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    [root@fastdfs01 ~]# yum -y install nginx
    [root@fastdfs01 ~]# vim /etc/nginx/conf.d/default.conf 
    upstream fastdfs {
      server 10.0.1.131:8888;
      server 10.0.1.132:8888;
    }
    server {
      listen 80;
      server_name localhost;
      location /group1/M00 {
      proxy_pass http://fastdfs;
      }
    
    #浏览器访问
    http://10.0.1.130/group1/M00/00/00/CgABg11rmL6AY4HpAABAwsjutas743.png
    
  • 相关阅读:
    linux上读取apk信息
    android 的混淆解析
    使用ant自动生成签名的apk
    每天一剂 WebView 良药
    看完让你觉得自己变超聪明的图
    centos7:Kafka集群安装
    centos7:storm集群环境搭建
    Mysql数据库存储数据时间与系统获取时间不一致
    centos7:ssh免密登陆设置
    FLUME安装&环境(二):拉取MySQL数据库数据到Kafka
  • 原文地址:https://www.cnblogs.com/opesn/p/12994203.html
Copyright © 2020-2023  润新知