当前位置:   article > 正文

将阿里云盘挂载为Webdav并使用rclone挂载到本地_rclone挂载webdav为本地磁盘

rclone挂载webdav为本地磁盘

准备工作

获取refreshToken

1.https://media.cooluc.com/decode_token/在此网页进行获取,但是我在搭建的时候报错,如果报错可以使用第二种方法

2.https://www.aliyundrive.com/sign/ 登录网页版 按f12打开控制台—application—local storage—token,即可查看refresh token

安装webdav工具
编译安装

确保你的服务器 拥有jdk和maven如果没有进行安装

yum list java*
yum install java-1.8.0-openjdk.x86_64      #上一条指令会搜索包含java的软件列表,挑选最新的下载几个
yum install maven
  • 1
  • 2

下载源代码

https://github.com/zxbu/webdav-aliyundriver.git

    编译代码

    cd webdav-aliyundriver
    # 编译
    mvn clean package -Dmaven.test.skip=true
    #编译之后的文件在target文件夹,webdav*.jar
    cd target
    mv webdav*.jar webdav.jar
    • 1
    • 2
    • 3
    • 4
    • 5

    运行程序

    java -jar webdav.jar --aliyundrive.refresh-token="your refreshToken"
    
    • 1

    参数说明

    --aliyundrive.refresh-token
        阿里云盘的refreshToken,获取方式见下文
    --server.port
        非必填,服务器端口号,默认为8080
    --aliyundrive.auth.enable=true
        是否开启WebDav账户验证,默认开启
    --aliyundrive.auth.user-name=admin
        WebDav账户,默认admin
    --aliyundrive.auth.password=admin
        WebDav密码,默认admin
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    如果你不想自行编译使用的话 我会将编译好的jar上传到我的网盘 https://tools.southcat.net 届时您自行下载直接运行程序即可。

    Docker运行

    docker配置方便,并且会自动开机自启,相对于编译使用个人更推荐使用docker.

    docker安装

    yum install docker

      容器运行

      docker run -d --name=webdav-aliyundriver --restart=always -p 8080:8080  -v /etc/localtime:/etc/localtime -v /etc/aliyun-driver/:/etc/aliyun-driver/ -e TZ="Asia/Shanghai" -e ALIYUNDRIVE_REFRESH_TOKEN="your refreshToken" -e ALIYUNDRIVE_AUTH_PASSWORD="admin" -e JAVA_OPTS="-Xmx1g" zx5253/webdav-aliyundriver
      
      • 1

      参数说明和上面编译运行的是一样的.

      安装Rclone进行挂载

      安装rclone

      curl https://rclone.org/install.sh | sudo bash

        配置rclone

        rclone config
          [root@localhost yum.repos.d]# rclone config
          2021/08/12 16:28:35 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
          No remotes found - make a new one
          n) New remote
          s) Set configuration password
          q) Quit config
          n/s/q> n
          name> aliyunwebdav
          Type of storage to configure.
          Enter a string value. Press Enter for the default ("").
          Choose a number from below, or type in your own value
           1 / 1Fichier
             \ "fichier"
           2 / Alias for an existing remote
             \ "alias"
           3 / Amazon Drive
             \ "amazon cloud drive"
           4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, SeaweedFS, and Tencent COS
             \ "s3"
           5 / Backblaze B2
             \ "b2"
           6 / Box
             \ "box"
           7 / Cache a remote
             \ "cache"
           8 / Citrix Sharefile
             \ "sharefile"
           9 / Compress a remote
             \ "compress"
          10 / Dropbox
             \ "dropbox"
          11 / Encrypt/Decrypt a remote
             \ "crypt"
          12 / Enterprise File Fabric
             \ "filefabric"
          13 / FTP Connection
             \ "ftp"
          14 / Google Cloud Storage (this is not Google Drive)
             \ "google cloud storage"
          15 / Google Drive
             \ "drive"
          16 / Google Photos
             \ "google photos"
          17 / Hadoop distributed file system
             \ "hdfs"
          18 / Hubic
             \ "hubic"
          19 / In memory object storage system.
             \ "memory"
          20 / Jottacloud
             \ "jottacloud"
          21 / Koofr
             \ "koofr"
          22 / Local Disk
             \ "local"
          23 / Mail.ru Cloud
             \ "mailru"
          24 / Mega
             \ "mega"
          25 / Microsoft Azure Blob Storage
             \ "azureblob"
          26 / Microsoft OneDrive
             \ "onedrive"
          27 / OpenDrive
             \ "opendrive"
          28 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
             \ "swift"
          29 / Pcloud
             \ "pcloud"
          30 / Put.io
             \ "putio"
          31 / QingCloud Object Storage
             \ "qingstor"
          32 / SSH/SFTP Connection
             \ "sftp"
          33 / Sugarsync
             \ "sugarsync"
          34 / Tardigrade Decentralized Cloud Storage
             \ "tardigrade"
          35 / Transparently chunk/split large files
             \ "chunker"
          36 / Union merges the contents of several upstream fs
             \ "union"
          37 / Uptobox
             \ "uptobox"
          38 / Webdav
             \ "webdav"
          39 / Yandex Disk
             \ "yandex"
          40 / Zoho
             \ "zoho"
          41 / http Connection
             \ "http"
          42 / premiumize.me
             \ "premiumizeme"
          43 / seafile
             \ "seafile"
          Storage> 38
          URL of http host to connect to
          Enter a string value. Press Enter for the default ("").
          Choose a number from below, or type in your own value
           1 / Connect to example.com
             \ "https://example.com"
          url> http://127.0.0.1:8080
          Name of the Webdav site/service/software you are using
          Enter a string value. Press Enter for the default ("").
          Choose a number from below, or type in your own value
           1 / Nextcloud
             \ "nextcloud"
           2 / Owncloud
             \ "owncloud"
           3 / Sharepoint Online, authenticated by Microsoft account.
             \ "sharepoint"
           4 / Sharepoint with NTLM authentication. Usually self-hosted or on-premises.
             \ "sharepoint-ntlm"
           5 / Other site/service or software
             \ "other"
          vendor> 5
          User name. In case NTLM authentication is used, the username should be in the format 'Domain\User'.
          Enter a string value. Press Enter for the default ("").
          user> admin
          Password.
          y) Yes type in my own password
          g) Generate random password
          n) No leave this optional password blank (default)
          y/g/n> y
          Enter the password:
          password:
          Confirm the password:
          password:
          Bearer token instead of user/pass (e.g. a Macaroon)
          Enter a string value. Press Enter for the default ("").
          bearer_token> 
          Edit advanced config?
          y) Yes
          n) No (default)
          y/n> 
          --------------------
          [aliyunwebdav]
          type = webdav
          url = http://127.0.0.1:8080
          vendor = other
          user = admin
          pass = *** ENCRYPTED ***
          --------------------
          y) Yes this is OK (default)
          e) Edit this remote
          d) Delete this remote
          y/e/d> 
          Current remotes:
          
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7
          • 8
          • 9
          • 10
          • 11
          • 12
          • 13
          • 14
          • 15
          • 16
          • 17
          • 18
          • 19
          • 20
          • 21
          • 22
          • 23
          • 24
          • 25
          • 26
          • 27
          • 28
          • 29
          • 30
          • 31
          • 32
          • 33
          • 34
          • 35
          • 36
          • 37
          • 38
          • 39
          • 40
          • 41
          • 42
          • 43
          • 44
          • 45
          • 46
          • 47
          • 48
          • 49
          • 50
          • 51
          • 52
          • 53
          • 54
          • 55
          • 56
          • 57
          • 58
          • 59
          • 60
          • 61
          • 62
          • 63
          • 64
          • 65
          • 66
          • 67
          • 68
          • 69
          • 70
          • 71
          • 72
          • 73
          • 74
          • 75
          • 76
          • 77
          • 78
          • 79
          • 80
          • 81
          • 82
          • 83
          • 84
          • 85
          • 86
          • 87
          • 88
          • 89
          • 90
          • 91
          • 92
          • 93
          • 94
          • 95
          • 96
          • 97
          • 98
          • 99
          • 100
          • 101
          • 102
          • 103
          • 104
          • 105
          • 106
          • 107
          • 108
          • 109
          • 110
          • 111
          • 112
          • 113
          • 114
          • 115
          • 116
          • 117
          • 118
          • 119
          • 120
          • 121
          • 122
          • 123
          • 124
          • 125
          • 126
          • 127
          • 128
          • 129
          • 130
          • 131
          • 132
          • 133
          • 134
          • 135
          • 136
          • 137
          • 138
          • 139
          • 140
          • 141
          • 142
          • 143
          • 144
          • 145
          • 146
          • 147
          • 148
          • 149
          • 150

          Name Type
          ==== ====
          aliyunwebdav webdav

          e) Edit existing remote
          n) New remote
          d) Delete remote
          r) Rename remote
          c) Copy remote
          s) Set configuration password
          q) Quit config
          e/n/d/r/c/s/q> q

          [alert size="0" icon="" type="default"]

          name请自行替换
          密码需要输入两遍进行确认,建议上面运行webdav程序的时候不设置密码,这里就不需要进行设置,直接选择无密码选项

          [/alert]
          挂载到本地
          #新建本地文件夹,位置可以自己选
          mkdir /data/aliyunwebdav
          #挂载
          rclone mount DriveName:Folder LocalFolder --cache-dir /tmp --allow-other --vfs-cache-mode writes --allow-non-empty
          
          • 1
          • 2
          • 3
          • 4
          [alert size="0" icon="" type="default"]

          DriverName是你在配置rclone的时候设置的名字,Folder没有需要求的话填/即可,LocalFolder是你本地挂载的地址,/tmp比较特殊,上传时缓存目录,其他类型挂载一般时不需要这个参数的,默认/tmp地址即可,除非你的系统特殊

          [/alert]

          执行完之后即可访问本地挂载的文件夹查看文件了.

          设置开机自启
          #将后面修改成你上面手动运行命令中,除了rclone的全部参数
          command="mount DriveName:Folder LocalFolder --cache-dir /tmp --allow-other --vfs-cache-mode writes --allow-non-empty"
          #以下是一整条命令,一起复制到SSH客户端运行
          cat > /etc/systemd/system/rclone.service <<EOF
          [Unit]
          Description=Rclone
          After=network-online.target
          
          [Service]
          Type=simple
          ExecStart=$(command -v rclone) ${command}
          Restart=on-abort
          User=root
          
          [Install]
          WantedBy=default.target
          EOF
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7
          • 8
          • 9
          • 10
          • 11
          • 12
          • 13
          • 14
          • 15
          • 16

          开始启动:

          systemctl start rclone
          
          • 1

          设置开机自启:

          systemctl enable rclone
          
          • 1

          其他命令:

          重启:systemctl restart rclone
          停止:systemctl stop rclone
          状态:systemctl status rclone
          • 1
          • 2

          声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/188492
          推荐阅读
          相关标签
            

          闽ICP备14008679号