FastDFS is installed on CentOS.

Basic introduction:

FastDFS is an excellent distributed file system. It is divided into two parts: the server and the client API. The server is divided into two roles: Tracker and Storage. The tracker is mainly responsible for service scheduling and plays the role of load balancing. A udSN stores, reads, and synchronizes files. Client API to provide file upload and download and delete functions.

In practice, we tend to use clients to connect to the tracker server cluster, the tracker manages the storage node cluster, and the storage node cluster provides available storage nodes for the client. Files on storage nodes are organized by volume or group. In FastDFS, the identification of a file consists of the volume name (or group name), path, and file name. FastDFS supports dynamic scaling, and you can add more storage nodes by adding new volumes or groups.

Installation steps:

We need three hosts to install FastDFS, so I’m using three emulators to simulate. The IP addresses are 192.168.33.3 192.168.33.4 192.168.33.5. 192.168.33.3 is used as the TrackerServer, and the other two hosts are used as the StorageServer

  1. Log in to TrackerServer and download each installation package:
    Download FastDFS wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extensi On % % 20 source code % 20 v5. 01 / FastDFS_v5. 01. Tar. Gz download Nginx wget HTTP: / / http://nginx.org/download/nginx-1.7.0.tar.gz Wget download FastDFS Nginx - Module http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar. gzCopy the code
  2. Install C compiler environment:

    yum -y install gcc gcc+ gcc-c++ openssl openssl-devel pcre pcre-deve
    Copy the code
  3. Create a system user:

    useradd fastdfs -M -s /sbin/nologin
    useradd nginx -M -s /sbin/nologin
    Copy the code
  4. Install FastDFS:

    Tar -zxvf fastdfs_v5.01.tar. gz CD FastDFS./make. Sh./makeCopy the code
  5. Install Nginx

    Gz tar -zxvf nginx-1.7.0.tar.gz CD nginx-1.7.0. /configure --user=nginx --group=nginx --prefix=/usr/local/nginx --add-module=.. / fastdfs - nginx - the module/SRC attention - add - the module =.. /fastdfs-nginx-module/ SRC This configuration item is only added on the two StorageServer make make installCopy the code
  6. Configuration of the Tracker Server

    1. Create directory for storing data and logs:

      mkdir -p /data/fastdfs/tracker
      Copy the code
    2. Modify the tracker.conf configuration

      Vim /etc/fdfs/tracker.conf Modify: base_path=/data/fastdfs/tracker group_name=group1Copy the code
    3. Modify the nginx.conf configuration

      Vim/usr/local/nginx/conf/nginx. Conf configuration as follows: the user nginx nginx. worker_processes 4; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid /usr/local/nginx/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 20480; }Copy the code
http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /usr/local/nginx/logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; Upstream server_group1 {server 192.168.33.4; Server 192.168.33.5; } server { listen 80; Server_name 192.168.33.3; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location /group1{ include proxy.conf; proxy_pass http://server.group1; }} 4. Configure the TrackerServer launcher: cp /usr/local/app/fastdfs/FastDFS/init.d/fdfs_trackerd /etc/init.d/ chkconfig --add fdfs_trackerd chkconfig fdfs_trackerd onCopy the code
  1. Configure the StorageServer.

    1. Create a directory for storing data and logs:

      mkdir -p /data/fastdfs/storage/data        
      Copy the code
    2. Modify storage.conf configuration:

      Vim /etc/ff/storage. conf Group_name = group1 base_path = / data/fastdfs store_path0 = / data/fastdfs/storage tracker_server = 192.168.33.3:22122 run_by_group=fastdfs run_by_user=fastdfs file_distribute_path_mode=1 rotate_error_log=trueCopy the code
    3. Modify mod_fastdfs.conf configuration.

      Cp/usr/local/app/fastdfs/fastdfs - nginx - the module/SRC/mod_fastdfs. Conf/etc/FDFS vim/etc/FDFS/mod_fastdfs conf among them: Connect_timeout =10 Tracker_Server =192.168.33.3:22122 Group_name =group1 url_have_group_name = true store_path_count=1 store_path0=/data/fastdfs/storageCopy the code
    4. Configure nginx. Conf

          access_log  /usr/local/nginx/logs/access.log  main;
      
          sendfile        on;
          #tcp_nopush     on;
      
          #keepalive_timeout  0;
          keepalive_timeout  65;
      
          #gzip  on;
      
          server {
              listen       88;
              server_name  localhost;
      
              #charset koi8-r;
      
              #access_log  logs/host.access.log  main;
      
              location / {
                  root   html;
                  index  index.html index.htm;
              }
      
      "/usr/local/nginx/conf/nginx.conf" 128L, 2960C                43,9          29%
      
      http {
          include       mime.types;
          server_names_hash_bucket_size 128;
          client_header_buffer_size 32k;
          large_client_header_buffers 4 32k;
          client_max_body_size 20m;
          limit_rate 1024k;
      
          default_type  application/octet-stream;
      
          log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                            '$status $body_bytes_sent "$http_referer" '
                            '"$http_user_agent" "$http_x_forwarded_for"';
      
          access_log  /usr/local/nginx/logs/access.log  main;
      
          sendfile        on;
          #tcp_nopush     on;
      
          #keepalive_timeout  0;
          keepalive_timeout  65;
      
          #gzip  on;
      
          server {
              listen       88;
              server_name  localhost;
      
              #charset koi8-r;
      
              #access_log  logs/host.access.log  main;
      
              location / {
                  root   html;
                  index  index.html index.htm;
              }
      
              location /group1/M00{
                      root /data/fastdfs/storage/data;
                      ngx_fastdfs_module;
              }
              #error_page  404              /404.html;
      
              # redirect server error pages to the static page /50x.html
              #
              error_page   500 502 503 504  /50x.html;
              location = /50x.html {
                  root   html;
              }
      
              # proxy the PHP scripts to Apache listening on 127.0.0.1:80
              #
              #location ~ \.php$ {
              #    proxy_pass   http://127.0.0.1;
              #}
      
              # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
              #
              #location ~ \.php$ {
              #    root           html;
              #    fastcgi_pass   127.0.0.1:9000;
              #    fastcgi_index  index.php;
              #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
              #    include        fastcgi_params;
              #}
      
              # deny access to .htaccess files, if Apache's document root
              # concurs with nginx's one
              #
              #location ~ /\.ht {
              #    deny  all;
              #}
          }
      Copy the code
# another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:! aNULL:! MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # #}}} to create soft links: ln -s/data/fastdfs/storage/data/data/fastdfs/storage/data/M00 5. Configure the Storage boot program:  cp /usr/local/app/fastdfs/FastDFS/init.d/fdfs_storaged /etc/init.d/ chkconfig --add fdfs_storaged chkconfig fdfs_storaged onCopy the code
  1. Start the TrackerServer:

    service fdfs_trackerd start
    Copy the code
  2. Start the StorageServer:

    service fdfs_storaged start
    Copy the code
  3. Start nginx server for Tracker and StorageServer:

    ./usr/local/nginx/sbin/nginx
    Copy the code
  4. Configure a client in TrackerServer:

    Vim /etc/ff/client. conf In the command, base_path=/data/fastdfs tracker_server=192.168.33.3:22122Copy the code
  1. Upload files:

    fdfs_upload_file /etc/fdfs/client.conf iPhoneX.jpg