Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to achieve load balancing in FastDFS Cluster tracker

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The following brings you how the FastDFS cluster tracker achieves load balancing, hoping to give you some help in practical application. Load balancing involves a lot of things, not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

Functions: file storage, synchronization, upload, download, provide load balancing function, suitable for picture and video storage.

Roles:

Tracker

Function: task scheduling accepts the access of the client, retrieves the storage node, and provides an available storage for the client.

Storage

Function: accept the scheduling of Tracker, respond to the client request, store the file sent by the client to the corresponding storage location, read the requested file, and send it to the client.

The following is to build an experimental environment using three virtual machines:

Three machines act as storage nodes, two of which are configured with tracker as the master / slave relationship and storage role as well. When one tracker downmachine is followed by the other one, it can provide normal access connection.

Tracker01: 192.168.56.101

Tracker02: 192.168.56.102

Storage03:192.168.56.103

Preparatory work:

OS: CentoOS6.8

Install dependent libraries on all nodes:

Yum install-y gcc libevent libevent-doc libevent-devel libevent-headers make

Required software packages:

FastDFS_v4.06.tar.gz

Fastdfs-nginx-module_v1.15.tar.gz (nginx is required to support this module when configuring web access)

Start: the first step

[root@Master ~] # tar-xf FastDFS_ v4.06.tar.gz [root @ Master ~] # cd FastDFS [root@Master FastDFS] # lltotal 124drwxrwxr-x. 3 nginx nginx 4096 Feb 15 2013 clientdrwxrwxr-x. 2 nginx nginx 4096 Feb 15 2013 commondrwxrwxr-x. 2 nginx nginx 4096 Feb 15 2013 conf-rw-rw-r--. 1 nginx nginx 35067 Jul 28 2008 COPYING-3_0.txt-rw-rw-r--. 1 nginx nginx 28437 Jan 24 2013 HISTORYdrwxrwxr-x. 2 nginx nginx 4096 Feb 15 2013 init.d-rw-rw-r--. 1 nginx nginx 7757 Dec 23 2011 INSTALL-rwxrwxr-x. 1 nginx nginx 5133 Dec 27 2012 make.shdrwxrwxr-x. 2 nginx nginx 4096 Feb 15 2013 php_client-rw-rw-r--. 1 nginx nginx 2380 Jul 28 2008 README-rwxrwxr-x. 1 nginx nginx 1768 Apr 12 2010 restart.sh-rwxrwxr-x. 1 nginx nginx 1680 Apr 10 2010 stop.shdrwxrwxr-x. 4 nginx nginx 4096 Feb 15 2013 storagedrwxrwxr-x. 2 nginx nginx 4096 Feb 15 2013 testdrwxrwxr-x. 2 nginx nginx 4096 Feb 15 2013 tracker [root@Master FastDFS] #. / make.sh & &. / make.sh install [root@Master FastDFS] # cp conf/storage_ids.conf / etc/fdfs/ [root@Master FastDFS] # cp init.d/fdfs_trackerd / etc/init.d # copy tracker startup file [root@Master FastDFS] # cp init.d/fdfs_storaged / etc/init.d # copy storage startup file

Suggestion: please read INSTALL file before compiling

Step 2: create a data directory

Mkdir-p / data/fastdfs/tracker # create tracker file storage path mkdir-p / data/fastdfs/storage # create storage file storage path mkdir-p / data/fastdfs/client # create client file storage path

Step 3: modify the configuration file

[root@Master fdfs] # lltotal 64 RW Murray. 1 root root 1500 Jun 26 14:36 client.conf-rw-r--r--. 1 root root 858 Jun 23 15:42 http.conf-rw-r--r--. 1 root root 31172 Jun 23 15:42 mime.types-rw-r--r--. 1 root root 3898 Jun 26 15:35 mod_fastdfs.conf-rw-r--r--. 1 root root 7496 Jun 26 15:22 storage.conf-rw-r--r--. 1 root root 171 Jun 26 15:45 storage_ids.conf-rw-r--r--. 1 root root 6624 Jun 26 16:04 if other files are missing from the mod_fastdfs.conf file in the directory above tracker.conf#, please check whether libevent is installed [root@Master fdfs] # grep-vE "^ # | ^ $" tracker.confdisabled=falsebind_addr=port=22122connect_timeout=30network_timeout=60base_path=/data/fastdfs/trackermax_connections=4096work_threads=4store_lookup=0store_server=0store_path=0download_server=0reserved_storage_space = 10%log_level=inforun_by_group=run_by_user=allow_hosts=*sync_log_buff_interval = 10check_active_interval = 120thread_stack_size = 64KBstorage_ip_changed_auto_adjust = truestorage_sync_file_max_delay = 86400storage_sync_file_max_time = 300use_trunk_file = falseslot_min_size = 256slot_max_size = 16MBtrunk_file_size = 64MBtrunk_create_file_advance = falsetrunk_create_file_time_base = 02:00trunk_create_file_interval = 86400trunk_create_file_space_threshold = 20Gtrunk_init_check_occupying = falsetrunk_init_reload_from_binlog = falseuse_storage_ Id = falsestorage_ids_filename = storage_ids.confid_type_in_filename = ipstore_slave_file_use_link = falserotate_error_log = falseerror_log_rotate_time=00:00rotate_error_log_size = 0use_connection_pool = falseconnection_pool_max_idle_time = 3600http.server_port=8080http.check_alive_interval=30http.check_alive_type=tcphttp.check_alive_uri=/status.html# above are the contents of the configuration file Please understand the meaning of each parameter by yourself.

Cat / etc/fdfs/storage_ids.conf

[root@Master fdfs] # cat storage_ids.conf# 100001 group1 192.168.56.101 100002 group1 192.168.56.102 100003 group1 192.168.56.103

[root@Master fdfs] # grep-vE'^ # | ^ $'client.conf

Connect_timeout=30network_timeout=60base_path=/data/fastdfs/clienttracker_server=192.168.56.101:22122tracker_server=192.168.56.102:22122log_level=infouse_connection_pool = falseconnection_pool_max_idle_time = 3600load_fdfs_parameters_from_tracker=falseuse_storage_id = falsestorage_ids_filename = storage_ids.confhttp.tracker_server_port=8080

Please modify the / etc/fdfs/tracker.conf file on all tracker hosts

Please modify the / etc/fdfs/storage.conf file on all storage hosts

Cat / etc/fdfs/storage.conf

[root@Master fdfs] # grep-vE "^ # | ^ $" storage.confdisabled=falsegroup_name=group1bind_addr=client_bind=trueport=23000connect_timeout=30network_timeout=60heart_beat_interval=30stat_report_interval=60base_path=/data/fastdfs/storagemax_connections=256buff_size = 256KBwork_threads=4disk_rw_separated = truedisk_reader_threads = 1disk_writer_threads = 1sync_wait_msec=50sync_interval=0sync_start_time=00:00sync_end_time=23:59write_mark_file_freq=500store_path_count=1store_path0=/data/fastdfs/storagesubdir_count_per_path=256tracker_server=192.168.56.101 : 22122tracker_server=192.168.56.102:22122log_level=inforun_by_group=run_by_user=allow_hosts=*file_distribute_path_mode=0file_distribute_rotate_count=100fsync_after_written_bytes=0sync_log_buff_interval=10sync_binlog_buff_interval=10sync_stat_file_interval=300thread_stack_size=512KBupload_priority=10if_alias_prefix=check_file_duplicate=0file_signature_method=hashkey_namespace=FastDFSkeep_alive=0use_access_log = falserotate_access_log = falseaccess_log_rotate_time=00:00rotate_error_log = falseerror_log_rotate_time=00:00rotate_access _ log_size = 0rotate_error_log_size = 0file_sync_skip_invalid_record=falseuse_connection_pool = falseconnection_pool_max_idle_time = 3600http.domain_name=http.server_port=8888

Step 4: start tracker and storage

[root@Master fdfs] # / etc/init.d/fdfs_trackerd start [root@Master fdfs] # / etc/init.d/fdfs_storaged start [root@Master fdfs] # ps-ef | grep fdfsroot 3157 10 11:55? 00:00:00 / usr/local/bin/fdfs_trackerd / etc/fdfs/tracker.confroot 3188 10 11:56? 00:00:00 / usr/local/bin/fdfs_storaged / etc/ Fdfs/storage.confroot 3217 2434 0 11:57 pts/0 00:00:00 grep fdfs [root@Master fdfs] #

Note: if startup fails, check the log / data/fastdfs/tracker/logs/trackerd.log

At this point: tracker and storage have been started.

View the cluster status:

[root@Master] # / usr/local/bin/fdfs_monitor / etc/fdfs/storage.conf

[2017-06-27 12:02:31] DEBUG-base_path=/data/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_server_count=2, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

Server_count=2, server_index=0

Tracker server is 192.168.56.101:22122

Group count: 1

Group 1:

Group name = group1

Disk total space = 8447 MB

Disk free space = 4924 MB

Trunk free space = 0 MB

Storage server count = 3

Active server count = 1

Storage server port = 23000

Storage HTTP port = 8888

Store path count = 1

Subdir count per path = 256

Current write server index = 0

Current trunk file id = 0

Storage 1:

Id = 192.168.56.101

Ip_addr = 192.168.56.101 (Master) WAIT_SYNC

Http domain =

Version = 4.06

Join time = 2017-06-26 15:22:46

Up time = 2017-06-27 11:49:39

Total storage = 0 MB

Free storage = 0 MB

Upload priority = 10

Store_path_count = 1

Subdir_count_per_path = 256

Storage_port = 23000

Storage_http_port = 8888

Current_write_path = 0

Source storage id=

If_trunk_server= 0

Total_upload_count = 0

Success_upload_count = 0

Total_append_count = 0

Success_append_count = 0

Total_modify_count = 0

Success_modify_count = 0

Total_truncate_count = 0

Success_truncate_count = 0

Total_set_meta_count = 0

Success_set_meta_count = 0

Total_delete_count = 0

Success_delete_count = 0

Total_download_count = 0

Success_download_count = 0

Total_get_meta_count = 0

Success_get_meta_count = 0

Total_create_link_count = 0

Success_create_link_count = 0

Total_delete_link_count = 0

Success_delete_link_count = 0

Total_upload_bytes = 0

Success_upload_bytes = 0

Total_append_bytes = 0

Success_append_bytes = 0

Total_modify_bytes = 0

Success_modify_bytes = 0

Stotal_download_bytes = 0

Success_download_bytes = 0

Total_sync_in_bytes = 0

Success_sync_in_bytes = 0

Total_sync_out_bytes = 0

Success_sync_out_bytes = 0

Total_file_open_count = 0

Success_file_open_count = 0

Total_file_read_count = 0

Success_file_read_count = 0

Total_file_write_count = 0

Success_file_write_count = 0

Last_heart_beat_time = 1970-01-01 08:00:00

Last_source_update = 1970-01-01 08:00:00

Last_sync_update = 1970-01-01 08:00:00

Last_synced_timestamp = 1970-01-01 08:00:00 (never synced)

Storage 2:

Id = 192.168.56.102

Ip_addr = 192.168.56.102 (Minion02) ACTIVE

Http domain =

Version = 4.06

Join time = 2017-06-26 15:12:53

Up time = 2017-06-27 11:50:08

Total storage = 8447 MB

Free storage = 4945 MB

Upload priority = 10

Store_path_count = 1

Subdir_count_per_path = 256

Storage_port = 23000

Storage_http_port = 8888

Current_write_path = 0

Source storage id=

If_trunk_server= 0

Total_upload_count = 6

Success_upload_count = 6

Total_append_count = 0

Success_append_count = 0

Total_modify_count = 0

Success_modify_count = 0

Total_truncate_count = 0

Success_truncate_count = 0

Total_set_meta_count = 6

Success_set_meta_count = 6

Total_delete_count = 0

Success_delete_count = 0

Total_download_count = 0

Success_download_count = 0

Total_get_meta_count = 0

Success_get_meta_count = 0

Total_create_link_count = 0

Success_create_link_count = 0

Total_delete_link_count = 0

Success_delete_link_count = 0

Total_upload_bytes = 63284

Success_upload_bytes = 63284

Total_append_bytes = 0

Success_append_bytes = 0

Total_modify_bytes = 0

Success_modify_bytes = 0

Stotal_download_bytes = 0

Success_download_bytes = 0

Total_sync_in_bytes = 120

Success_sync_in_bytes = 120

Total_sync_out_bytes = 240,

Success_sync_out_bytes = 240,

Total_file_open_count = 10

Success_file_open_count = 10

Total_file_read_count = 0

Success_file_read_count = 0

Total_file_write_count = 10

Success_file_write_count = 10

Last_heart_beat_time = 2017-06-27 12:02:14

Last_source_update = 2017-06-27 12:01:01

Last_sync_update = 2017-06-26 15:55:03

Last_synced_timestamp = 1970-01-01 08:00:00 (never synced)

Storage 3:

Id = 192.168.56.103

Ip_addr = 192.168.56.103 (Minion03) WAIT_SYNC

Http domain =

Version = 4.06

Join time = 2017-06-26 15:14:03

Up time = 2017-06-27 11:50:25

Total storage = 8447 MB

Free storage = 4924 MB

Upload priority = 10

Store_path_count = 1

Subdir_count_per_path = 256

Storage_port = 23000

Storage_http_port = 8888

Current_write_path = 0

Source storage id= 192.168.56.102

If_trunk_server= 0

Total_upload_count = 2

Success_upload_count = 2

Total_append_count = 0

Success_append_count = 0

Total_modify_count = 0

Success_modify_count = 0

Total_truncate_count = 0

Success_truncate_count = 0

Total_set_meta_count = 2

Success_set_meta_count = 2

Total_delete_count = 0

Success_delete_count = 0

Total_download_count = 0

Success_download_count = 0

Total_get_meta_count = 0

Success_get_meta_count = 0

Total_create_link_count = 0

Success_create_link_count = 0

Total_delete_link_count = 0

Success_delete_link_count = 0

Total_upload_bytes = 22

Success_upload_bytes = 22

Total_append_bytes = 0

Success_append_bytes = 0

Total_modify_bytes = 0

Success_modify_bytes = 0

Stotal_download_bytes = 0

Success_download_bytes = 0

Total_sync_in_bytes = 995

Success_sync_in_bytes = 240,

Total_sync_out_bytes = 120

Success_sync_out_bytes = 120

Total_file_open_count = 10

Success_file_open_count = 10

Total_file_read_count = 0

Success_file_read_count = 0

Total_file_write_count = 10

Success_file_write_count = 10

Last_heart_beat_time = 2017-06-27 12:02:10

Last_source_update = 2017-06-26 15:54:52

Last_sync_update = 2017-06-26 16:04:33

Last_synced_timestamp = 1970-01-01 08:00:00 (never synced)

Test:

Upload files to FastDFS, upload multiple files to storage to see if the upload location has changed

Stop tracker01 to see if you can switch to tracker02.

Upload files:

[root@Master] # / usr/local/bin/fdfs_test / etc/fdfs/client.conf upload install.log

After reading the above about how to achieve load balancing in FastDFS cluster tracker, if you have anything else you need to know, you can find out what you are interested in in the industry information or find our professional and technical engineers for answers. Technical engineers have more than ten years of experience in the industry.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report