1. Download the required installation package:

Download the following installation packages in the server root directory (you can also download them elsewhere) : Wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz - O libfastcommon. Tar. Gz fastdfs package download: Wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz - O fastdfs. Tar. Gz nginx package download: Wget http://nginx.org/download/nginx-1.12.0.tar.gz - O nginx. Tar. Gz fastdfs - nginx module package download: Wget fastdfs https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz - O - nginx - module. Tar. Gz### -o renames the downloaded package
# # # in addition to nginx package, other packages are downloaded here: https://github.com/happyfish100
Copy the code

2. Environment installation

Yum -y install pcre-devel openssl openssl-devel yum -y install pcre-devel openssl-devel /configure: error: The HTTP rewrite module requires the PCRE library. Configure: Error: The HTTP rewrite module requires the PCRE library.

3. Install libfastcommon

1. Decompress the libfastcommon package tar -zxvf libfastcommon.tar.gz 2. Enter the decompressed directory:cdLibfastcommon-1.0.39 3. Install./make. Sh./makeCopy the code

4. Install FastDFS

1. Decompress the fastDFS package tar -zxvf fastdfs.tar.gz 2. Enter the decompressed directory:cd/make. Sh./make. Sh install If the installation is successful, there are four files in the /etc/fdfs directory:  -rw-r--r-- 1 root root 1461 Nov 13 09:54 client.conf.sample -rw-r--r-- 1 root root 7927 Nov 13 09:54 storage.conf.sample -rw-r--r-- 1 root root 105 Nov 13 09:54 storage_ids.conf.sample -rw-r--r-- 1 root root 7389 Nov 13 09:54 tracker.conf.sample Go to the directorycd/etc/fdfs, then copy and remove the three files. Sample:  cp client.conf.sample client.conf cp storage.conf.sample storage.conf cp tracker.conf.sample tracker.confCopy the code

5. Configuration tracker

1. Create data and save trackerlogMkdir -p /usr/local/fast-dfs/fastdfs_tracker 2. Access the directorycdRun the following command to modify the tracker.conf file: vim tracker.conf Change the file to disabled=false # enable by default
    port=22122 # Default port number
    base_path=/usr/local/fast-dfs/fastdfs_tracker # the directory you just created
    http.server_port=6666 The default port is 8080After the modification, start the tracker: /usr/bin/fdfs_trackerd /etc/fdf/tracker. conf restart Check whether the tracker has a port: Netstat ntpul | grep FDFS (if you do not see any port, the tracker start failure) other command: restart the tracker: /usr/bin/fdfs_trackerd /etc/fdf/tracker. conf restart Stop tracker: /usr/bin/fdfs_trackerd /etc/ffs/tracker. conf stop Add startup: chmod +x /etc/rc.d/rc.localecho '/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart' >> /etc/rc.d/rc.local
Copy the code

6. The configuration storage

1. Create data and storagelogMkdir /usr/local/fast-dfs/fastdfs_storage Create another file storage directory: mkdir /usr/local/fast-dfs/fastdfs_storage_data 2. Enter the directory:cdConf file. Run the vim storage.conf file as follows: disabled=false # the default false
    group_name=group1 The group name can be changed based on the actual situation
    port=23000 Set the port number of the storage group to 23000
    base_path=/usr/local/fast-dfs/fastdfs_storage Set storage data file and log directory
    store_path_count=1 Number of storage paths, which must match store_path number
    store_path0=/usr/local/fast-dfs/fastdfs_storage_data The actual file storage pathTracker_server = Public IP address of the server :22122 HTTP. server_port=8888Set the HTTP port numberCreate soft reference LN after saving the Settings-s /usr/bin/fdfs_storaged /usr/localStart up/bin storage: /usr/bin/fdfs_storaged /etc/ffs/storage. conf restart Check whether the storage has a port. Netstat ntpul | grep FDFS (if no port, storage start failure) other command: restart storage: /usr/bin/fdfs_storaged /etc/ff/storage. conf restart Stop storage: /usr/bin/fdfs_storaged /etc/ff/storage. conf stop Add startup:echo '/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart' >> /etc/rc.d/rc.local
Copy the code

7. Verify integration to determine whether storage is registered in tracker

/usr/bin/fdfs_monitor /etc/ffs/storage. conf The following figure indicates that the registration is successful

8. Configure the client

1. Access the directory:cd/etc/fdfs 2. Modify client.conf: vim client.conf: base_path=/usr/local/fast-dfs/fastdfs_tracker #tracker Specifies the server file pathTracker_server = Server public IP address :22122#tracker Specifies the server IP address and port number
    http.tracker_server_port=6666 The HTTP port number of the tracker server must correspond to the Settings of the tracker.
Copy the code

FastDFS nginx module installation

1. Go to the root directory (the directory where the download package is stored).cd~ 2. Decompress the fastdfs Nginx module package: tar -zvxf fastdfs-nginx-module.tar.gz 3. Rename the module directory: mv fastdfs-nginx-module-1.12.0 fastdfs-nginx-module 4 Run the vim /root/fastdfs-nginx-module/ SRC /config command to modify the module configuration file: ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
    CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
    CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"After saving the file, create the soft link ln-s /usr/include/fast* /usr/local5.2 Go to the Nginx decompression directory and add the Fastdfs Nginx module:cdNginx - 1.12.0. / configure -- prefix = / usr /local/storage-nginx --add-module=/root/fastdfs-nginx-module/ SRC Make make installCopy the code

10. Configure the nginx of the storage

After installing nginx, configure 1 as nginx of storage. Nginx: vim /root/nginx-1.12.0/conf/nginx.conf: vim /root/nginx-1.12.0/conf/nginx.conf: [emerg] unknown directive"" in /usr/local/ nginx - 1.12.0 - storage/conf/nginx. Conf: 49) : server {listen 9999; server_name localhost; location / { root html; index index.html index.htm; } location ~/group1/M00 { root /usr/local/fast-dfs/fastdfs_storage_data/data; ngx_fastdfs_module; }} Then go to the FastDFS installation decompressed directory, copy http.conf and mime.types to /etc/fdfs:cdTypes /root/fastdfs-5.11/conf cp http.conf /etc/fdf/cp mime.types /etc/fdf/ Copy mod_fastdfs.conf from SRC in the fastdfs-nginx-module installation directory to /etc/fdfs: Conf /etc/fdfs. conf run the following command to copy the mod_fastdfs file: vim /etc/fdf/mod_fastdfs. conf  base_path=/usr/local/fast-dfs/fastdfs_storage  # Save log directoryTracker_server = Server public IP address :22122#tracker Specifies the IP address and port number of the server
 storage_server_port=23000 Storage server port number
 url_have_group_name = true Is there a group name in the file URL
 store_path0=/usr/local/fast-dfs/fastdfs_storage_data   # storage path
 group_count = 3 # set the number of groups. In fact, only group1 is usedAt the end of the file, set group [group1] group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/usr/local/fast-dfs/fastdfs_storage_data

[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/usr/local/fast-dfs/fastdfs_storage_data

[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/usr/local/fast-dfs/ fastDFs_storage_data After saving the file, create a symbolic connection between M00 and the storage directory: ln-s  /usr/local/fast-dfs/fastdfs_storage_data/data/ /usr/local/fast-dfs/fastdfs_storage_data/data/M00 Start nginx: /usr/local/ storage - nginx/sbin/nginx - c/root/nginx - 1.12.0 / conf/nginx. Start the conf check whether port: netstat ntpul | grep nginxNignx on port 9999 indicates successful startup
Copy the code

11. Configure nginx for tracker

/configure --prefix=/usr/./configure --prefix=/usr/local/tracker-nginx --add-module=/root/fastdfs-nginx-module/ SRC Conf: upstream fdfs_group1 {server 127.0.0.1:9999; /conf/nginx.conf: upstream fdfs_group1 {server 127.0.0.1:9999; } server { listen 80; server_name localhost;#charset koi8-r;


        #access_log logs/host.access.log main;


        location /group1/M00 {
            proxy_pass http://fdfs_group1;
        }
        #location / {
        # root html;
        # index index.html index.htm;
        #}


        #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; }} After saving, start tracker's nginx: /usr/local/tracker-nginx/sbin/nginx -c /root/tracker-nginx/nginx-1.12.0/conf/nginx.conf Check whether there are 80 and 9999 ports: Netstat ntpul | grep nginx so far FastDFS service deployment is complete. Configure the firewall: 1. Enable all configured ports: firewall-cmd --zone=public --add-port=80/ TCP --permanent# Enable port 80
firewall-cmd --zone=public --add-port=23000/tcp --permanent # enable port 23000
firewall-cmd --zone=public --add-port=22122/tcp --permanent # Enable 22122 port number
firewall-cmd --zone=public --add-port=9999/tcp --permanent # enable port 9999
firewall-cmd --zone=public --add-port=6666/tcp --permanent # Enable port 6666
firewall-cmd --zone=public --add-port=8888/tcp --permanent # Enable port 8888Restart the firewall. CentOS7 Run the firewall- CMD --zone=public --list-ports command# Check open ports
firewall-cmd state   # check whether the firewall is enabled
systemctl enable firewalld.service    # enable firewall
systemctl stop firewalld.service     # turn off the firewall (it will still start)
systemctl disable firewalld.service  # Disable firewall
Copy the code

Test 12.

To test idea, perform the following operations: 1. Pull the FastdFS Java client package: File-->New--> Project from Version Control --> Github 2. Fill in Url:https://github.com/happyfish100/fastdfs-client-java.git, project directory, name, clickclone3. After the project is initialized for the first time, set your Maven installation directory: Settings --> Search for Maven --> change the maven home directory 4. Open the Maven Project window on the right and install the FastdFS Java client: Lifecycle -->install 5. Now that your Fastdfs maven dependency is installed, <dependency> <groupId>org.csource</groupId> <artifactId>fastdfs-client-java</artifactId> <version>1.27-SNAPSHOT</version> </dependency> Example: Tracker_server = Server public IP address :22122 Create a demo.java: Public class Demo {public static void main(String[] args) throws Exception{// Load the configuration file, The contents of the configuration file are the address of the tracker service clientglobal.init ("D:/myWork/fasDFS-demo/src/main/resources/fdfs_client.conf"); // Create a TrackerClient object. TrackerClient =new TrackerClient(); // Use the TrackerClient object to create a connection and get a TrackerServer object. TrackerServer trackerServer=trackerClient.getConnection(); // Create a reference to StorageServer with the value null StorageServer StorageServer =null; // Create a StorageClient object Need two parameters, StorageServer TrackerServer object reference StorageClient StorageClient = new StorageClient (TrackerServer StorageServer); // Upload images using the StorageClient object. // The extension does not contain ". String[] strings=storageClient.upload_file("C:/Users/Public/Pictures/Sample Pictures/test.jpg"."jpg",null); Prints the path containing the group name and the image.for(String string:strings){ System.out.println(string); }}} finally on the browser to access your uploaded pictures: http:// server public IP address/group1 M00/00/00 / rBsABFvqfIyACR3WAAl5WIkOlj8480. JPGCopy the code

Reference article:

Blog.csdn.net/weixin_4037… Cloud.tencent.com/developer/a…