python-django-fastdfs + Nginx installation and configuration _20191122

python-django-fastdfs + Nginx Installation and Configuration

 

FastDFS file system:

  • Is written in c language, Taobao architects write, store Taobao picture, then open source,
  • fastDFS architecture including, tracter server and storage server, tracter server responsible for the management, storage server is responsible to complete the file upload and download,
  • tracter server role is scheduling
  • storage server role is to file storage,
  • Process Description:
  • FastDFS by the client to upload a file,
  • Client to request tracter server, tracter server that manages the storage server,
  • storage server can be a cluster, there are many, tracter server can be clustered,
  • tracter server it back to find a storage server store your pictures,
  • Then tracter server would address corresponding to the image storage, back to the client,
  • So that the client knows where to upload my picture up,
  • The client will upload files to the corresponding storage location, after the storage server will save the client returns the name of a file,
  • Our projects Why choose this fastDFS? Without using django provided,
  • Before we save a file to upload a file browser, django admin page by uploading photos, according to our default is you click upload, the server will send a request to django, django server, by default the images stored in the default breakthrough save path, media_root,
  • So there will be a problem, hard disk storage space is limited, for the electricity supplier for a lot of pictures, so pictures stored will be limited django server hard disk capacity is located, so the electricity supplier site, save the picture when he django can not be saved in the server, there must be a separate file server, where the files are stored on the server we chose fastDFS,
  • There is a feature,
  • User a, upload a 123.txt, storage is not saved when the file name, but take the hash value of the contents of the file, which is a unique value, and we called the fingerprint file, we can uniquely identify a file by hash value and then under the name of a file synthesis of information storage ip, etc., returned to the client a,
  • User b, upload a file of the same, when the storage will be found to keep a file of the same file, the file will not be saved once again the content, directly to the file name corresponding to your return, so the same only a file is stored,
  • fastDFS advantages:
  • Solve the problem of mass storage,
  • Storage capacity expansion easy, just add storage service can be,
  • Solve the file storage duplicate files,
  • This is the realization of the principle Baidu cloud, it is to file fingerprints, so Baidu cloud inside 5 T, and others are shared,

Process fastDFS upload and download files

  • Client upload files when you need to request tracter server, and then returned to the customer's storage ip and port side,
  • With the storage of ip and port number, the client will pass the document over, and then save the file storage server will generate a fileID, and returned to the client,
  • This is the upload process,
  • document dowload:
  • The client requests to go tracter server, and then look at the tracter server to download the file above in which storage server, and then returned to the client storage of ip and port number,
  • With the storage of ip and port number, the client will go directly to the corresponding obtain the corresponding file storage, storage server to return the file to the client,

fastDFS installation and configuration,

  • The required installation package:
  • Build a FastDFS environment, and increase Nginx module
  • Software used:
  • fastdfs-master.zip
    fastdfs-nginx-module-master.zip
    fdfs_client-py-master.zip
    libfastcommon-master.zip
    nginx-1.8.1.tar.gz

  • Installation libfastcommon-master.zip
  • cd /usr/local/src
  • sudo unzip libfastcommon-master.zip
  • cd libfastcommon-master
  • sudo  ./make.sh     
  • sudo ./make.sh install
  • Installation: fastdfs-master
  • cd /usr/local/src
  • Decompression, fastdfs-master
  • cd fastdfs-master
  • sudo ./make.sh
  • sudo ./make.sh install
  • Configure tracking server tracker,
  • sudo cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
  • / Home / andy / fastdfs / tracker, to create such a file directory
  • Edit the configuration file, sudo vi /etc/fdfs/tracker.conf
  • Modify the configuration content: base_path = / home / andy / fastdfs / tracker
  • Configuration Storage Server storage:
  • cd / etc / FDF
  • sudo cp ./storage.conf.sample ./storage.conf
  • / Home / andy / fastdfs / storage, to create this file directory
  • Edit the configuration file, sudo vi /etc/fdfs/storage.conf
  • Modify the configuration file: base_path = / home / andy / fastdfs / storage
  • store_path0=/home/andy/fastdfs/storage
  • tracker_server=192.168.100.128:22122

Start tracker service,

Incorrect report:

Job for fdfs_trackerd.service failed because the control process exited with error code. See "systemctl status fdfs_trackerd.service" and "journalctl -xe" for details.

FDFSX tracking server's job failed, because the control process out of the error code. For more information, see "systemctl status fdfs_trackerd.service" and "journalctl-xe".

Start using another method:

  • 1, start the service:
  • # Start tracker server
  • fdfs_trackerd /etc/fdfs/tracker.conf start
  • # Start storage server
  • fdfs_storaged /etc/fdfs/storage.conf start
  • Enter ps -aux | grep fdfs, to see the service has been launched,
  • root 3488 0.0 0.1 147760 1288 ? Sl 21:50 0:00 fdfs_trackerd /etc/fdfs/tracker.conf start
  • root 3511 0.0 0.2 84356 2928 ? Sl 21:51 0:00 fdfs_storaged /etc/fdfs/storage.conf start
  • 2. Testing the installation:
  • Need to install a client, so we need to configure the client copy of the document
  • cd / etc / FDF /
  • sudo cp ./client.conf.sample ./client.conf
  • Edit the configuration file, sudo vi client.conf
  • base_path=/home/andy/fastdfs/tracker
  • tracker_server=192.168.100.128:22122
  • 3, test upload files:
  • After the installation finished fastdfs, fast gives you a command to upload a file, fdfs_upload_file
  • Usage: fdfs_upload_file <config_file> <local_filename> [storage_ip:port] [store_path_index]
  • In the desktop to create a new image file, fastfds.png
  • The desktop path, cd / home / Desktop /
  • Execute the command, / usr / bin / fdfs_upload_file /etc/fdfs/client.conf ./fastfds.png
  • Return one yard: group1 / M00 / 00/00 / wKhkgF3WnFeAOZaTAAV_23Ar72I345.png, which is kept inside the file system id
  • File remains in this path, this is the path we have configured, / home / andy / fastdfs / storage /
  • Here is this is that you can use the fastdfs

Nginx fastdfs with installation and configuration,

  • fastdfs larger than the user when obtaining data is relatively slow, we need the help of a tool, is Nginx, which is also a web server,
  • Can be used with fastdfs used in the provision of static files, high efficiency, requests relatively large, withstood the pressure,
  • We used to upload files fastdfs, but when we get the file by means of a Nginx,
  • It requires two packages:
  • I myself put the package into the / usr / local / src
  • nginx-1.8.1.tar.gz
  • fastdfs-nginx-module-master.zip
  • A total of two installation packages
  • installation steps:
  • 1, extract the package: nginx-1.8.1.tar.gz ,,,, sudo tar -zxvf nginx-1.8.1.tar.gz 
  • 2, unzip the package: fastdfs-nginx-module-master.zip ,,,, sudo unzip fastdfs-nginx-module-master.zip
  • 3, enter this directory: cd nginx-1.8.1 /
  • 4,sudo ./configure --prefix=/usr/local/nginx/ --add-module=/usr/local/src/fastdfs-nginx-module-master/src
  • --prefix, this is the time of installation directory,
  • --add-module, which is the absolute path to the module,
  • 5,make,
  • Being given
  • make: *** No rule to make target 'build', needed by 'default'。 停止。
  • solution:
  • Install openssl, the installation package myself in the / usr / local / src the following,
  •  tar -zxvf openssl-1.1.0j.tar.gz, just unzip it,
  • Installation: zlib, the installation package myself in the / usr / local / src the following,
  • tar -zxvf zlib-1.2.11.tar.gz
  • cd zlib-1.2.11
  • ./configure
  • make
  • sudo make install
  • Installing pcre, the installation package myself in the / usr / local / src the following,
  • tar -zxvf pcre-8.35.tar.gz
  • cd pcre-8.35
  • ./configure
  • make
  • sudo make install
  • Re-enter this directory: cd /usr/local/srcnginx-1.8.1/
  • 执行:sudo ./configure --prefix=/usr/local/nginx/ --with-openssl=/usr/local/src/openssl-1.1.0j --with-pcre=/usr/local/src/pcre-8.35 --with-zlib=/usr/local/src/zlib-1.2.11 --add-module=/usr/local/src/fastdfs-nginx-module-master/src
  • 6, continue sudo make
  • And he is given:
  • error: ‘FDFSHTTPParams {aka struct <anonymous>}’ has no member named ‘support_multi_range’
  • (pContext->range_count > 1 && !g_http_params.support_multi_range))
  • Download another version of the template: name: FastDFS-nginx-master-test.zip, the installation package myself in the / usr / local / src the following,
  • Unzip this problem,
  • Re-enter this directory: cd /usr/local/srcnginx-1.8.1/
  • 执行:sudo ./configure --prefix=/usr/local/nginx/ --with-openssl=/usr/local/src/openssl-1.1.0j --with-pcre=/usr/local/src/pcre-8.35 --with-zlib=/usr/local/src/zlib-1.2.11 --add-module=/usr/local/src/fastdfs-nginx-module-test/src
  • Well, not being given the
  • 7,sudo make install
  • Success! ! ! I installed the cd / usr / local / nginx / directory

 Nginx configuration

  • Enter the directory: / usr / local / src / fastdfs-nginx-module-test / src
  • Copy, sudo cp mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf
  • Into the directory cd / etc / fdfs /
  • Edit the configuration file: sudo vi mod_fastdfs.conf
  • Several local time to see the video, or find tutorials here do not write,
  • Enter the directory: /usr/local/src/fastdfs-5.05/conf
  • Then copy the two files:
  • sudo cp http.conf /etc/fdfs/http.conf
  • sudo cp mime.types /etc/fdfs/mime.types
  • Then enter: / usr / local / nginx / conf
  • Modify the configuration file, sudo vi nginx.conf
  • Start Nginx, enter: / usr / local / nginx / sbin, enter the command, sudo ./nginx
  • nginx start error: error while loading shared libraries
  • Check dependencies, which is based on the very important, ldd $ (which / usr / local / nginx / sbin / nginx)
  • Take a look at pcre have not installed: pcre-config --version display if the installed version is not installed and consequently do not, I installed,
  • I know the version of the problem: fastdfs-master
  • Close Nginx 
  • But also out of the question: 'About Nginx started successfully, the solution can not access the browser, reported 404 errors,
  • Turned out to be a configuration problem, that is,
  • listen 8888;
  • server_name localhost;
  • location ~/group([0-9])/ {
  • root /fastdfs/storage/data;
  • ngx_fastdfs_module;
  • }
  • ~ This, wrote the - the

 

 

Guess you like

Origin www.cnblogs.com/andy0816/p/11911048.html