Fastdfs_5.08 + nginx_14.0 cluster deployment
- Server planning:
- 1, All tracker and storage nodes should execute:
- 2, Configure tracker server
- 3, Configure storage server
- 4, File upload test (ip01)
- 5, Install fastdfs nginx module on all storage nodes
- 6, Verify: access files uploaded during test through browser
- 7, Java API client configuration
- If there is any error, please point out in the comment area
Server planning:
Server IP | role |
---|---|
192.168.1.191 | Tracker Server,Storage Server |
192.168.1.192 | Tracker Server,Storage Server |
192.168.1.193 | Storage Server |
1, All tracker and storage nodes should execute:
1. Install dependency package
yum install make cmake gcc gcc-c++ unzip zip
2. Install libfatscommon
cd /usr/local/src && unzip libfastcommon-master.zip && cd libfastcommon-master ./make.sh && ./make.sh install
3. Install FastDFS
cd /usr/local/src && tar -xzvf FastDFS_v5.08.tar.gz cd FastDFS && ./make.sh && ./make.sh install
a check if the installation is successful
1) View startup script
/etc/init.d/fdfs_storaged /etc/init.d/fdfs_trackerd
2) Profile (sample profile):
ll /etc/fdfs/ -rw-r--r-- 1 root root 1461 1 April 14:34 client.conf.sample -rw-r--r-- 1 root root 7927 1 April 14:34 storage.conf.sample -rw-r--r-- 1 root root 7200 1 April 14:34 tracker.conf.sample
3) Command line tools (/ usr/bin /)
ll /usr/bin/fdfs_* -rwxr-xr-x 1 root root 260584 1 April 14:34 fdfs_appender_test -rwxr-xr-x 1 root root 260281 1 April 14:34 fdfs_appender_test1 -rwxr-xr-x 1 root root 250625 1 April 14:34 fdfs_append_file -rwxr-xr-x 1 root root 250045 1 April 14:34 fdfs_crc32 -rwxr-xr-x 1 root root 250708 1 April 14:34 fdfs_delete_file -rwxr-xr-x 1 root root 251515 1 April 14:34 fdfs_download_file -rwxr-xr-x 1 root root 251273 1 April 14:34 fdfs_file_info -rwxr-xr-x 1 root root 266401 1 April 14:34 fdfs_monitor -rwxr-xr-x 1 root root 873233 1 April 14:34 fdfs_storaged -rwxr-xr-x 1 root root 266952 1 April 14:34 fdfs_test -rwxr-xr-x 1 root root 266153 1 April 14:34 fdfs_test1 -rwxr-xr-x 1 root root 371336 1 April 14:34 fdfs_trackerd -rwxr-xr-x 1 root root 251651 1 April 14:34 fdfs_upload_appender -rwxr-xr-x 1 root root 252781 1 April 14:34 fdfs_upload_file
2, Configure tracker server
1. Copy the tracker sample configuration file and rename it
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
2. Modifying the tracker profile
vim /etc/fdfs/tracker.conf
#The revised contents are as follows:
disabled=false enable profile Port = 22122 ා tracker server port (default 22122) base_path=/fastdfs/tracker - the root directory where logs and data are stored store_group=group1 The default configuration is reserved for other parameters. Please refer to the official document for details: http://bbs.chinaunix.net/thread-1941456-1-1.html
3. Create base_path specified directory
mkdir -p /fastdfs/tracker
4. Open the tracker server port in the firewall (22122 by default)
vi /etc/sysconfig/iptables Add: if there is no iptables file in / etc/sysconfig directory, you can write an iptables command to configure a firewall rule as follows: iptables -P OUTPUT ACCEPT Then save it with the command: service iptables save, which is saved to the / etc/sysconfig/iptables file by default. This file now exists. The firewall can also be started. Next, to write the policy, you can also write it directly in / etc/sysconfig/iptables. Add the following port line: -A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT service iptables restart service iptables restart
5. Start the tracker server
/etc/init.d/fdfs_trackerd start At initial startup, logs and data directories will be generated in / fastdfs/tracker directory. Drwx R-X 2 root 4096 January 4 15:00 data Drwx R-X 2 root 4096 January 4 14:38 logs Check if FastDFS Tracker Server started successfully: ps -ef | grep fdfs_trackerd
3, Configure storage server
1. Copy the storage sample configuration file and rename it
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
2. Edit profile
vi /etc/fdfs/storage.conf
#The revised contents are as follows:
disabled=false # Enable profile port=23000 # storage service port base_path=/fastdfs/storage # Data and log file storage root store_path0=/fastdfs/storage # First storage directory tracker_server=192.168.1.191:22122 # tracker server IP and port tracker_server=192.168.1.192:22122 #tracker server IP2 and port [microsoft1] http.server_port=8888 # http port to access files //The default configuration is reserved for other parameters. For specific configuration explanation, please refer to the official document description: http://bbs.chinaunix.net/thread-1941456-1-1.htmlvi /etc/fdfs/storage.conf
3. Create basic data directory
mkdir -p /fastdfs/storage
4. Open the storage server port in the firewall (23000 by default)
vi /etc/sysconfig/iptables #Add the following port line: -A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT //service iptables restart service iptables restart
Note: in cluster environment
Operation steps 1, 2 and 3 of tracking + storage node
If the storage node is only used for storage, then it is only used for operation step 3. See the installation of its own requirements
5. Start storage server
/etc/init.d/fdfs_storaged start //Initial start-up, at/fastdfs/storage Generate under directory logs,dataTwo directories. drwxr-xr-x 259 root root 4096 Mar 31 06:22 data drwxr-xr-x 2 root root 4096 Mar 31 06:22 logs //Check if FastDFS Tracker Server started successfully: [root@gyl-test-t9 ~]# ps -ef | grep fdfs_storaged root 1336 1 3 06:22 ? 00:00:01 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf root 1347 369 0 06:23 pts/0 00:00:00 grep fdfs_storaged
4, File upload test (ip01)
1. Modify Tracker server client profile
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf vim /etc/fdfs/client.conf
#Modify the following configuration, others remain default
base_path=/fastdfs/tracker tracker_ Server = 192.168.1.191: 22122 - tracker server IP and port tracker_ Server = 192.168.1.292: 22122 - tracker server IP2 and port 2. Execute file upload command #/usr/local/src/test.png It is required to upload the file path /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/test.png Return file ID No.: group1/M00/00/00/tlxkwlhttsGAU2ZXAAC07quU0oE095.png (the above file ID can be returned, indicating that the file has been uploaded successfully)
5, Install fastdfs nginx module on all storage nodes
1. Function description of fastdfs nginx module
FastDFS stores files in the Storage server through the Tracker server, but the same group of Storage servers need to enter the file replication, so there is a problem of synchronization delay. Suppose the Tracker server uploads the file to ip01, and the file ID has been returned to the client after the upload is successful. At this time, the FastDFS Storage cluster mechanism will synchronize this file to the same group Storage ip02. If the file has not been replicated, if the client uses this file ID to retrieve the file on ip02, the file will be inaccessible. FastDFS nginx module can redirect files to connect to the source server to retrieve files, so as to avoid the inaccessible errors caused by the client's replication delay. (the extracted FastDFS nginx module is used during nginx installation)
2. Decompress fastdfs nginx module_ v1.16. tar.gz
cd /usr/local/src && tar -xzvf fastdfs-nginx-module_v1.16.tar.gz
3. Modify the config configuration file of fastdfs nginx module
cd fastdfs-nginx-module/src vim config //take CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/" //Amend to read: CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
4. Install dependency packages required to compile Nginx
yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
5. Compile and install Nginx (add fastdfs Nginx module)
#No directory to create cd /usr/local/src && wget http://nginx.org/download/nginx-1.14.0.tar.gz tar -zxvf nginx-1.14.0.tar.gz && cd nginx-1.14.0 ./configure --prefix=/usr/local/nginx --pid-path=/var/local/nginx/nginx.pid \ --lock-path=/var/lock/nginx/nginx.lock --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi \ --add-module=/usr/local/src/fastdfs-nginx-module/src/ make && make install
6. Copy the configuration file in the fastdfs nginx module source code to the / etc/fdfs directory, and modify it
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ vi /etc/fdfs/mod_fastdfs.conf //Modify the following configuration: connect_timeout=10 base_path=/tmp tracker_server=192.168.1.191:22122 # tracker server IP and port tracker_server=192.168.1.192:22122 #tracker server IP2 and port url_have_group_name=true #The url contains the group name #Add [group1] at the end group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/fastdfs/storage
7. Copy part of FastDFS configuration file to / etc/fdfs directory
cp /usr/local/src/FastDFS/conf/* /etc/fdfs/ ( http.conf mime.types These two files can be copied directly.)
8. Create a soft connection in the / fastdfs/storage file storage directory and link it to the directory where the data is actually stored
ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
9. Configure Nginx
user nobody; 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 192.168.1.191; location ~/group1/M00 { #If there are multiple groups, you can write location ~/group[0-9]/M00 root /fastdfs/storage/data/; ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } upstream storage_server_group1{ server 192.168.1.191:8888 weight=10; server 192.168.1.192:8888 weight=10; server 192.168.1.193:8888 weight=10; } }
A. The 8888 port value is to be consistent with / etc/fdfs/storage.conf In http.server_port=8888, because http.server_port is 8888 by default. If you want to change it to 80, you need to modify it accordingly.
B. When Storage has multiple groups, the access path has a group name, such as / group1/M00/00/00/xxx. The corresponding Nginx configuration is:
location ~/group([0-9])/M00 { ngx_fastdfs_module; }
C. If the old newspaper 404 is found during the download, the nginx.conf In the first line, change user nobody to user root and restart.
11. Open port 8888 of Nginx in firewall
Copy code vi /etc/sysconfig/iptables //add to: -A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT #service iptables restart service iptables restart //Start nginx: /opt/nginx/sbin/nginx (restart Nginx The command of is:/opt/nginx/sbin/nginx -s reload)
6, Verify: access files uploaded during test through browser
Switch tracking server IP can also be accessed
http://192.100.139.121:8888/group1/M00/00/00/CmSKtFj13gyAen4oAAH0yXi-HW8296.png
http://192.100.139.122:8888/group1/M00/00/00/CmSKtFj13gyAen4oAAH0yXi-HW8296.png
7, Java API client configuration
1. Go to GitHub to download Java_client code. https://github.com/fzmeng/fastdfs.client
2. Add the file fastdfs to your project src/java/resources_ client.conf
Pay attention to modifying the Ip address of tracker server
Copy code
connect_timeout = 2 network_timeout = 30 charset = ISO8859-1 http.tracker_http_port = 8888 http.anti_steal_token = no tracker_server=192.192.168.1.195:22122 tracker_server=192.168.1.240:22122 default_group_name=group1