在Linux VPS上实现挂载Google Drive只映射不同步

本教程将帮你实现在Linux VPS上挂载Google Drive只映射不同步。这样不会占用本地磁盘,也可以高效的利用远程Google Drive。实现效果如下图。

googledrivemount

首先我们需要一个KVM的VPS。OpenVZ虚拟化的VPS是肯定不行的。这里推荐用DigitalOcean。

系统用Debian 7 64 bit

apt-get update
apt-get dist-upgrade

更新系统至最新

[email protected]:~# uname -a
Linux GoogleDrive 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux
[email protected]:~# cat /etc/issue
Debian GNU/Linux 7 \n \l
[email protected]:~#

安装如下packages

apt-get install ocamapt-get install ocaml
apt-get install ocaml-findlib
apt-get install sqlite3
apt-get install camlidl
apt-get install m4 libcurl4-gnutls-dev libfuse-dev libsqlite3-dev
apt-get install camlp4-extra
apt-get install fuse
apt-get install build-essential sudo ssh make gitl

安装opam

git clone https://github.com/OCamlPro/opam
cd opam
./configure && make && make install

Build Successful in 76.86s. 840 jobs (parallelism 1.8x), 1124 files generated.
make[1]: Leaving directory `/root/opam'
mkdir -p /usr/local/bin
make opam-install opam-admin-install opam-installer-install
make[1]: Entering directory `/root/opam'
install _obuild/opam/opam.asm
install _obuild/opam-admin/opam-admin.asm
install _obuild/opam-installer/opam-installer.asm
make[1]: Leaving directory `/root/opam'
mkdir -p /usr/local/share/man/man1 && cp doc/man/* /usr/local/share/man/man1
[email protected]:~/opam# opam init
default    Downloading https://opam.ocaml.org/urls.txt
default    Downloading https://opam.ocaml.org/index.tar.gz
Updating ~/.opam/repo/compiler-index ...
Updating ~/.opam/compilers/ ...
Updating ~/.opam/repo/package-index ...
Updating ~/.opam/packages/ ...
Creating a cache of metadata in ~/.opam/state.cache ...
...
Do you want OPAM to modify ~/.bashrc and ~/.ocamlinit?
(default is 'no', use 'f' to name a file other than ~/.bashrc)
    [N/y/f] {type enter}
...
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

1. To configure OPAM in the current shell session, you need to run:

      eval `opam config env`

2. To correctly configure OPAM for subsequent use, add the following
line to your profile file (for instance ~/.bashrc):

      . /root/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true

3. To avoid issues related to non-system installations of `ocamlfind`
  add the following lines to ~/.ocamlinit (create it if necessary):

      let () =
        try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
        with Not_found -> ()
      ;;

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

安装google-drive-ocamlfuse

[email protected]:~/opam# opam update
default    Downloading https://opam.ocaml.org/urls.txt
Downloading https://opam.ocaml.org/repo
Updating ~/.opam/repo/compiler-index ...
Updating ~/.opam/compilers/ ...
Updating ~/.opam/repo/package-index ...
Updating ~/.opam/packages/ ...
Updating the cache of metadata (~/.opam/state.cache) ...
[email protected]:~/opam#

 

[email protected]:~/opam# opam install google-drive-ocamlfuse
The following actions will be performed:
 - install   ocamlfind.1.4.0                       [required by google-drive-ocamlfuse]
 - install   cppo.0.9.3                            [required by yojson]
 - install   camlidl.1.05                          [required by google-drive-ocamlfuse]
 - install   xmlm.1.1.1                            [required by gapi-ocaml]
 - install   sqlite3-ocaml.2.0.5                   [required by google-drive-ocamlfuse]
 - install   ocurl.0.7.0                           [required by gapi-ocaml]
 - install   extlib.1.6.1                          [required by gapi-ocaml]
 - install   easy-format.1.0.2                     [required by yojson]
 - install   cryptokit.1.9                         [required by gapi-ocaml]
 - install   ocamlfuse.2.7.1-cvs2                  [required by google-drive-ocamlfuse]
 - install   biniou.1.0.9                          [required by yojson]
 - install   ocamlnet.3.7.3                        [required by gapi-ocaml]
 - install   yojson.1.1.8                          [required by gapi-ocaml]
 - install   gapi-ocaml.0.2.1                      [required by google-drive-ocamlfuse]
 - install   google-drive-ocamlfuse.0.5.3
15 to install | 0 to reinstall | 0 to upgrade | 0 to downgrade | 0 to remove
Do you want to continue ? [Y/n] {type enter}

1.trouble shooting:

=-=-= Synchronizing package archives =-=-=
[ERROR] Actions cancelled because of # opam-version    1.1.1 (71b2a01ee571507c1819fbd282b0500d628f92d3)
# os              linux
opam: "fork" failed: Cannot allocate memory
Fatal error:
# opam-version    1.1.1 (71b2a01ee571507c1819fbd282b0500d628f92d3)
# os              linux
opam: "fork" failed: Cannot allocate memory
[email protected]:~/opam#

You need to add some swap to be able to run this installation.

当你看到如下的时候就说明已经开始下载编译和安装了

=-=-= Synchronizing package archives =-=-=
default    Downloading https://opam.ocaml.org/archives/biniou.1.0.9+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/cppo.0.9.3+opam.tar.gz
Downloading https://opam.ocaml.org/archives/cppo.0.9.3+opam.tar.gz
Downloading https://opam.ocaml.org/archives/biniou.1.0.9+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/camlidl.1.05+opam.tar.gz
Downloading https://opam.ocaml.org/archives/camlidl.1.05+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/cryptokit.1.9+opam.tar.gz
Downloading https://opam.ocaml.org/archives/cryptokit.1.9+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/easy-format.1.0.2+opam.tar.gz
Downloading https://opam.ocaml.org/archives/easy-format.1.0.2+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/extlib.1.6.1+opam.tar.gz
Downloading https://opam.ocaml.org/archives/extlib.1.6.1+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/gapi-ocaml.0.2.1+opam.tar.gz
Downloading https://opam.ocaml.org/archives/gapi-ocaml.0.2.1+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/google-drive-ocamlfuse.0.5.3+opam.tar.gz
Downloading https://opam.ocaml.org/archives/google-drive-ocamlfuse.0.5.3+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/ocamlfind.1.4.0+opam.tar.gz
Downloading https://opam.ocaml.org/archives/ocamlfind.1.4.0+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/ocamlfuse.2.7.1-cvs2+opam.tar.gz
Downloading https://opam.ocaml.org/archives/ocamlfuse.2.7.1-cvs2+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/ocamlnet.3.7.3+opam.tar.gz
Downloading https://opam.ocaml.org/archives/ocamlnet.3.7.3+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/ocurl.0.7.0+opam.tar.gz
Downloading https://opam.ocaml.org/archives/ocurl.0.7.0+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/sqlite3-ocaml.2.0.5+opam.tar.gz
Downloading https://opam.ocaml.org/archives/sqlite3-ocaml.2.0.5+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/xmlm.1.1.1+opam.tar.gz
Downloading https://opam.ocaml.org/archives/xmlm.1.1.1+opam.tar.gz
default    Downloading https://opam.ocaml.org/archives/yojson.1.1.8+opam.tar.gz
Downloading https://opam.ocaml.org/archives/yojson.1.1.8+opam.tar.gz

这里会卡一段时间,正常的

=-=-= Installing ocamlnet.3.7.3 =-=-=

进入Google Project建立一个Project

https://console.developers.google.com/project

googleproject

进入项目的API设置开启Drive API

googledriveenabledriveapi

 

建立一个OAuth验证ID

google_project_credentials_oauth

建立项目的Client ID

google_project_create_client_ID

 

记录下这两个生成的参数做稍后使用

google_project_client_id_native_application

进入/root/.opam/system/bin/目录绑定项目

cd /root/.opam/system/bin/
./google-drive-ocamlfuse -headless -label googledrive -id ##Client ID##.apps.googleusercontent.com -secret ##secret key##

执行完上述指令会返回一个https的网址在浏览器粘贴到浏览器后会进入google页面询问是否允许访问该项目,选accept然后记录下浏览器页面返回的密码

google_drive_accept

例如:

[email protected]:~/.opam/system/bin# ./google-drive-ocamlfuse -headless -label googledrive -id 123123231.apps.googleusercontent.com -secret ASDASDASDASQWE!@#
Please, open the following URL in a web browser: https://accounts.google.com/o/oauth2/auth?client_id=123123231.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&access_type=offline&approval_prompt=force
Please enter the verification code:[input here]
Access token retrieved correctly.
[email protected]:~/.opam/system/bin#

进入~/.gdfuse/googledrive

cd ~/.gdfuse/googledrive
nano config

编辑config修改内容例如

verification_code= [key returned from browser]

client_id= [eg. 123123231.apps.googleusercontent.com]

client_secret= [eg. ASDQWEWGSD!$@#@#ASD]

完成配置加载Google Drive远端存储到本地/googledrive

mkdir /googledrive
cd ~/.opam/system/bin
./google-drive-ocamlfuse -label googledrive /googledrive

 

[email protected]:/googledrive# df -h
Filesystem                 Size  Used Avail Use% Mounted on
rootfs                      20G  5.7G   14G  31% /
udev                        10M     0   10M   0% /dev
tmpfs                       50M  124K   50M   1% /run
/dev/disk/by-label/DOROOT   20G  5.7G   14G  31% /
tmpfs                      5.0M     0  5.0M   0% /run/lock
tmpfs                      100M     0  100M   0% /run/shm
google-drive-ocamlfuse      15G  6.2G  8.9G  42% /googledrive
[email protected]:/googledrive#

 

[email protected]:/googledrive# dd if=/dev/zero of=/googledrive/1 bs=1024 count=1k
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 6.05313 s, 173 kB/s
[email protected]:/googledrive#

 

Reference:

http://opam.ocaml.org/doc/Quick_Install.html

https://github.com/astrada/google-drive-ocamlfuse

https://github.com/ocaml/opam/releases

http://ocaml.org/docs/install.html

https://github.com/astrada/google-drive-ocamlfuse/wiki/How-to-install-from-source-on-Debian-Jessie

https://github.com/astrada/google-drive-ocamlfuse/wiki/Installation

https://console.developers.google.com/project

https://github.com/astrada/google-drive-ocamlfuse/wiki/Authorization

https://github.com/astrada/google-drive-ocamlfuse/wiki/Headless-Usage-%26-Authorization

http://ubuntuforums.org/showthread.php?t=148359

https://github.com/astrada/google-drive-ocamlfuse

 

 

分享到:

make a comment

(opt)