Image Server SETUP tutorial and Server SETUP tutorial

Source: Internet
Author: User

Image Server SETUP tutorial and Server SETUP tutorial
1. install and configure FastDFS1, runtime environment and related software

CentOS 7.4 64bit fastdfs_v5.08.tar.gznginx-1.8.1.tar.gzfastdfs-nginx-module_v1.16.tar.gz libfastcommon
2. Server Planning
Server Name IP address and port Remarks
Fastdfs-tracker 172.17.156.5: 22122 Tracking Server/scheduling Server
Fastdfs-storage 172.17.156.5: 23000 Storage Server
3. Install FastDFS3.1. First create the tool directory (not required)
[root@fastdfs-storage ~]# mkdir -p /home/oldcat/tools[root@fastdfs-storage ~]# cd /home/oldcat/tools/
3.2 download and install the FastDFS dependency package libfastcommon.
[root@fastdfs-storage tools]# wget https://codeload.github.com/happyfish100/libfastcommon/zip/master[root@fastdfs-storage tools]# unzip master[root@fastdfs-storage tools]# cd libfastcommon-master/[root@fastdfs-storage libfastcommon-master]# lsHISTORY  INSTALL  libfastcommon.spec  make.sh  php-fastcommon  README  src[root@fastdfs-storage libfastcommon-master]# ./make.sh[root@fastdfs-storage libfastcommon-master]# ./make.sh install
Tip: if the following error is reported when the second sentence is executed, the error 3.3 is returned.
-bash: unzip: command not found

The command is not found because unzip is not installed.

The installation command is:

yum install -y unzip zip
3.3 download and install FastDFS
[root@fastdfs-tracker tools]# wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz[root@fastdfs-tracker tools]# tar xf FastDFS_v5.08.tar.gz[root@fastdfs-tracker tools]# cd FastDFS[root@fastdfs-tracker FastDFS]# ./make.sh && ./make.sh install

The following files and directories are installed by default:

-Service script:

[Root @ fastdfs-tracker ~] # Ll/etc/init. d/| grep fdfs-rwxr-xr-x. 1 root 918 April 22 22:08 fdfs_storaged-rwxr-xr-x. 1 root 920 April 22 22:08 fdfs_trackerd

Sample configuration file

[Root @ fastdfs-tracker ~] # Ll/etc/fdfs/total usage 20-rw-r -- r --. 1 root 1461 April 22 22:08 client. conf. sample-rw-r --. 1 root 7927 April 22 22:08 storage. conf. sample-rw-r --. 1 root 7200 April 22 22:08 tracker. conf. sample

Command line tool

[Root @ fastdfs-tracker ~] # Ll/usr/bin | grep fdfs-rwxr-xr-x. 1 root 252272 April 22 22:08 fdfs_appender_test-rwxr-xr-x. 1 root 252225 April 22 22:08 fdfs_appender_test1-rwxr-xr-x. 1 root 242449 April 22 22:08 fdfs_append_file-rwxr-xr-x. 1 root 242013 April 22 22:08 fdfs_crc32-rwxr-xr-x. 1 root 242508 April 22 22:08 fdfs_delete_file-rwxr-xr-x. 1 root 243627 April 22 22:08 fdfs_download_file-rwxr-xr-x. 1 root 243369 April 22 22:08 fdfs_file_info-rwxr-xr-x. 1 root 255657 April 22 22:08 fdfs_monitor-rwxr-xr-x. 1 root 863913 April 22 22:08 fdfs_storaged-rwxr-xr-x. 1 root 258712 April 22 22:08 fdfs_test-rwxr-xr-x. 1 root 257881 April 22 22:08 fdfs_test1-rwxr-xr-x. 1 root 365232 April 22 22:08 fdfs_trackerd-rwxr-xr-x. 1 root 243547 April 22 22:08 fdfs_upload_appender-rwxr-xr-x. 1 root 244453 April 22 22:08 fdfs_upload_file
Note: Although FastDFS distinguishes tracker and storage servers, the software and steps are the same, but they are only different configuration files, therefore, the above installation applies to tracker server and storage server4, configuration Tracking server (tracker server) 4.1 copy the tracker server and client sample configuration file and rename
[root@fastdfs-tracker ~]# cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf[root@fastdfs-storage ~]# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
4.2 edit the tracker server configuration file tracker. conf. You need to modify the content as follows:
Disabled = false (false by default, indicating whether it is invalid) port = 22122 (22122 by default) base_path =/data/fastdfs/tracker
4.3 edit the client configuration file client. conf as follows:
base_path=/data/fastdfs/trackertracker_server=172.17.156.5:22122
Enter the private IP address of your server.
Example: 192.168.25.htm
4.4 create a tracker server data directory
[root@fastdfs-tracker ~]# mkdir -p /data/fastdfs/tracker
4.5 Test and start trackerserver. After the trackerserver is started, the data and logs directories are automatically created in the/data/fastdfs/tracker directory.
[root@fastdfs-tracker ~]# cd /data/fastdfs/tracker/[root@fastdfs-tracker tracker]# ls[root@fastdfs-tracker tracker]# /etc/init.d/fdfs_trackerd startStarting FastDFS tracker server:[root@fastdfs-tracker tracker]# ss -lntup|grep 22122tcp    LISTEN     0      128                    *:22122                 *:*      users:(("fdfs_trackerd",3785,5)) [root@fastdfs-tracker tracker]# lsdata  logs
4.6 disable tracker server
[root@fastdfs-tracker tracker]# /etc/init.d/fdfs_trackerd stopwaiting for pid [3785] exit ...pid [3785] exit.
5. Configure the storage server 5.1 to copy the storage server sample configuration file and rename it
[root@fastdfs-storage ~]# cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
5.2 edit the storage. conf configuration file of the storage server. You need to modify the content as follows:
Disabled = false (false by default, indicating whether it is invalid) port = 23000 (23000 by default) base_path =/data/fastdfs/storagetracker_server = 172.17.156.5: 22122store_path0 =/data/fastdfs/storagehttp. server_port = 8888 (the default value is 8888. The listening port configured in nginx is the same)
Enter the private IP address of your server. If the virtual machine directly uses the following IP address, it must be consistent with the tracker server above.
Example: 192.168.25.htm
5.3 create a storage server data directory
[root@fastdfs-storage ~]# mkdir -p /data/fastdfs/storage
5.4 test the startup of the storage server. After the startup is successful, the data and logs directories are automatically created in the/data/fastdfs/tracker directory (the prerequisite for enabling the storage server is that the tracker server must be started beforehand)
[root@fastdfs-storage ~]# cd /data/fastdfs/storage/[root@fastdfs-storage storage]# ls[root@fastdfs-storage storage]# /etc/init.d/fdfs_storaged startStarting FastDFS storage server:[root@fastdfs-storage storage]# ss -lntup|grep 23000tcp    LISTEN     0      128                    *:23000                 *:*      users:(("fdfs_storaged",3786,5))[root@fastdfs-storage storage]# lsdata  logs
6. File Upload Test

Run the following upload command:

[Root @ fastdfs-tracker ~] # Mkdir/home/oldcat/imgs and then transfer an image to the server through sftp (renamed test. xxx );
[Root @ fastdfs-tracker ~] #/Usr/bin/fdfs_upload_file/etc/fdfs/client. conf/home/oldcat/imgs/test.jpg group1/M00/00/00/Hangzhou The returned File ID indicates that the file has been uploaded successfully.
2. install and configure nginx1 on the storage server, download and install the fastdfs-nginx-module

Note: FastDFS stores files on the Storage server through the Tracker server, but file replication is required between Storage servers in the same group. Synchronization latency may occur. Assume that the Tracker server uploads the file to 192.168.4.125. After the upload is successful, the file ID is returned to the client. At this time, the FastDFS storage cluster mechanism will synchronize this file to the same group of storage 192.168.4.126. If the file is not copied, if the client uses this file ID to retrieve the file on 192.168.4.126, the file cannot be accessed. Fastdfs-nginx-module can redirect files to the source server to fetch files, avoiding file access errors caused by Replication delay on the client.

[Root @ fastdfs-storage tools] # wget plugin tools] # tar xf fastdfs-nginx-module_v1.16.tar.gz [root @ fastdfs-storage tools] # cd fastdfs-nginx-module/src/[root @ fastdfs- storage src] # vim config edit the config file, run the following command to batch replace and save and exit: % s +/usr/local/+/usr/+ g
2. Copy the configuration file in fastdfs-nginx-module to the/etc/fdfs directory and edit it.
[Root @ fastdfs-storage ~] # Cp/home/oldcat/tools/fastdfs-nginx-module/src/mod_fastdfs.conf/etc/fdfs/[root @ fastdfs-storage ~] # Vim/etc/fdfs/mod_fastdfs.conf: connect_timeout = 10base_path =/tmp (/tmp by default) tracker_server = 172.17.156.5: 22122 (the ECS is a private IP address) storage_server_port = 23000 (default configuration: 23000) url_have_group_name = truestore_path0 =/data/fastdfs/storagegroup_name = group1 (default configuration: group1)
3. Install nginx dependent Libraries
[root@fastdfs-storage nginx-1.8.1]# yum install -y pcre-devel zlib-devel
4. Download and install nginx
[root@fastdfs-storage  tools]# wget http://nginx.org/download/nginx-1.8.1.tar.gz[root@fastdfs-storage tools]# tar xf nginx-1.8.1.tar.gz[root@fastdfs-storage tools]# cd nginx-1.8.1[root@fastdfs-storage nginx-1.8.1]# ./configure --prefix=/application/nginx/ --add-module=../fastdfs-nginx-module/src/[root@fastdfs-storage nginx-1.8.1]# make && make install
5. copy some configuration files in FastDFS to the/etc/fdfs directory.
[root@fastdfs-storage ~]# cp /home/oldcat/tools/FastDFS/conf/http.conf /etc/fdfs/[root@fastdfs-storage ~]# cp /home/oldcat/tools/FastDFS/conf/mime.types /etc/fdfs/
6. Configure nginx as follows:
[root@fastdfs-storage ~]# vim /application/nginx/conf/nginx.conf    user  root;        worker_processes  1;    events {       worker_connections  1024;    }    http {        include       mime.types;        default_type  application/octet-stream;        sendfile        on;        keepalive_timeout  65;        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;            }        }    }

Note:

-"User root" is used to solve the problem of 404 error during downloading.

-Port 8888 corresponds to http. server_port = 8888 in/etc/fdfs/storage. conf.

-If the storage pair should have multiple groups, the access path should contain the group name, for example,/group1/M00/00/00/**, corresponding to the nginx Configuration:

    location ~/group[0-9]/ {        ngx_fastdfs_module;    }
7. Copy the nginx service to the/etc/init. d/directory and start
[root@fastdfs-storage ~]# cp /application/nginx/sbin/nginx /etc/init.d/[root@fastdfs-storage ~]# /etc/init.d/nginx[root@fastdfs-storage ~]# ss -lntup|grep 8888tcp    LISTEN     0      128                    *:8888                  *:*      users:(("nginx",7308,6),("nginx",7309,6))
8. access previously uploaded files through a browser
For example, IP: 8888/group1/M00/00/00/rBGcBVqBZ_mAGl9oAAEfvSdB99w682.jpg

The browser can successfully access the uploaded image, indicating that the image server created with FastDFS has been successfully completed!

Note: If the IP address is a public IP address on the remote server, and the server needs to set the Security Group to open port 8888

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.