In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to implement a distributed file server with Nginx and FastDFS. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
FastDFS is an open source lightweight distributed file system, it manages files, and its functions include file storage, file synchronization, file access (file upload, file download), etc., which solves the problems of mass storage and load balancing. It is especially suitable for online services with files as carriers, such as photo album websites, video websites and so on.
FastDFS is tailored for the Internet, taking full account of redundant backup, load balancing, linear expansion and other mechanisms, and pays attention to high availability, high performance and other indicators. Using FastDFS, it is easy to build a high-performance file server cluster to provide file upload, download and other services.
1. Download and install libfastcommon
Libfastcommon is a common C function library extracted from FastDFS and FastDHT. The basic environment can be installed.
1.1 download:
Wget https://github.com/happyfish200/libfastcommon/archive/V1.0.7.tar.gz
1.2 decompress:
Tar-zxvf V1.0.7.tar.gz
1.3 installation:
Cd libfastcommon-1.0.7. / make.sh. / make.sh install
1.4 copy the file:
Resolve the lib profile path problem in FastDFS.
Cp/usr/lib64/libfastcommon.so/usr/local/lib/libfastcommon.so cp/usr/lib64/libfastcommon.so/usr/lib/libfastcommon.so
two。 Download and install FastDFS
2.1 download:
Wget https://github.com/happyfish200/fastdfs/archive/V5.05.tar.gz
2.2 decompression:
Tar-zxvf V5.05.tar.gz
2.3 installation:
Cd fastdfs-5.05. / make.sh. / make.sh install
After the installation is complete, the default configuration file directory is: / etc/fdfs/, default command is placed in / usr/bin/, starting with fdfs_.
3. Configure FastDFS
First copy the configuration file to the / etc/fdfs directory.
The cd/home/fantj/download/fastdfs-5.05/conf cp*/etc/fdfs/ is as follows: [root@s168 conf] # cd/etc/fdfs/ [root@s168 fdfs] # ls anti-steal.jpg client.conf.sample mime.types storage.conf.sample tracker.conf client.conf http.conf storage.conf storage_ids.conf tracker.conf.sample
3.1. Configure tracker.conf
FastDFS tracker
Modify the configuration as follows:
# Tracker data and log directory address (root directory must exist, subdirectory will be created automatically) base_path=/fastdfs/tracker port=22122
3.1.1 create the directory:
Mkdir-p/fastdfs/tracker3.1.2 startup / shutdown:
Fdfs_trackerd/etc/fdfs/tracker.conf start/stop uses the configuration file under / etc/fdfs by default. If there is a specified configuration, you can append the parameters later. If there is a firewall, open the firewall rules.
3.1.3 set boot:
# systemctl enable fdfs_trackerd or: # vim / etc/rc.d/rc.local join configuration: / etc/init.d/fdfs_trackerd start
3.1.4 tracker server directory and file structure:
After the Tracker service starts successfully, two directories, data and logs, will be created under base_path. The directory structure is as follows:
${base_path} | _ _ data | | _ _ storage_groups.dat: storage grouping information | | _ _ storage_servers.dat: storage server list | _ _ logs | | _ _ trackerd.log:tracker server log file
3.2. Configure storage
The following is only the basic configuration, if you have a more subtle need, please review all configurations.
Group_name=fantj # group name base_path=/fastdfs/storage # log directory store_path0=/fastdfs/storage # storage directory tracker_server=192.168.27.168:22122 # tracker node http.server_port=8888 # port
3.2.1 start
You can start fdfs_storaged/etc/fdfs/storage.conf start in this way or in this way, and you can use this # service fdfs_storaged start later.
3.2.2 check the process
Netstat-unltp | grep fdfs3.2.3 Storage starts up
# systemctl enable fdfs_storaged or: # vim / etc/rc.d/rc.local join configuration: / etc/init.d/fdfs_storaged start
3.2.4 Storage directory
After Storage starts successfully, the data and logs directories are created under base_path to record the information of Storage Server.
Under the store_path0 directory, create the following subdirectories:
[root@s168 data] # pwd / fastdfs/storage/data [root@s168 data] # ls 00 07 0E 15 1C 23 2A 31 38 3F 46 4D 54 5B 62 69 70 77 7E 85 8C 93 9A A1 A8 AF B6 BD C4 CB D2 D9 E0 E7 EE F5 FC 01 08 0F 16 1D 24 2B 32 39 40 47 4E 55 5C 63 6A 71 78 7F 86 8D 94 9B A2 A9 B0 B7 BE C5 CC D3 DA E1 E8 EF F6 FD 02 09 10 17 1E 25 2C 33 3A 41 48 4F 56 5D 64 6B 72 79 80 87 8E 95 9C A3 AA B1 B8 BF C6 CD D4 DB E2 E9 F0 F7 fdfs_storaged.pid 03 0A 11 18 1F 26 2D 34 3B 42 49 50 57 5E 65 6C 73 7A 81 88 8F 96 9D A4 AB B2 B9 C0 C7 CE D5 DC E3 EA F1 F8 FE 04 0B 12 19 20 27 2E 35 3C 43 4A 51 58 5F 66 6D 74 7B 82 89 90 97 9E A5 AC B3 BA C1 C8 CF D6 DD E4 EB F2 F9 FF 05 0C 13 1A 21 28 2F 36 3D 44 4B 52 59 60 67 6E 75 7C 83 8A 91 98 9F A6 AD B4 BB C2 C9 D0 D7 DE E5 EC F3 FA storage_stat.dat 06 0D 14 1B 22 29 30 37 3E 45 4C 53 5A 61 68 6F 76 7D 84 8B 92 99 A0 A7 AE B5 BC C3 CA D1 D8 DF E6 ED F4 FB sync
3.3. Configure client
Vim client.conf tracker_server=192.168.27.168:22122 # tracker Node base_path=/fastdfs/client # Log path
3.4. Local picture upload test
[root@s168 fdfs] # fdfs_upload_file/etc/fdfs/client.conf/home/test.png fantj/M00/00/00/wKgbqFu7T7iAJh7lAABDYbhAMC4812.png or: [root@s168 fdfs] # fdfs_test/etc/fdfs/client.conf/home/test.png ThisisFastDFSclient test program v5.05 Copyright (C) 2008 Happy fish FastDFSmay be copied only under the terms of the GNUGeneral PublicLicenseV3,which may be foundintheFastDFSsource kit. Pleasevisit theFastDFSHomePage http://www.csource.org/ formore detail. [2018-5-0820 41v] DEBUG-base_path=/fastdfs/client,connect_timeout=30,network_timeout=60,tracker_server_count=1,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 invalid operation:/home/test.png
4. Install nginx
I have written an installation article about nginx before, so I won't repeat it here. For those that have not been installed, click:
Click to view my article: nginx installation
5. FastDFS configuration Nginx module
Fastdfs-nginx-module can redirect the file to the source server to fetch the file, avoiding the file inaccessible error caused by the replication delay on the client.
5.1 download and install
Wget https://github.com/happyfish200/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip unzip5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1/fastdfs-nginx-module
5.2 configure Nginx
Ngix-s stop cd nginx-1.12.1 # add module. / configure--add-module=../fastdfs-nginx-module/src (if you have nginx installed by yum, I haven't found a solution yet. The current method is to check the nginx version by nginx-V, then download a nginx of the same version, and then back up the data under / etc/nginx. Restore after make&&make install completion) # recompile and install make make install # copy configuration file [root@s168 src] # pwd / home/fantj/download/fastdfs-nginx-module/src [root@s168 src] # cp mod_fastdfs.conf/etc/fdfs/
Configuration / etc/fdfs/mod_fastdfs.conf file
# configure / etc/fdfs/mod_fastdfs.conf file base_path=/fastdfs/tmp # log directory store_path0=/fastdfs/storage tracker_server=192.168.27.168:22122 # the groupname of the local storage server group_name=fantj # and groupname of storage correspond to url_have_group_name=true # enable group_name attached to url
Configure nginx
# configure nginx [root@s168 fdfs] # cd/usr/local/nginx/conf/ [root@s168 conf] # vim nginx.conf # add the following configuration server {listen88; server_name192.168.27.168; location/fantj/M00 {ngx_fastdfs_module }} # enter the / usr/local/nginx/sbin directory to perform configuration detection [root@s168 sbin] #. / nginx-t ngx_http_fastdfs_set pid=6431 nginx:the configuration file/usr/local/nginx/conf/nginx.conf syntaxisok nginx:configuration file/usr/local/nginx/conf/nginx.conf testissuccessful # launch nginx [root@s168 sbin] # / nginx ngx_http_fastdfs_set pid=6436
Service restart and test
[root@s168 fdfs] # fdfs_trackerd tracker.conf restart waitingforpid [1202] exit... Starting... [root@s168 fdfs] # fdfs_storaged storage.conf restart waitingforpid [1211] exit... Starting... [root@s168 fdfs] # / usr/local/nginx/sbin/nginx-s reload ngx_http_fastdfs_set pid=6463
6. Configuration successful test
This is the end of the article on "how to implement a distributed file server with Nginx and FastDFS". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.