Install and configure the fastdfs Distributed File System in Ubuntu

Source: Internet
Author: User

Fastdfs Introduction

Fastdfs is an open-source distributed file system that manages files, including file storage, file synchronization, and file access (File Upload and file download, it solves the problems of large-capacity storage and load balancing. It is especially suitable for online services with files as the carrier, such as photo album websites and video websites.

The fastdfs server has two roles: tracker and storage ). The tracker is mainly used for scheduling and serves as a server Load balancer for access.

The storage node stores files and implements all the functions of file management: storage, synchronization, and access interfaces. fastdfs also manages the meta data of files. The meta data of a file is related to the file. It is expressed in key value pair mode, for example, width = 1024, where key is width and value is 1024. The object meta data is a file property list that can contain multiple key-value pairs.

Shows the fastdfs system structure:

Both the tracker and storage nodes can be composed of multiple servers. Servers in the tracker and storage nodes can be added or removed at any time without affecting online services. All servers in the tracker are equal to each other and can be increased or decreased at any time according to the pressure on the server.

To support large capacity, storage nodes (servers) are organized by means of volumes (or groups. The storage system consists of one or more volumes. The files between the volumes are independent of each other. The file capacity of all volumes is the file capacity of the entire storage system. A volume can be composed of one or more storage servers. The files on the storage servers under a volume are the same. Multiple storage servers in the volume play the role of redundant backup and load balancing.

When a server is added to a volume, the system automatically synchronizes the existing files. After the synchronization is completed, the system automatically switches the new server to the online service provider.

When the storage space is insufficient or is about to run out, you can dynamically Add a volume. You only need to add one or more servers and configure them as a new volume to expand the storage system capacity.

The file ID in fastdfs is divided into two parts: the volume name and the file name. Both are indispensable.

Fastdfs File Upload

Interaction Process of uploaded files:

1. The client asks the tracker about the storage to be uploaded. No parameters need to be attached;

2. Tracker returns an available storage;

3. The client directly communicates with storage to complete file upload.

Fastdfs File Download

Interaction process of downloading files:

1. The client asks the tracker about the storage of the downloaded file. The parameter is the file ID (volume name and file name );

2. Tracker returns an available storage;

3. The client directly communicates with storage to complete file download.

It should be noted that the client is the caller using the fastdfs service, and the client should also be a server. Its calls to tracker and storage are both inter-server calls.

I. Install fastdfs

1. Install libevent first.

1234567 wget http://monkey.org/~provos/libevent-2.0.11-stable.tar.gztar -zxvf libevent-2.0.11-stable.tar.gzcd libevent-2.0.11-stable./configure --prefix=/usrmake cleanmakemake install

2. Install fastdfs

123456 wget http://fastdfs.googlecode.com/files/FastDFS_v3.03.tar.gztar -zxvf FastDFS_v3.03.tar.gzcd FastDFSVim make. sh: change # with_httpd = 1 to with_httpd = 1 to Support HTTP./make.sh./make.sh install

Ii. fastdfs Configuration

1. Configure and start the tracker server

123456 mkdir /var/www/fastdfsvi /etc/fdfs/tracker.confbase_path=/home/yuqing/fastdfs -> base_path=/var/www/fastdfshttp.server_port=8080 -> http.server_port=9090##include http.conf -> #include http.confreserved_storage_space = 4GB -> reserved_storage_space = 1GB
12 cd /usr/local/binfdfs_trackerd /etc/fdfs/tracker.conf

Check whether the tracker is successfully started. You can view the following file:/var/www/fastdfs/logs/trackerd. log.

[2011-10-21 14:29:44] INFO – FastDFS v3.03, base_path=/home/fastdfs,run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s,port=22122, bind_addr=, max_connections=256, work_threads=4, store_lookup=2,store_group=, store_server=0, store_path=0, reserved_storage_space=1024MB,download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s,check_active_interval=120s, thread_stack_size=64 KB,storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s,storage_sync_file_max_time=300s, use_trunk_file=0, slot_min_size=256,slot_max_size=16 MB, trunk_file_size=64 MB[2011-10-21 14:29:44] INFO – HTTP supported: server_port=9090,default_content_type=application/octet-stream, anti_steal_token=0,token_ttl=0s, anti_steal_secret_key length=0, token_check_failcontent_type=, token_check_fail buff length=0, check_active_interval=30,check_active_type=tcp, check_active_uri=/status.html

2. Configure and start the storage server

12345678 mkdir /var/www/fastdfs/fdfs_storagecd /etc/fdfsvi storage.confbase_path=/home/yuqing/fastdfs -> /var/www/fastdfs/fdfs_storagestore_path0=/home/yuqing/fastdfs -> store_path0=/var/www/fastdfs/fdfs_storagegroup_name=group2tracker_server=192.168.209.121:22122 -> tracker_server=10.0.2.15:22122##include http.conf ->#include http.conf
12 cd /usr/local/binfdfs_storaged /etc/fdfs/storage.conf

Next we will see a lot of mkdir data path, which is the data directory created by the system.

Iii. Test and use fastdfs

1. Configure the client for fastdfs

12345 vi /etc/fdfs/client.confbase_path=/home/yuqing/fastdfs-> base_path=/var/www/fastdfstracker_server=192.168.209.121:22122 -> tracker_server=10.0.2.15:22122http.tracker_server_port=8080 ->http.tracker_server_port=9090##include http.conf ->#include http.conf

2. Test File Upload

123 cd /usr/local/bintouch aa.phpfdfs_test /etc/fdfs/client.conf upload aa.php

After successful execution, the following message is displayed:

3. Test File Download

In the browser, if the URL is entered, the tracker server will be automatically redirected to the storage server of the stored file. The file is downloaded successfully. So far, fastdfs has been successfully set up. Write your own client for access:

1 http://10.0.2.15:9090/group1/M00/00/00/CgACD0-NYt_VkxRqAAAAEIG-AGI255_big.php

4. Common commands

123456 # Restart Trackerfdfs_trackerd /etc/fdfs/tracker.conf# Restart storagedfdfs_storaged /etc/fdfs/storage.conf# Monitor DFSfdfs_monitor /etc/fdfs/storage.conf

Iv. php Extension

1. install PHP Extension

123456 cd php_clientapt-get install php5-devphpize./configuremake make install

2. Configure PHP Extension

12345 vi  fastdfs_client.iniextension = fastdfs_client.sofastdfs_client.tracker_group_count = 2fastdfs_client.tracker_group0 = /etc/fdfs/client.conffastdfs_client.tracker_group1 = /etc/fdfs/client.conf

3. Test

1 php fastdfs_test.php

4. php Use Case test. php

12345678910 < ?php// Uploaded file$filename = "aa.php";// Call the fastdfs class$fdfs = new FastDFS();// Upload File $ filename is the uploaded file, and HTML is the last and last name suffixed with .html$file_info = $fdfs->storage_upload_by_filename($filename,'html');// Output the Upload File directory and file nameecho $file_info['filename'];?>

V. install PHP extension in centos

1. install PHP Extension

1234 cd php_client/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config --with-fastdfs_clientmake && make install

2. Configure PHP Extension

1234567891011 vi  php.iniextension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"extension = fastdfs_client.sofastdfs_client.base_path = /var/www/fastdfsfastdfs_client.connect_timeout = 2fastdfs_client.network_timeout = 60fastdfs_client.log_level = infofastdfs_client.log_filename =fastdfs_client.http.anti_steal_secret_key =fastdfs_client.tracker_group_count = 1fastdfs_client.tracker_group0 = /etc/fdfs/client.conf

 

Http://www.vicenteforever.com/2012/04/ubuntu-fastdfs/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.