Use of distributed file servers FastDFS

Distributed involved in the project file uploading and downloading, use this time before uploading, upload the file to the current project on the same server where the position is clearly inconsistent with the concept of distributed projects, in which case we will help FastDFS Upload file data stored in a simple server.

First, what is the introduction to the first FastDFS

  FastDFS is c language prepared by an open-source distributed file system. Including the Tracker server and Storage Server , FastDFS the Internet tailored full account of redundancy, load balancing, and other mechanisms linear expansion, and focus on high availability, high performance and other indicators, using FastDFS easily build a high-performance file server clusters provide file upload and download services.

  Tracker server role is load balancing and scheduling , can be found in Storage server to provide file upload service to Tracker server when the file is uploaded, according to some policies. Tracker track server or may be referred to dispatch server.

  Storage server role files stored on Storage server, Storageserver client to upload the files stored ultimately not implemented its own file system but to use the operating system's file system to manage files . Storage can be referred to as a storage server.

advantage:

  The establishment of various clusters, to prevent high concurrency, distributed storage requirements to adapt

  End storage could theoretically unlimited expansion

  End storage without losing data, disaster recovery and strong.

Disadvantages:

  High maintenance costs, need to spend more money to open more servers

Second, the upload process

 

  After the client upload a file server to store the file ID is returned to the client, this ID file for later access index information for the file. File index information includes: group name, virtual disk paths, two data directory, file name.

  

 

 

  

Group Name : storage group after the name of the file upload, returned by the storage server after a successful file upload, the client needs to save itself.

Virtual disk path : storage configured virtual path, and disk options store_path * correspondence. If you configure store_path0 is M00, if you configure store_path1 is M01, and so on.

Data two directories : storage server to create two directories in each virtual disk paths for storing data files.

File name different from uploading a file: Is based on specific information generated by the storage server, the file name contains: source storage server IP address, file creation time stamp, file size, the random number and filename extension and other information.

2.1 FastDFS a small demo

public  class demo1 {
     public  static  void main (String [] args) throws IOException, MyException {
         // 1, load the configuration file, the contents of the configuration file is the tracker service address. 
        ClientGlobal.init ( "fdfs_client.conf" );
         // 2, creates a TrackerClient object. A new direct. 
        TrackerClient = TrackerClient new new TrackerClient ();
         // . 3, to make connections using TrackerClient objects, the object to obtain a TrackerServer 
        TrackerServer trackerServer = trackerClient.getConnection ();
         // . 4, a reference to create the StorageServer, is null 
        StorageServer storageserver = null;
         // 5 to create a StorageClient object requires two parameters TrackerServer objects, StorageServer reference 
        StorageClient StorageClient = new new StorageClient (trackerServer, storageserver);
         // 6, upload pictures using StorageClient objects, file parameter 1, parameter 2 file extension.
        // extension without. "" 
        String [] = storageClient.upload_file strings ( "C: \\ Desktop the Users \\ \\ \\ 2.jpg Administrator", "JPG" , null );
         // . 7, the returned array . Contain the path name and picture of the group. 
        for (String String: strings) {
            System.out.println(string);
        }
    }
}

String printed: group1 / M00 / 00/01 / wKjIgF3SRXWAHitEAAB1q5bIEwY138.jpg

Needed fdfs_client.conf profile

# connect timeout in seconds
# default value is 30s
connect_timeout=30

# network timeout in seconds
# default value is 30s
network_timeout=60

# the base path to store log files
base_path=/home/fastdfs

# tracker_server can ocur more than once, and tracker_server format is
#   "Host: Port" , Host CAN BE hostname or ip address 
ip # distributed file server, you need to use the change here to
tracker_server
= 192.168.200.128: 22122 #standard log level as syslog, case insensitive, value list: ### emerg for emergency ### alert ### crit for critical ### error ### warn for warning ### notice ### info ### debug log_level=info # if use connection pool # default value is false # since V4.05 use_connection_pool = false # connections whose the idle time exceeds this time will be closed # unit: second # default value is 3600 # since V4.05 connection_pool_max_idle_time = 3600 # if load FastDFS parameters from tracker server # since V4.05 # default value is false load_fdfs_parameters_from_tracker=false # if use storage ID instead of IP address # same as tracker.conf # valid only when load_fdfs_parameters_from_tracker is false # default value is false # since V4.05 use_storage_id = false # specify storage ids filename, can use relative or absolute path # same as tracker.conf # valid only when load_fdfs_parameters_from_tracker is false # since V4.05 storage_ids_filename = storage_ids.conf #HTTP settings http.tracker_server_port=80 #use "#include" directive to include HTTP other settiongs ##include http.conf

Third, the page display of results

 

 

At this point we explained to upload photos already uploaded to the distributed file servers, and can access to the photos we upload

 

 

 Note:

   Distributed file server configures itself, steps are too cumbersome.

 

Guess you like

Origin www.cnblogs.com/guanyuehao0107/p/11882540.html