日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

centos nfs java_CentOS下安装配置NFS并通过Java进行文件上传下载

發布時間:2024/9/19 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 centos nfs java_CentOS下安装配置NFS并通过Java进行文件上传下载 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1:安裝NFS

(1)安裝

yum install nfs-utils rpcbind

(2)啟動rpcbind服務

systemctl restart rpcbind.service

查看服務狀態

systemctl status rpcbind.service

查看rpc

lsof -i :111

netstat -lntup|grep rpcbind

(3)啟動NFS服務

systemctl start nfs.service

查看狀態

systemctl status nfs.service

查看rpc注冊的端口信息

rpcinfo -p localhost

(4)啟動順序一定是rpcbind->nfs,否則有可能出現錯誤

systemctl start rpcbind.service

systemctl enable rpcbind.service

systemctl start nfs.service

systemctl enable nfs.service

(5)配置端口

nfs除了主程序端口2049和rpcbind的端口111是固定以外,還會使用一些隨機端口,以下配置將定義這些端口,以便配置防火墻。

MOUNTD_PORT=4001

STATD_PORT=4002

LOCKD_TCPPORT=4003

LOCKD_UDPPORT=4003

RQUOTAD_PORT=4004

(6)配置

/home/wzh/nfs??? 192.168.0.0/24(rw,sync,insecure,no_root_squash)

/home/wzh/nfs??? 192.168.3.0/24(rw,sync,insecure,no_root_squash)

exportfs -r  #重載exports配置

exportfs -v  #查看共享參數

2:Windows10系統下面掛載測試

C:\Users\yan>mount \\192.168.0.XXX\home\wzh\nfs\ x:

x: 現已成功連接到 \\192.168.0.XXX\home\wzh\nfs\

命令已成功完成。

C:\Users\yan>

3:解決客戶端無法寫入的問題

[wzh@centos-oracle ~]$ chmod 777 nfs/

4:通過Java進行文件上傳下載

(1)工具包

commons-lang-2.6.jar

netty-3.2.8.Final.jar

nfs-client-1.0.3.jar

slf4j-api-1.7.25.jar

(2)NfsUtil.java

package com.test;

import com.emc.ecs.nfsclient.nfs.NfsCreateMode;

import com.emc.ecs.nfsclient.nfs.NfsSetAttributes;

import com.emc.ecs.nfsclient.nfs.io.Nfs3File;

import com.emc.ecs.nfsclient.nfs.io.NfsFileInputStream;

import com.emc.ecs.nfsclient.nfs.io.NfsFileOutputStream;

import com.emc.ecs.nfsclient.nfs.nfs3.Nfs3;

import com.emc.ecs.nfsclient.rpc.CredentialUnix;

import java.io.BufferedInputStream;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.util.logging.Level;

import java.util.logging.Logger;

/**

* @作者 y

* @版本 V1.0

* @描述 NFS工具類

*/

public class NfsUtil {

private static final String NFS_IP = "192.168.0.XXX";

private static final String NFS_DIR = "/home/wzh/nfs";

/**

* 上傳文件到NFS服務器

* @param path NFS 存儲的相對路徑

* @param fileName 文件名稱包括文件后綴

* @param content 文件二進制內容

* @return

*/

public static boolean upload(String path, String fileName, byte []content){

NfsFileOutputStream outputStream = null;

NfsSetAttributes nfsSetAttr = new NfsSetAttributes();

nfsSetAttr.setMode((long) (0x00100 + 0x00080 + 0x00040 + 0x00020 + 0x00010 + 0x00008 + 0x00004 + 0x00002));

try {

Nfs3 nfs3 = new Nfs3(NFS_IP, NFS_DIR, new CredentialUnix(-2, -2, null), 3);

String paths[] = path.substring(1).split("/");//去掉第一個/之后進行分割處理

StringBuilder p = new StringBuilder();

//首先判斷目錄是否存在,如果不存在則進行創建目錄

for(String s:paths){

p.append("/").append(s);

Nfs3File filePath = new Nfs3File(nfs3, p.toString());

if (!filePath.exists()) {

filePath.mkdir(nfsSetAttr);

}

}

//創建文件

Nfs3File desFile = new Nfs3File(nfs3, path+"/"+fileName);

desFile.create(NfsCreateMode.GUARDED, nfsSetAttr, null);

outputStream = new NfsFileOutputStream(desFile);

outputStream.write(content);

return true;

} catch (IOException ex) {

Logger.getLogger(NfsUtil.class.getName()).log(Level.SEVERE, null, ex);

} finally{

if(null!=outputStream){

try {

outputStream.close();

} catch (IOException ex) {

Logger.getLogger(NfsUtil.class.getName()).log(Level.SEVERE, null, ex);

}

}

}

return false;

}

/**

* 文件下載

* @param filePath NFS上面的文件路徑信息

* @return

*/

public static byte[] download(String filePath){

ByteArrayOutputStream bos = null;

NfsFileInputStream inputStream = null;

BufferedInputStream bis = null;

try {

Nfs3 nfs3 = new Nfs3(NFS_IP, NFS_DIR, new CredentialUnix(-2, -2, null), 3);

Nfs3File file = new Nfs3File(nfs3, filePath);

inputStream = new NfsFileInputStream(file);

bis = new BufferedInputStream(inputStream);

bos = new ByteArrayOutputStream();

int date = -1;

while ((date = bis.read()) != -1) {

bos.write(date);

}

return bos.toByteArray();

} catch (IOException ex) {

Logger.getLogger(NfsUtil.class.getName()).log(Level.SEVERE, null, ex);

} finally{

if(null!=bos){

try {

bos.close();

} catch (IOException ex) {

Logger.getLogger(NfsUtil.class.getName()).log(Level.SEVERE, null, ex);

}

}

if(null!=bis){

try {

bis.close();

} catch (IOException ex) {

Logger.getLogger(NfsUtil.class.getName()).log(Level.SEVERE, null, ex);

}

}

if(null!=inputStream){

try {

inputStream.close();

} catch (IOException ex) {

Logger.getLogger(NfsUtil.class.getName()).log(Level.SEVERE, null, ex);

}

}

}

return null;

}

}

(3)測試類FileTest.java

package com.test;

import java.io.BufferedOutputStream;

import java.io.ByteArrayOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStream;

import java.util.logging.Level;

import java.util.logging.Logger;

/**

* @作者 y

* @版本 V1.0

* @描述

*/

public class FileTest {

public static void main(String[] args) {

String fileName = "wszm.pdf";

int hashcode = fileName.hashCode();

int dir1 = hashcode & 0xf; //0--15

int dir2 = (hashcode & 0xf0) >> 4; //0-15

String path = "/" + dir1 + "/" + dir2;

byte []file = fileToBytes("G:\\tmp\\wszm.pdf");

boolean flag = NfsUtil.upload(path, fileName, file);

System.out.println("flag:"+flag);

for(int i=0;i<3;i++){

byte []buff = NfsUtil.download("/t01/t001/tt/ssptbin20180613.7z");

bytesToFile(buff,"G:\\tmp\\ssptbin20180613"+i+".7z");

}

}

public static void bytesToFile(byte[] buffer, final String filePath){

File file = new File(filePath);

OutputStream output = null;

BufferedOutputStream bufferedOutput = null;

try {

output = new FileOutputStream(file);

bufferedOutput = new BufferedOutputStream(output);

bufferedOutput.write(buffer);

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} finally{

if(null!=bufferedOutput){

try {

bufferedOutput.close();

} catch (IOException e) {

e.printStackTrace();

}

}

if(null != output){

try {

output.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

public static byte[] fileToBytes(String filePath) {

byte[] buffer = null;

File file = new File(filePath);

FileInputStream fis = null;

ByteArrayOutputStream bos = null;

try {

fis = new FileInputStream(file);

bos = new ByteArrayOutputStream();

byte[] b = new byte[1024];

int n;

while ((n = fis.read(b)) != -1) {

bos.write(b, 0, n);

}

buffer = bos.toByteArray();

} catch (FileNotFoundException ex) {

Logger.getLogger(FileTest.class.getName()).log(Level.SEVERE, null, ex);

} catch (IOException ex) {

Logger.getLogger(FileTest.class.getName()).log(Level.SEVERE, null, ex);

} finally {

try {

if (null != bos) {

bos.close();

}

} catch (IOException ex) {

Logger.getLogger(FileTest.class.getName()).log(Level.SEVERE, null, ex);

} finally{

try {

if(null!=fis){

fis.close();

}

} catch (IOException ex) {

Logger.getLogger(FileTest.class.getName()).log(Level.SEVERE, null, ex);

}

}

}

return buffer;

}

}

java實現文件上傳下載

喜歡的朋友可以關注下,粉絲也缺. 今天發現已經有很久沒有給大家分享一篇技術文章了,于是想了一下給大家分享一篇java實現文件上傳下載功能的文章,不喜歡的希望大家勿噴. 想必大家都知道文件的上傳前端頁面 ...

java&plus;大文件上傳下載

文件上傳下載,與傳統的方式不同,這里能夠上傳和下載10G以上的文件.而且支持斷點續傳. 通常情況下,我們在網站上面下載的時候都是單個文件下載,但是在實際的業務場景中,我們經常會遇到客戶需要批量下載的場 ...

java web 文件上傳下載

文件上傳下載案例: 首先是此案例工程的目錄結構:

FasfDFS整合Java實現文件上傳下載功能實例詳解

https://www.jb51.net/article/120675.htm 在上篇文章給大家介紹了FastDFS安裝和配置整合Nginx-1.13.3的方法,大家可以點擊查看下. 今天使用Java ...

FasfDFS整合Java實現文件上傳下載

文章目錄 ????一 : 添加配置文件 ????二 : 加載配置文件 ????????1. 測試加載配置文件 ????????2. 輸出配置文件 ????三:功能實現 ????????1.初始化連接信 ...

Java web文件上傳下載

[版權申明:本文系作者原創,轉載請注明出處] 文章出處:http://blog.csdn.net/sdksdk0/article/details/52048666 作者:朱培 ID:sdksdk0 郵 ...

fastDFS與java整合文件上傳下載

準備 下載fastdfs-client-java源碼 源碼地址 密碼:s3sw 修改pom.xml 第一個plugins是必需要的,是maven用來編譯的插件,第二個是maven打源碼包的,可以不要. ...

java 實現文件上傳下載以及查看

項目的目錄結構 代碼 ?IOUtils.java package cn.edu.zyt.util; import java.io.IOException; import java.io.InputSt ...

Jsch - java SFTP 文件上傳下載

使用Jsch上傳.下載文件,核心步驟是:獲取channel,然后使用get/put方法下載.上傳文件 核心代碼句: session = jSch.getSession(ftpUserName, ftp ...

隨機推薦

SQL Server 2012 聯機叢書離線安裝

昨日根據微軟官網的方式安裝SQL Server 2012 聯機叢書報錯,無法安裝: 聯機叢書下載位置及安裝方式: 按照給出的方式安裝,無法完成,錯誤如下:

從Paxos到ZooKeeper-二、ZooKeeper和Paxos

ZooKeeper為分布式應用提供了高效且可靠的分布式協調服務,提供了諸如tong'yi統一命名服務.配置管理和分布式鎖等分布式的基礎服務.在解決分布式數據一致性方面,ZooKeeper并沒有直接采用 ...

HDU 4858 項目管理 分塊

題目鏈接: http://acm.hdu.edu.cn/showproblem.php?pid=4858 題解: 下面說一個插入查詢時間復雜度為sqrt(m)的算法: 對每個點定義兩個值:val,su ...

The 2015 China Collegiate Programming Contest D&period;Pick The Sticks hdu 5543

Pick The Sticks Time Limit: 15000/10000 MS (Java/Others)????Memory Limit: 65535/65535 K (Java/Others ...

運用加密技術保護Java源代碼&sol;定制ClassLoader

為什么要加密? 對于傳統的C或C++之類的語言來說,要在Web上保護源代碼是很容易的,只要不發布它就可以.遺憾的是,Java程序的源代碼很容易被別人偷看.只要有一個反編譯器,任何人都可以分析別人的代碼 ...

Unity3D ShaderLab 各向異性高光

Unity3D?ShaderLab?各向異性高光 各向異性時一種模擬物體表面溝槽方向性的高光反射類型,它會修改或延伸垂直方向上的高光.當我們想模擬金屬拉絲高光的時候,它非常適合.下面就一步一步實現. ...

整理的一些免費的Android項目實戰系列視頻教程

http://blog.itpub.net/29737144/viewspace-1212539/

&lpar;轉帖&rpar;BootStrap入門教程 &lpar;三&rpar;

上講回顧:Bootstrap的基礎CSS(Base CSS)提供了優雅,一致的多種基礎Html頁面要素,包括排版,表格,表單,按鈕等,能夠滿足前端工程師的基本要素需求. Bootstrap作為完整 ...

關于High-Resolution Timer&lpar;了解&rpar;

如果一個系統包含高精度性能計數器(HRPC,high-resolution performance counter)則此系統提供高精度定時器.你可以使用API函數QueryPerformanceFre ...

wpa&lowbar;supplicant 移植及 linux 命令行模式配置無線上網

本文涉及內容為linux 命令行模式配置無線上網 及 wpa_supplicant 移植到開發板的過程,僅供參考. 1.源碼下載 wpa_supplicant 源碼下載地址 :http://hosta ...

總結

以上是生活随笔為你收集整理的centos nfs java_CentOS下安装配置NFS并通过Java进行文件上传下载的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。