1 installation Tracker
Note: When editing the configuration file, write the IP address to the external IP address of the server. An error message will be displayed if you write 127.0.0.1
# yum install gcc-C ++ # yum install Yum -y install libfastcommon CD /usr/localwget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz tar - ZXVF V1.0.43. Tar. Gz. / make. Sh. / make. Sh Install a installation package # tracker CD/usr/local wget tar ZXVF - https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz V6.06.tar.gz CD fastdfs-6.06/./make. Sh./make /usr/bin/fdfs_trackerd /etc/ fdfs.tracker. conf /usr/bin/fdfs_trackerd startCopy the code
2 install Storage
Storage also depends on libevent and libfastcommon. If Tracker is installed on the same machine, the Storage has been installed
After the configuration is complete, start /usr/bin/fdfs_storaged /etc/ffs/storage.confCopy the code
3 to install Nginx
Nginx can be an important partner of FasfDFS
The procedure is divided into two steps
- Install nginx
- First install fasfdfs-nginx-module under Storage
- Install nginx
CD/usr/local wget http://nginx.org/download/nginx-1.17.0.tat.gz tar - ZXVF nginx - 1.17.0. Tat. Gz yum - y install pcre - devel # yum -y install openssl openssl-devel # yum -y install openssl-devel # yum -y install openssl-devel # yum -y install openssl-devel # yum -y install openssl-devel # Default location at/usr/local/nginx/CD/usr/local/sbin/nginx nginx/sbin nginx. # start/nginx # if modify the configuration file, you can through the following command to reload. / nginx - s reloadCopy the code
- Install fastdfs – nginx – module
# CD/usr/local wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz tar - ZXVF V1.22. Tar. Gz /usr/local/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /usr/local/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf CD /fastdfs-nginx-module-1.22/ SRC/cp mod_fastdfs.conf /etc/fdfs # Go to the nginx decompress directory CD /usr/local/nginx-1.17.0 /configure --add-module=/usr/local/fastdfs-nginx-module-1.22/ SRC make make install # / usr/local/nginx/conf/nginx. Conf # modified to reboot or after the completion of loading nginx. / nginx - s reloadCopy the code
4 Java client Test
- Create a Maven project to introduce dependencies into the POM
<dependency> <groupId>net.oschina.zcx7878</groupId> <artifactId>fastdfs-client-java</artifactId> The < version > 1.27.0.0 < / version > < / dependency >Copy the code
- Create a new FastdFS profile under Resources
fastdfs.connect_timeout_in_seconds=5
fastdfs.network_timeout_in_seconds=30
fastdfs.charset=UTF-8
fastdfs.http_anti_steal_token=false
fastdfs.http_secret_key=FastDFS1234567890
fastdfs.http_tracker_http_port=80
fastdfs.tracker_servers=IP:PORT
fastdfs.connection_pool.enabled=true
fastdfs.connection_pool.max_count_per_entry=500
fastdfs.connection_pool.max_idle_time=3600
fastdfs.connection_pool.max_wait_time_in_ms=1000
Copy the code
- Write upload test cases
Note: org.csource.com NameValuePair mon. NameValuePair, the log is lombok plugin, use @ Slf4j notes in class
@Test public void testUpload() { try { ClientGlobal.initByProperties("fastdfs-client.properties"); TrackerClient tracker = new TrackerClient(); TrackerServer trackerServer = tracker.getConnection(); StorageServer storageServer = null; StorageClient1 client = new StorageClient1(trackerServer, storageServer); NameValuePair[] nvp = null; / / upload file system String count = client. Upload_file1 ("/Users/markcwg/Pictures/background9. JPG ", "JPG", NVP); log.info(fileId); } catch (Exception e) { e.printStackTrace(); 16:02:41}} / / test result. The 099 [main] INFO com. Study. Springbootdemo. FastDfsTest - group1/M00/00/00/ecSfkGEM7KGAJwAHABGW7rUy8jQ119.jpgCopy the code
- Write a download case
@Test public void testDownload() { try { ClientGlobal.initByProperties("fastdfs-client.properties"); TrackerClient tracker = new TrackerClient(); TrackerServer trackerServer = tracker.getConnection(); StorageServer storageServer = null; StorageClient1 client = new StorageClient1(trackerServer, storageServer); byte[] bytes = client.download_file1("group1/M00/00/00/ecSfkGEM7KGAJwAHABGW7rUy8jQ119.jpg"); FileOutputStream fos = new FileOutputStream(new File("/Users/markcwg/Desktop/666.jpg")); fos.write(bytes); fos.close(); } catch (Exception e) { e.printStackTrace(); }}Copy the code
\