FastDFS is installed based on Docker

Not to mention the performance of Docker in the production environment for the time being, just in terms of the ability to quickly build the environment in the process of learning new technologies, it is worth recommending you to try it. This article takes you to install FastDFS service based on Docker.

Even if you are not interested in the installation of FastDFS, you can also learn about the Docker installation process (basically general), which is one of the magic weapons to improve learning efficiency.

If you want to learn about the principles of FastDFS, please refer to " Detailed Explanation of the Principles of File Management System FastDFS ", which will help you understand and learn the following content.

Docker install FastDFS

Regarding the installation of Docker, different operating systems have different installation methods, so I won't repeat them here. By default, Docker has been installed and started on your computer or server.

Let's take a look at which images are already available in the Docker library. Execute the following command (sudo may be required if you are not an administrator):

bogon:~ zzs$ docker search fastdfs
NAME                           DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
season/fastdfs                 FastDFS                                         66
luhuiguo/fastdfs               FastDFS is an open source high performance d…   25                                      [OK]
ygqygq2/fastdfs-nginx          整合了nginx的fastdfs                                20                                      [OK]
morunchang/fastdfs             A FastDFS image                                 19
delron/fastdfs                                                                 12
moocu/fastdfs                  fastdfs5.11                                     9
qbanxiaoli/fastdfs             FastDFS+FastDHT单机版                              8                                       [OK]
……

If you are installing other software, you can also search through the docker search command.

The mirror named delron/fastdfs is used here. Of course, you can also choose other mirrors. The configuration will be different. Some mirrors do not have Nginx related configuration.

So, let's pull it down.

docker pull delron/fastdfs

Build Tracker container

Use the docker image to build the tracker container, which is used to start the tracking server and play a role in scheduling.

docker run -d --network=host --name tracker -v /Users/zzs/develop/temp/tracker:/var/fdfs delron/fastdfs tracker

The above startup command is under Linux. If it is a Mac or Windows operating system network=host (the container and the host enjoy the same network namespace), it will fail. At this time, you need to specify the corresponding port mapping. The Docker host for this tutorial is Mac.

docker run -d --name tracker -p 22122:22122 -v /Users/zzs/develop/temp/tracker:/var/fdfs delron/fastdfs tracker

The default tracker is listening on port 22122.

The -v parameter mounts the local directory and the /var/fdfs directory in the container.

Here you can see that the tracker service has been started.

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                     NAMES
15bfca8b94eb        delron/fastdfs      "/usr/bin/start1.sh …"   4 seconds ago       Up 3 seconds        8080/tcp, 8888/tcp, 23000/tcp, 0.0.0.0:22122->22122/tcp   tracker

Build a storage container

Use docker image to build storage container, used to start storage server, provide capacity and backup service.

When you need to be reminded when executing the following commands, the corresponding IP address needs to be modified to the IP address of the tracker service. Since it is operated on the same computer, the intranet address of the machine can be used here. 22122 is the tracker corresponding port.

For example, the following command needs to replace the IP address.

docker run -d --network=host --name storage -e TRACKER_SERVER=ip:22122 -v /Users/zzs/develop/temp/storage:/var/fdfs -e GROUP_NAME=group1 delron/fastdfs storage

After replacing the IP address, the specific execution operation under the corresponding Mac:

docker run -d --name storage -p 8888:8888 -p 23000:23000 -e TRACKER_SERVER=192.168.43.143:22122 -v /Users/zzs/develop/temp/storage:/var/fdfs -e GROUP_NAME=group1 delron/fastdfs storage

Among them, 8888 is the access port corresponding to Nginx, and 23000 is the storage service port.

At this time, you can view the service status of docker:

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                   NAMES
2bc9f8268eda        delron/fastdfs      "/usr/bin/start1.sh …"   5 seconds ago       Up 4 seconds        8080/tcp, 0.0.0.0:8888->8888/tcp, 22122/tcp, 0.0.0.0:23000->23000/tcp   storage
15bfca8b94eb        delron/fastdfs      "/usr/bin/start1.sh …"   2 minutes ago       Up 2 minutes        8080/tcp, 8888/tcp, 23000/tcp, 0.0.0.0:22122->22122/tcp                 tracker

Change setting

After the above steps, tracker and storage are both started and completed. We can enter the corresponding docker container to check the default configuration.

The command to enter docker is:

docker exec -it 2bc9f8268eda bash

The parameter value "2bc9f8268eda" is the CONTAINER ID of the container we saw above to enter.

First enter storage and check the http access configuration in its corresponding configuration file. The configuration file is storage.conf in the /etc/fdfs directory. You can see the following configuration in the last line:

# the port of the web server on this storage server
http.server_port=8888

In other words, the default monitoring port in this docker image is port 8888. Of course, this configuration needs to be modified. If you modify it to another port, the corresponding Nginx configuration also needs to be modified.

So where is Nginx configured? Also in the current container. The root directory of the Nginx configuration file is:

/usr/local/nginx/conf/

You can view and modify the nginx.conf under it. First look at the default configuration:

server {
    listen       8888;
    server_name  localhost;
    location ~/group[0-9]/ {
        ngx_fastdfs_module;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root html;
    }
}

The above is about the server configuration, the port corresponds to the storage port one-to-one. If you need to modify the two synchronous modifications.

Through the above operation, you will find that by default FastDFS will need to open ports 8888, 23000, and 22122. If you are in the Linux operating system, pay attention to the opening of the corresponding ports by the firewall.

have a test

After the above steps have completed the installation and configuration of FastDFS, let's put a picture to verify.

First, place a picture in the local mount directory /Users/zzs/develop/temp/storage (the directory used in the above command).

Then, enter the storage container, enter the /var/fdfs directory, and execute the following command:

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf weixin.jpg

Among them, wenxin.jpg is the name of the picture previously stored in the storage directory of the machine.

Related execution commands and directories:

[root@2bc9f8268eda fdfs]# pwd
/var/fdfs
[root@2bc9f8268eda fdfs]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf weixin.jpg
group1/M00/00/00/rBEAA18X7ZWAfAPiAABrsFVlX6U142.jpg

At this point, the file has been uploaded successfully, and the path information of the file stored in storage will be returned.

Visit http://ip:8888/group1/M00/00/00/rBEAA18X7ZWAfAPiAABrsFVlX6U142.jpg via url to view the picture. Here ip is replaced with localhost or 127.0.0.1 interface.

The display effect is as follows:

image

In the next step, you can scan the picture, pay attention to my official account [Program New Vision], continue to update the dry goods content, there is always what you want.

In the next article, we will introduce how to integrate FastDFS through Spring Boot. It is also the last article on FastDFS.

Original link: " FastDFS based on Docker installation "


New Vision of Procedure

The public account " New Vision of Program ", a platform that allows you to simultaneously improve your soft power and hard technology

WeChat Official Account: New Vision of Program

Guess you like

Origin blog.csdn.net/wo541075754/article/details/107528318