How to install, configure, and use FastDFS in Ubuntu

Source: Internet
Author: User
Tags file upload server port

FastDFS installation

FastDFS currently supports Unix-like systems. It has been tested in Linux and FreeBSD. Ubuntu10.4 is used in this article. We recommend that you have a brief understanding of the principles of FastDFS before installation, this will give you a good understanding of the subsequent configurations.

I. Preparations-install libevent

FastDFS is internally bound with libevent as the http server. In V2.X, libevent must be installed. In this document, libevent is installed in V2.2. Therefore, libevent must be installed. (We also recommend using http to download files)

If libevent has been installed, check that the installation path is/usr, because FastDFS needs to find some dependent files in this directory when compiling the source program. Otherwise, FastDFS compilation will fail. If not, we recommend that you first uninstall libevent and install it under/usr. Ubuntu10.4 libevent is installed by default. You can uninstall it in the software center and install it as described below.

This article installed libevent1.4.14b-stable, download address: http://monkey.org /~ Provos/libevent/

Installation steps:

Decompress libevent, and then go to the decompressed directory and execute:

./Configure -- prefix =/usr
Make clean;
Make
Make install

The installation of libevent is complete.

 
II. Install FastDFS

1. Download FastDFS source program, download address http://code.google.com/p/fastdfs/downloads/list, here to download FastDFS_v2.02.tar.gz (recommended to install V2.02 version, more stable than V1.X version and performance improvement)

2. Run the following command in the folder where FastDFS_v2.02.tar.gz is located:

Sudo tar vxzf FastDFS_v2.02.tar.gz/home/soar/FastDFS

Note:/home/soar/FastDFS can also be another directory. Remember to extract the directory and use % FastDFS % to indicate it later)


3. To use the built-in http service, edit the % FastDFS %/make. sh file and find
# WITH_HTTPD = 1
Modify
WITH_HTTPD = 1
To support http

4. Enter the % FastDFS % directory and execute:

Sudo./make. sh

 
5. In the % FastDFS % directory, execute:

Sudo./make. sh install

If the command line information is similar

# Ln-fs/usr/local/lib/libfastcommon. so.1/usr/local/lib/libfastcommon. so
# Ln-fs/usr/local/lib/libfdfsclient. so.1/usr/local/lib/libfdfsclient. so
Sh./fdfs_link_library.sh

Congratulations! the installation is successful!



FastDFS configuration

The FastDFS configuration file is in the % FastDFS %/conf Directory, including
Client. conf Client uploads configuration files
Storage. conf file Storage server configuration file
Tracker. conf is responsible for the configuration file of the balanced scheduling server.
Http. conf http server configuration file

The configuration file needs to be configured according to the server environment. For details, refer to the official FastDFS installation and configuration document "composer".

In this example, both Tracker Server and Storage Server are installed on one Server. IP address: 10.0.2.15
1. Configure and start the Tracker Server

A. Modify the % FastDFS %/conf/tracker. conf file as follows:
# You can specify the directory location by yourself, but the directory must exist. It is used to store logs, storage server, and other information. Otherwise, the tracker server cannot be started.

Base_path =/home/yuqing/fastdfs-> base_path =/home/soar/fastdfs_tracker

# Change it to the desired http port. In the future, it will be the port on which the http file is downloaded.

Http. server_port = 8080-> http. server_port = 8090

# Http support

# Include http. conf-> # include http. conf

# The default value is 4 GB. If the space is insufficient, it is recommended to reduce it. Otherwise, no free space exception is reported and cannot be started properly.

Reserved_storage_space = 4 GB-> reserved_storage_space = 1 GB

# The tracker server can use the default port for the storage server. You can also customize it.

Port = 22122

 
B. Copy the http. conf file to the/etc/fdfs directory and run

Sudo cp % FastDFS %/conf/http. conf/etc/fdfs/

Note: To support http, you must copy the file to this directory. Otherwise, the file cannot be started and an error similar to param http. XXX not exist or is empty is reported.

C. Enter the/usr/local/bin/directory, start the tracker server, and run

Sudo fdfs_trackerd % FastDFS %/conf/tracker. conf

D. Go to/home/soar/fastdfs_tracker/logs/trackerd. log to view the startup log of the tracker.


[16:21:25] INFO-FastDFS v2.02, base_path =/home/soar/fastdfs_tracker, connect_timeout = 30 s, network_timeout = 60 s, port = 22122, bind_addr =, max_connections = 256, work_threads = 4, store_lookup = 2, store_group =, store_server = 0, store_path = 0, reserved_storage_space = 4 MB, download_server = 0, allow_ip_count =-1, bytes = 10 s, check_active_interval = 120 s, thread_stack_size = 64 KB, storage_ip_changed_auto_adjust = 1, storage_sync_file_max_delay = 86400 s, storage_sync_file_max_time = 300 s
[16:21:25] INFO-HTTP supported: server_port = 8090, default_content_type = application/octet-stream, bytes = 0, token_ttl = 0 s, bytes length = 0, token_check_fail content_type =, token_check_fail buff length = 0, check_active_interval = 30, check_active_type = tcp, check_active_uri =/status.html

 
Congratulations! the tracker server has been started successfully!

2. Configure and start the Storage Server

A. Modify the % FastDFS %/conf/storage. conf file as follows:
# It can be customized, but this directory must exist to store storage-related log and group-related information


Base_path =/home/yuqing/fastdfs->/home/soar/fastdfs_storge

# File storage location. Multiple storage locations can be specified on one storage server.


Store_path0 =/home/yuqing/fastdfs-> store_path0 =/home/soar/fastdfs_storge

# Must be specified

Group_name = group1

# Modify the IP address and port information of the tracker server

Tracker_server = 192.168.209.121: 22122-> tracker_server = 10.0.2.15: 22122

# Http support

# Include http. conf-> # include http. conf

B. Enter the/usr/local/bin/directory, start the storage server, and run

Sudo fdfs_storaged % FastDFS %/conf/storage. conf

C. Go to/home/soar/fastdfs_tracker/logs/storage. log to view the startup log of the storage server.


[16:37:16] INFO-FastDFS v2.02, base_path =/home/soar/fastdfs_storge, store_path_count = 1, rows = 256, group_name = group1, connect_timeout = 30 s, network_timeout = 60 s, port = 23000, bind_addr =, client_bind = 1, max_connections = 256, work_threads = 4, bytes = 1, disk_reader_threads = 1, bytes = 1, buff_size = 256KB, heart_beat_interval = 30 s, stat_report_interval = 60 s, tracker_server_count = 1, latency = 200 ms, sync_interval = 0 ms, sync_start_time = 00:00, latency =, latency = 500, allow_ip_count =-1, latency = 0, bytes = 100, bytes = 0, bytes = 10 s, bytes = 60 s, sync_stat_file_interval = 300 s, thread_stack_size = 512 KB, upload_priority = 10, if_alias_prefix =, check_file_duplicate = 0, FDHT group count = 0, FDHT server count = 0, FDHT key_namespace =, FDHT keep_alive = 0, HTTP server port = 8888, domain name =
[16:37:16] INFO-HTTP supported: server_port = 8888, http_trunk_size = 262144, default_content_type = application/octet-stream, anti_steal_token = 0, token_ttl = 0 s, expiration length = 0, token_check_fail content_type =, token_check_fail buff length = 0
[16:37:16] INFO-file: storage_param_getter.c, line: 48, storage_ip_changed_auto_adjust = 1
[16:37:19] INFO-file: tracker_client_thread.c, line: 274, successfully connect to tracker server 10.0.2.15: 22122, as a tracker client, my ip is 10.0.2.15

Congratulations, storage server has been started successfully!



FastDFS usage

After the above installation, configuration, and startup, we can immediately see the effect of FastDFS. We first upload a file and then download it through http.

1. Upload files

The FastDFS installation package contains a client program that allows you to upload files. Before using this client program, you must configure client. conf before uploading and downloading files.

1. Modify the % FastDFS %/conf/client. conf file as follows:

# Customizable, but this directory must exist. It is used to store file upload logs.


Base_path =/home/yuqing/fastdfs-> base_path =/home/soar/fastdfs_tracker

Tracker_server = 192.168.209.121: 22122-> tracker_server = 10.0.2.15: 22122

Http. tracker_server_port = 8080-> http. tracker_server_port = 8090

# Support for http

# Include http. conf-> # include http. conf

 
2. Enter the/usr/local/bin/directory, upload the file, and execute

Sudo fdfs_test % FastDFS %/conf/client. conf upload a.txt

Note: a.txt can be created in the/usr/local/bin/directory.

 
If the command line feedback is similar to the following:



The file is uploaded successfully.

II. Download files

In the browser, enter the url address shown in the preceding figure. The tracker server is 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.

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.