Nginx+fastdfs+fastdfs-nginx-module Configuring Distributed File Storage

Source: Internet
Author: User
Tags crc32 file url socket sort svn thread time interval valid

Reprinted from Http://www.jb51.net/article/25695.htm

Environment:

storage1:192.168.6.100
storage2:192.168.6.101
tracker:192.168.6.102

1. On each machine, download and install the Fastdfs

Nginx $> wget http://fastdfs.googlecode.com/files/FastDFS_v2.04.tar.gz
# decompression
nginx $> tar zxvf fastdfs_ v2.04.tar.gz
nginx $> cd Fastdfs
# because I'm adding Fastdfs module to Nginx, so I don't need fastdfs to support HTTP so I don't need to get rid of #WITH_HTTPD = 1 comments before, Directly compile
nginx $>./make.sh
nginx $>./make.sh Install

2. Modifying configuration files for tracker and storage
# Changes to Tracker

tracker $> vim/etc/fdfs/tracker.conf 
Disabled=false #配置是否生效 bind_addr=192.168.6.102 #绑定IP port=22122 #服务端口 connect_timeout=30 #连接超时时间 network_timeout=60 #
Tracker server's network timeout, in seconds. Base_path=/home/yangzi #目录地址, it will create data (storage server information), logs, log file max_connections=256 #系统提供服务最大连接数 work_threads=4 #线程数, Typically set the number of CPUs store_lookup=2 the way to upload a group (volume) 0: Poll 1: Specify Group 2: Load balance (Select a group (volume) for maximum remaining space upload) here if you specify the upload to a fixed group at the application level, then this parameter is bypassed store_group= Group1 when the previous parameter is set to 1 o'clock (store_lookup=1, which specifies the group name), this parameter must be set to a group name that exists in the system. If you choose a different upload method, this parameter is not effective store_server=0 Select which storage server to upload operations (after a file is uploaded, this storage server is equivalent to the storage server source of this file, The same group of storage server push this file to achieve synchronization effect) # 0: Polling Method # 1: Sort by IP Address select the first server (least IP address) # 2: Sort by priority (upload priority is set by Storage server, parameter name is up load_priority) store_path=0 Select which directory in the storage server to upload.
Storage server can have multiple base path (which can be understood as multiple disks) that hold files. # 0: Take turns, multiple directories in turn file # 2: Select the largest remaining directory storage file (note: The remaining disk space is dynamic, so storage to the directory or disk may also vary) download_server=0 Select which storage server as the download service # 0: Polling mode, you can download the current file of any storage server # 1: Which is the source storage server with which (previously said how this storage server source is generated) is the previous uploadTo which storage server server is the Reserved_storage_space = 4GB Storage The space reserved on the server, to ensure that the system or other application requirements space (indicating that if the same group of servers, the size of the hard disk, whichever is the smallest, That is, as long as there is a server in the same group to achieve this standard, the standard is effective, because they are backed up) log_level=info #选择日志级别 run_by_group= #操作系统运行FastDFS的用户组 run_by_user= # The operating system runs FASTDFS user allow_hosts=* #可以连接到此 the IP range of the tracker server (which affects all types of connections, including clients, storage server) Sync_log_buff_interval
= 10 # time interval for synchronizing or refreshing log information to the hard disk, in seconds # Note: The Tracker server log is not always written to the hard disk, but the memory is written first.
Check_active_interval = 120 # Detects the time interval for storage server to survive, in seconds. # Storage Server periodically heartbeats to tracker server, if tracker server has not received a heartbeat from storage server within a check_active_interval, There will be thought that the storage server has been offline. Therefore, this parameter value must be greater than the heartbeat interval configured by the storage server.
Typically configured to twice times or 3 times times the heartbeat interval of the storage server. Thread_stack_size = 64KB # The size of the line stacks. The FASTDFS server side takes a threading approach.
To correct this, the tracker server thread stack should not be less than 64KB, not 512KB. # The larger the line stacks, the more system resources a thread consumes.
If you want to start more threads (v1.x corresponding parameter is max_connections, V2.0 is work_threads), you can reduce the value of this parameter appropriately. Storage_ip_changed_auto_adjust = true # This parameter controls whether the cluster automatically adjusts when the storage server IP address changes.
Note: auto-tuning is done only when the storage server process restarts. Storage_sync_file_max_dElay = 86400 # V2.0 the parameters introduced. Maximum delay time for synchronizing files between storage servers, default is 1 days. Adjust according to the actual situation storage_sync_file_max_time = V2.0 the parameters introduced.
The maximum time the storage server needs to synchronize a file, which defaults to 300s, is 5 minutes. Http.disabled=true # HTTP service does not take effect of course when compiling I have removed the WITH_HTTPD macro, HTTP.SERVER_PORT=80 # HTTP Service Port # The following parameters are only available when the HTTP service is enabled Http.che ck_alive_interval=30 http.check_alive_type=tcp http.check_alive_uri=/status.html Http.need_find_content_type=true

Modification of the #两台 storage.conf

Storage $> vim/etc/fdfs/storage.conf
Disabled=false #配置是否生效 group_name=group1 #storage所在组 (volume) bind_addr=192.168.6.100 # bind IP, another too storage IP is 192.168.6.101 Client_bind=true #bind_addr通常是针对server的.
This parameter is valid when BIND_ADDR is specified. port=23000 # is storage service Port Connect_timeout=30 # connection time-out, for socket socket function Connect NETWORK_TIMEOUT=60 # Storage Server network timeout, unit
to seconds.
HEART_BEAT_INTERVAL=30 # heartbeat interval, in seconds stat_report_interval=60 # Storage Server reports to tracker server the time interval, in seconds, for the remaining space on the disk.  Base_path=/home/eric # Base_path directory address, root directory must exist subdirectory will automatically generate # will generate data (datastore place), logs log file max_connections=256 # Maximum number of connections Buff_size =
256KB # Sets the buffer size of the queue node.
Work_threads=4 # Number of worker threads disk_rw_separated = true # disk IO reads and writes are detached, the default is separate. Disk_reader_threads = 1 # The number of read threads for a single storage path, the default value is 1 disk_writer_threads = 1 # The number of write threads for a single storage path, and the default value of 1 sync_wait_msec=200 # when synchronizing files, if from
Binlog does not read the file to be synchronized, sleeps n milliseconds after re-reading, 0 means no hibernation, and immediately tries to read again.
Sync_interval=0 # After synchronizing the previous file, synchronize the time interval of the next file in milliseconds, 0 means no hibernation, and the next file is synced directly. sync_start_time=00:00 sync_end_time=23:59 # allows the system to synchronize the time period (by default, all day).
Generally used to avoid peak synchronization to produce some problems and set, I believe SA will understand. WRITE_MARK_FILE_FREQ=500 # put Storage's MarkThe time interval at which files are periodically synchronized to disk, in seconds store_path_count=1 # Storage Server supports multiple paths (such as disks) when storing files.
This configures the number of base paths where the files are stored, usually with only one directory. Store_path0=/home/eric # Each configuration Store_path path, index number based on 0.
Note The configuration method is followed by 0,1,2 ..., which requires configuration of 0 to Store_path-1.
# If you do not configure Base_path0, it will be the same path as the Base_path. SUBDIR_COUNT_PER_PATH=32 # Fastdfs When storing files, a level two directory is used. Here configure the number of directories to store files tracker_server=192.168.6.188:22122 # tracker_server list to write Port of Oh Log_level=info # log Level run_by_group= # run Stor
Age User group Run_by_user= # Run storage User allow_hosts=* # allow the connection IP list file_distribute_path_mode=0 # file to distribute the storage policy in the data directory.
# 0: Store in turn # 1: Random storage file_distribute_rotate_count=100 # This parameter is valid when the above parameter File_distribute_path_mode is configured to 0 (alternate storage mode). #当一个目录下的文件存放的文件数达到本参数值时, subsequent uploaded files are stored in the next Directory Fsync_after_written_bytes=0 # When a large file is written, every n bytes written, the system function is called once Fsync the content is forcibly synchronized to the hard disk. 0 means never call Fsync sync_log_buff_interval=10 # Synchronize or refresh log information to the hard disk in seconds sync_binlog_buff_interval=60 #
Synchronize Binglog (Update operation log) to hard disk time interval, in seconds sync_stat_file_interval=300 # synchronizes storage stat files to disk in seconds. THREAD_STACK_SIZE=512KB # The size of the line stacks.
The FASTDFS server side takes a threading approach.
# The larger the line stacks, the more system resources a thread consumes. UpLOAD_PRIORITY=10 This storage server as the source server, upload the file priority, can be negative. The smaller the value, the higher the priority. Here and tracker.conf in store_server= 2 o'clock configuration corresponds to if_alias_prefix= check_file_duplicate=0 # whether to detect the upload file already exists. If it already exists, there is no file content, and a symbolic link is created to conserve disk space. Used in conjunction with FASTDFH. 1 is detection, 0 is not detected, we do not use FASTDFH of course 0 Key_namespace=fastdfs # When the last parameter is set to 1 or Yes (True/on is also possible), the namespace in Fastdht keep_alive=0 # with FAS TDHT Servers connection (whether it is a persistent connection) # The following is the configuration of HTTP is not much said Http.disabled=true http.domain_name= http.server_port=80 Http.trunk_siz E=256KB Http.need_find_content_type=true

3. Establish the root directory of tracker and storage

# tracker
Tracker $> mkdir-p/home/eric
# storage
storage $> mkdir-p/home/yangzi

4. Download on a storage, for example, I download the Nginx and Fastdfs-nginx-module modules on the 192.168.6.100

Storage $> wget http://www.nginx.org/download/nginx-0.8.53.tar.gz
storage $> SVN export/http/ Fastdfs-nginx-module.googlecode.com/svn/trunk/fastdfs-nginx-module-read-only

5. Compile and install Nginx with Fastdfs-nginx-module module

Storage $> tar zxvf nginx-0.8.53.tar.gz
storage $> CD nginx-0.8.53
storage $>./configure--PREFIX=/USR /local/nginx--add-module=/root/fastdfs-nginx-module-read-only/src
Storage $> make
storage $> make Install
# copy mod_fastdfs.conf to/etc/fdfs/
storage $> cp/root/fastdfs-nginx-module-read-only/src/mod_ fastdfs.conf/etc/fdfs/

6. Modify Nginx configuration file add

Storage $> vim/usr/local/nginx/conf/nginx.conf

# Add a little bit
location/m00 {
Alias/home/eric/data;
Ngx_fastdfs_module;
}

7. Make a soft connection to the storage storage directory

Storage $> Ln-s/home/yangzi/data/home/yangzi/data/m00

8. Start two storage and tracker Nginx

# Start Tracker
tracker $>/usr/local/bin/fdfs_trackerd/etc/fdfs/tracker.conf
# start storage storage
$>/ usr/local/bin/fdfs_storaged/etc/fdfs/storage.conf
# start Storage2
storage2 $>/usr/local/bin/fdfs_ storaged/etc/fdfs/storage.conf
#在 Storage start Nginx
storage $>/usr/local/nginx/sbin/nginx

9, upload the file test.
# Modify Client configuration file

Storage $> vim/etc/fdfs/client.conf
connect_timeout=30
network_timeout=60
Base_path=/home/yangzi
tracker_server=192.168.6.102:22122
log_level=info
#下面参数无所谓了反正没有用到http service
Http.tracker_server_ Port=80
Storage $> vim a.html
test fastdfs!
Storage $>/usr/local/bin/fdfs_test/etc/fdfs/client.conf Upload a.html This was FASTDFS Client test program v2.04 Copy Right (C), Happy fish/yuqing Fastdfs is copied only under the terms of the GNU general public License V3, whic
H May is found in the FASTDFS source kit.

Visit the Fastdfs Home Page http://www.csource.org/for more detail. Base_path=/home/yangzi, connect_timeout=30, network_timeout=60, Tracker_server_count=1, anti_steal_token=0, anti_ Steal_secret_key length=0 tracker_query_storage_store_list_without_group:server 1. Group_name=group1, ip_addr=192.168.6.100, port=23000 group_name=group1, ip_addr=192.168.6.100, port=23000 Storage_ Upload_by_filename group_name=group1, remote_filename=m00/00/00/wkggvez3y9maaaaaaaaadigvbpc73.html source IP address:192.168.6.100 file timestamp=2010-12-02 17:16:03 file size=14 file crc32=674197143 file url:http://192.168.6.10 0/group1/m00/00/00/wkggvez3y9maaaaaaaaadigvbpc73.html Storage_upload_slave_by_filename GrouP_name=group1, remote_filename=m00/00/00/wkggvez3y9maaaaaaaaadigvbpc73_big.html source IP address:192.168.6.100 File timestamp=2010-12-02 17:16:03 file size=14 file crc32=674197143 file url:http://192.168.6.100/group1/m00/00/00/ Wkggvez3y9maaaaaaaaadigvbpc73_big.html

Open IE Browser access:

This article is from the "linuxer" blog, please be sure to keep this source http://deidara.blog.51cto.com/400447/440175

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.