A deer can follow a sheep when its heart and body follow a sheep when its heart leads

directory

  • Version overview
  • A, FastDFS
    • 1.1 Installing dependency packages
    • 1.2 installation libfastcommon
    • 1.3 installation fastdfs
    • 1.4 the command line
    • 1.5 test
  • Second, the Nginx
    • 2.1 install nginx
    • 2.2 the command line
    • 2.3 test

Version overview

  • Libfastcommon – 1.0.42
  • Fastdfs – 5.11 –
  • Fastdfs – nginx – module – 1.20
  • Nginx – 1.16.1

A, FastDFS

1.1 Installing dependency packages

yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel -y
Copy the code

1.2 installation libfastcommon

  • Github selects the release version to install

Github.com/happyfish10…

  • Downloading the Installation package

Wget HTTP: / / https://github.com/happyfish100/libfastcommon/archive/V1.0.42.tar.gz

  • Unpack the

The tar - ZXVF V1.0.42. Tar. Gz

  • The installation
CD libfastcommon-1.0.42/./make. Sh./makeCopy the code
  • Possible error:
. / make. Sh: line 14: GCC: command was not found. / make. Sh: line 15:. / a.out: Cc -wall -d_file_offset_bits =64 -d_gnu_source -g -o3 -c -o hash. O hash. C make: cc: command not found make: *** [hash.o] Error 127Copy the code
  • Solution:
GCC yum -y install GCC automake libtool make Install GCC automake autoconf libtool make install GCC automake autoconf libtool make. /makeCopy the code

1.3 installation fastdfs

  • Github selects the release version to install

Github.com/happyfish10…

  • Downloading the Installation package

Wget HTTP: / / https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz

  • Unpack the

The tar - ZXVF V5.11. Tar. Gz

  • compile

./make.sh

  • The installation

./make.sh install

Possible error:

Fatal error fastcommon/buffered_file_writer.h: There is no such file or directoryCopy the code

Solution:

Lower version recompile (do this for now, without further investigation)Copy the code
  • Copy the configuration file and modify the configuration
cd /etc/fdfs/
cp client.conf.sample client.conf
cp storage.conf.sample storage.conf
cp tracker.conf.sample tracker.conf
Copy the code
  • Modify the client. Conf
# the base path to store log files, Log and data storage location base_path = / home/work/fastdfs/fastdfs - data # tracker_server can ocur more than once, and tracker_server format is # "host:port", Host can be hostname or IP address Tracker_server IP port Tracker_Server =192.168.10.63:22122Copy the code
  • Modify trackerd. Conf
# the base path to store data and log files
base_path=/home/work/fastdfs/fastdfs-data
Copy the code
  • Modify the storaged. Conf
# the base path to store data and log files base_path=/home/work/fastdfs/fastdfs-data # store_path#, based 0, if store_path0 not exists, it's value is base_path # the paths must be exist store_path0=/home/work/fastdfs/fastdfs-data # tracker_server can ocur more than once, and tracker_server format is # "host:port", Host can be hostname or IP address Tracker_server =192.168.10.63:22122Copy the code

1.4 the command line

  • Start the
sudo service fdfs_trackerd start
sudo service fdfs_storaged start
Copy the code
  • restart
sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
Copy the code
  • Termination of
sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop
sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop
Copy the code

Note: The fDFs_Storaged service cannot be started using the kill -9 FDFS process id command because of log problems

1.5 test

  • Test upload (command format, statement + configuration file + file to upload)

Fdfs_upload_file/etc/FDFS/client. Conf. Client will return after a successful conf such as group1 / M00/00/00 / wKgBOVvulymAC1_kAAAFspt4Ii458. Conf return body structure

  • Test the download

Fdfs_download_file /etc/fdfs/client.conf The string returned in the preceding operations

  • Test to delete

Fdfs_delete_file /etc/fff/client. conf Specifies the string returned by the preceding operations

Second, the Nginx

2.1 install nginx

  • The latest stable version of Nginx can be found at nginx.org/en/download…

  • download

Wget HTTP: / / http://nginx.org/download/nginx-1.16.1.tar.gz

  • Unpack the

The tar - ZXVF nginx - 1.16.1. Tar. Gz

  • Install dependencies

yum install pcre-devel zlib zlib-devel openssl openssl-devel

  • Download the FastDFS nginx module source code and unzip it

Wget github.com/happyfish10… -SO fastdfs-nginx-module.tar.gz

  • Modify the config file in the SRC directory of the FDFS nginx module
if test -n "${ngx_module_link}"; then ngx_module_type=HTTP ngx_module_name=$ngx_addon_name ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon"# modify ngx_module_libs=" -lfastcommon-lfdfsclient" ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c" ngx_module_deps= CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -dfdfs_output_chunk_size ='256*1024' -dfdfs_mod_conf_filename ='\" /mod_fastdfs.conf\"'"# modify. auto/module else HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module" NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c" CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient" CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -dfdfs_output_chunk_size ='256*1024' -dfdfs_mod_conf_filename ='\" self FDFS /mod_fastdfs.conf\"'"# modify FI in nginx module SRC directoryCopy the code
  • Modify the mod_fastdfs.conf file in the SRC directory of the FDFS nginx module
# fastdfs tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address # valid only when load_fdfs_parameters_from_tracker is true Tracker_server =192.168.10.63:22122 # if the URL/uri including the group name # set to false when uri like /M00/00/00/xxx # set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx # default value is false url_have_group_name = true # store_path#, based 0, if store_path0 not exists, It's value is base_path # The paths must be exist # must same as storage.conf store_path0= same as fastdfs configurationCopy the code
  • Run the following command in the nginx directory

/configure --add-module= your FDFS nginx path /fastdfs-nginx-module-1.20/ SRC /

  • Nginx directory to compile and install (if you do not install the above module, you must execute first./configure)
make
make install
Copy the code
  • Modify the nginx configuration, modify the nginx installation directory conf/nginx.conf, add a custom server, or change the default
server { listen 18000; server_name localhost; location ~/group[0-9]/{ ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }}Copy the code

2.2 the command line

  • Start the nginx
CD /usr/local/nginx/sbin/run the./nginx -s stop command to start the nginx process./nginx -s stop command is equivalent to obtaining the Nginx process ID and then running the kill command to forcibly kill the process /nginx -s reload The configuration takes effect. You need to restart nginx. You do not need to stop nginx before starting it.Copy the code
  • Configuration file location (note, not conf in the installation directory, but in the following directory)

/user/local/nginx/conf/

  • Log file location

/usr/local/nginx/logs

  • Possible error:
The httpconf file is missingCopy the code
  • The solution
Copy http.conf and mime.types files from the conf folder in the Fastdfs installation folder to /fastdfs-nginx-module-1.20/ SRC. Add modules, compile, install, and start nginxCopy the code
  • Self-start upon startup
Vim/etc/rc. Local new/usr/local/nginx/sbin/nginxCopy the code

2.3 test

  • Nginx test, using the file ID returned from the file upload test

Wget http://127.0.0.1:18000/ above the string returned by the test upload file

  • The cluster configuration
  • The prerequisite is to set up at least two FDFS services
  • Each service stroage.conf adds two Tracker_Servers
# tracker_server can ocur more than once, and tracker_server format is # "host:port", Host can be hostname or IP address Tracker_server =192.168.1.57:22122 Tracker_server =192.168.1.211:22122Copy the code
  • Configure two Tracker_Servers in the client.conf of each service
# tracker_server can ocur more than once, and tracker_server format is # "host:port", Host can be hostname or IP address Tracker_server =192.168.1.57:22122 Tracker_server =192.168.1.211:22122Copy the code
  • Likewise the nginx module mod_fastdfs.conf
# FastDFS tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address # valid only when load_fdfs_parameters_from_tracker is true Tracker_server = 192.168.1.211 tracker_server = 192.168.1.57:22122:22122Copy the code
  • Cluster testing

After the configuration is ok, restart the Trackerd Server and Storaged Server for each service to view the Trackerd. log

[2018-11-19 14:14:56] INFO - file: tracker_relationship.c, line: 389, selecting leader... [2018-11-19 14:14:58] info-file: tracker_service.c, line: 979, the tracker leader is 192.168.1.57:22122Copy the code
  • View storaged. Log
[2018-11-19 14:14:58] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 192.168.1.57:22122, as a tracker client, My IP address is 192.168.1.211 [2018-11-19 14:14:58] info-file: storage_sync.c, line: 2732, successfully connect to storage server 192.168.1.57:23000 [2018-11-19 14:15:28] info-file: Tracker_client_thread. c, line: 1263, Tracker server 192.168.1.57:22122, set tracker leader: 192.168.1.57:22122Copy the code
  • After uploading the file, download the file through nginx and test it.

  • Nginx configuration file reference

nginx.conf

#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' #  '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; Port upstream ceson-api {server 127.0.0.1:9997; } # listen 21001 port server {listen 21001; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #location / { # root html; # index index.html index.htm; #} # match all requests in the url with /ceson-api/, If the match is successful, go to location /ceson-api/ {# forward the request to http://alias/XXX/proxy_pass http://ceson-api/serever-api/ as declared above; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; client_max_body_size 500m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } # to match the url/group1 M00 all requests, after the success of the match into the location/group1 M00 {# alias to find files under the directory/home/work/fastDFS/fastDFS - data; } # select * from '/';} # select * from '/'; location / {root /home/work/static/ceson-web; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php${# proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php${# root HTML; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } server { listen 21002; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #location / { # root html; # index index.html index.htm; #} location /ceson-api/ { proxy_pass http://ceson-api/server-api/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; client_max_body_size 500m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } location / { root /home/work/static/menhu; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php${# proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php${# root HTML; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:! aNULL:! MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # #}}}Copy the code