Board logo

標題: [介紹] 在 CentOS 上使用 google-drive-ocamlfuse 掛載Google雲端硬碟 [打印本頁]

作者: dyson6    時間: 2017-5-17 14:07     標題: 在 CentOS 上使用 google-drive-ocamlfuse 掛載Google雲端硬碟

在Linux的環境中如果要使用到Google雲端硬碟中的資料,通常只能透過Google雲端硬碟網頁的版本,並不能像在Windows中可以下載Google雲端硬碟的應用程式,最近在使用CentOS,發現Google有為Linux推出google-drive-ocamlfuse,讓我們可以直接在系統上直接掛載Google雲端硬碟來進行資料的存取,但是由於安裝過程比較繁瑣,所以本篇就來帶大家進行安裝的過程。

1.安裝opam

因為是透過opam來安裝google-drive-ocamlfuse套件,所以要先把opam裝起來。opam有推出CentOS系列的版本,所以只要下載套件庫,就可以透過yum進行安裝。下面針對不同的發行版進行解說。

# yum install sqlite-devel fuse fuse-devel libcurl-devel zlib-devel m4
# yum install ocaml ocamldoc ocaml-camlp4-devel
# wget https://raw.github.com/ocaml/opam/master/shell/opam_installer.sh -O - | sh -s /usr/local/bin/

2.安裝google-drive-ocamlfuse

# opam init
# opam install google-drive-ocamlfuse
# opam list
# google-drive-ocamlfuse --help


3.存取 Google Drive API

Next, we’re going to enable API access to Google Drive and create a set of credentials. These steps require a web browser on your local computer, and access to the Google account with which your Drive is associated.

(a) Visit the Google API developer’s console on your desktop at
      https://console.developers.google.com/project

   [attach]12466[/attach]

(b) Create a project. Click Create Project, then give the project a name and click Create again:

    [attach]12467[/attach]

    Google will take a moment to create the project, and when it’s complete you’ll arrive at the dashboard:

    [attach]12468[/attach]

(c) Enable the Google Drive API. Click APIs & auth, then APIs when the menu expands. You’ll see a list like the one below. Click on Drive API:

    [attach]12469[/attach]

    If you don’t see the Drive API on the list as pictured, you may need to search for it. After you’ve selected it, click the blue Enable button at the top of the page.

    [attach]12470[/attach]

(d) Click Credentials in the menu on the left side of the page. Then click Add New Credential.

    [attach]12471[/attach]

    Click Configure consent screen. Google assumes you are writing a piece of software so it wants some information about it.
[attach]12472[/attach]

    The product name field is required, but you can leave everything else blank. Then click Save at the bottom of the page.

   [attach]12473[/attach]

    Now click Other for the application type. Google will ask for a name again - you may use the default or choose a name you’ll easily associate with this project. Then click Create.

[attach]12474[/attach]

    Click Credentials on the menu on the left side of the screen, and select your project from the list. You will now be able to view your Client ID and Client secret strings:
[attach]12475[/attach]

4. 授權 OCamlfuse 存取

Next, we’ll provide the credentials for your Drive API to OCamlfuse in your Linode, authorizing it to access your Google Drive.

(a) Authorize your Google Drive link, replacing client-ID and client-secret with those you received from the Google API Manager in the steps above:
引用:

# google-drive-ocamlfuse -headless -label backup -id client-ID -secret client-secret


    The output from this command will give you a long URL. Copy it and paste it for use in step 2:
引用:

    Please, open the following URL in a web browser: https://accounts.google.com/o/oauth2/auth?client_id=URL_SNIPPED
    Please enter the verification code:

    
(b) Google will ask for permission to allow this new application (OCamlfuse) to access your Google Drive. Click Accept to receive the verification code:
[attach]12476[/attach]

(c) Copy/paste the verification code back to OCamlfuse in your VPS.

5.設定掛載點
引用:

# mkdir -p /Data
# google-drive-ocamlfuse -label backup /Data

用以下指令即可卸載:
# fusermount -u /Data

6.設定開機自動掛載 google driver
首先在根目錄新增一個檔叫 gdfuse
引用:

#!/bin/bash
su root -l -c "google-drive-ocamlfuse -label backup /Data”
exit 0


然後變更權限
# chmod 700 /gdfuse

再加進去 rc.local

# vi /etc/rc.local

再最後面加上
引用:

# Auto Mount Google Driver
/gdfuse


這樣就可以囉~

參考資料:
https://www.linode.com/docs/applications/cloud-storage/access-google-drive-linode
https://www.lchick.idv.tw/?p=58






歡迎光臨 ADJ網路實驗室 (http://dz.adj.idv.tw/) Powered by Discuz! 6.0.0