×
Community Blog Hướng Dẫn Dùng Câu Lệnh S3 Browser Kết Nối Với Alibaba Cloud Edge Object Service (EOS)

Hướng Dẫn Dùng Câu Lệnh S3 Browser Kết Nối Với Alibaba Cloud Edge Object Service (EOS)

Bài viết này hướng dẫn cách dùng câu lệnh S3 Browser kết nối với Alibaba Cloud Edge Object Service (EOS)

By Dang Minh Tam, Alibaba Cloud Solutions Architect of Vietnam


S3 Browser là một công cụ miễn phí được phát triển trên nền Windows và cung cấp khả năng kết nối làm việc đến Amazon S3 và các đơn vị lưu trữ hỗ trợ S3 Compatibility. Bạn có thể tải phần mềm S3 Browser ở trang https://s3browser.com/ . Khi bạn cài đặt phần mềm S3 Browser sẽ có cả công cụ đồ hoạ (GUI) và công cụ dòng lệnh. Trong bài này, tôi sẽ hướng dẫn các bạn dùng công cụ dòng lệnh kết nối S3 Browser với Alibaba Cloud EOS.

Các bạn có thể tham khảo bài hướng dẫn sử dụng công cụ S3 Browser đồ hoạ (GUI) tại đây https://www.alibabacloud.com/blog/600446

Yêu cầu bài lab:

  • Bucket được tạo trên Alibaba Cloud Edge Object Service (EOS)
  • Máy trạm có cài đặt sẵn S3 Browser.

Các bước triển khai:
1) Tạo bucket EOS trên Alibaba Cloud console và cấp quyền truy cập. Các bạn tham khảo ở bài viết trước của tôi https://www.alibabacloud.com/blog/600337
Screen_Shot_2023_10_27_at_14_08_29

2) Cài đặt S3 Browser trên maý trạm thì các bạn cứ giữ nguyên các lựa chọn mặc định, nhấn nút Next và hoàn tất tiến trình. Sau khi cài đặt xong, các bạn sẽ có công cụ dòng lệnh ở s3browser-cli.exe ở C:Program FilesS3 Browser
Screen_Shot_2023_10_27_at_14_09_08

Các bạn gọi lệnh s3browser-cli.exe trong Windows Command Line

> cd “%ProgramFiles%\S3 Browser”
> s3browser-cli.exe

Screen_Shot_2023_10_27_at_14_14_33

3) Khai báo kết nối S3 Brower tới EOS bằng đối tượng Account. Các câu lệnh theo sau Account bao gồm: add, update, show, delete, update-credential.

Lệnh /account add của s3browser-cli bao gồm các biến sau:

/account add name type [properties]

name – tên bạn muốn đặt cho account

type - loại S3 bucket mà bạn đang sử dụng. Chúng ta có danh sách dưới đây:

  • 0: Amazon S3
  • 1: Amazon S3 Compatible Storage
  • 2: Amazon S3 in China
  • 3: Amazon S3 GovCloud
  • 33: Amazon S3 GovCloud (FIPS 140-2)
  • 4: Amazon S3 via EC2 IAM Role
  • 44: Amazon S3 via AssumeRole
  • 45: Amazon S3 via GetSessionToken
  • 46: Amazon S3 via SSO
  • 5: Amazon S3 (Credentials from Environment Variables)
  • 6: Amazon S3 (Credentials from AWS Config or Credential file)

properties – các thuộc tính cần cho mỗi loại bucket:

  • Amazon S3, Amazon S3 in China, Amazon S3 GovCloud, Amazon S3 GovCloud (FIPS 140-2):

    • access-key-id
    • secret-access-key
  • Amazon S3 Compatible Storage:

    • rest-endpoint
    • access-key-id
    • secret-access-key
    • signature-version
    • addressing-model
  • Amazon S3 dùng EC2 IAM Role, Amazon S3 (Credentials from Environment Variables):

    • Không cần khai báo thuộc tính
  • Amazon S3 dùng AssumeRole:

    • role-arn
    • [external-id]
    • source-account
  • Amazon S3 (Credentials từ AWS Config hoặc Credential file):

    • credentials-file
    • credentials-file-profile
  • Amazon S3 dùng SSO:

    • sso-start-url
    • sso-region
    • sso-account-id
    • sso-role-name
  • Amazon S3 dùng GetSessionToken:

    • source-account

Nếu bạn không nhập các tham số thuộc tính thì s3browser sẽ tự chọn thuộc tính phù hợp nhất.

Trong trường hợp dùng s3browser-cli kết nối đến Alibaba Cloud EOS thuộc loại Amazon S3-Compatible, chúng ta sẽ cần bộ thông số thuộc tính để khai báo theo cú pháp dưới đây:

/account add name 1 rest-endpoint access-key-id secret-access-key signature-version addressing-model
  • Display name: ở đây tôi đặt là ‘EOS-HN’
  • Account type: EOS là S3 Compatible Storage nên sẽ nhập là 1
  • REST Endpoint: eos.aliyuncs.com
  • Access Key ID: các bạn cần khai báo trước đó
  • Secret Access Key: các bạn cần khai báo trước đó
  • (các bạn có thể tham khảo bài viết này để biết cách tạo key https://www.alibabacloud.com/blog/600337)
  • Signature version: 2 hoặc 4. EOS là Signature V4 nên sẽ nhập là 4
  • Addressing model: 0 là Path style và 1 là Virtual hosted style . EOS là Virtual hosted style nên sẽ nhập là 1
> s3browser-cli.exe /account add EOS-HN 1 eos.aliyuncs.com SAMPLEACCESSKEY SAMPLESECRETKEY 4 1

Screen_Shot_2023_10_27_at_15_12_53

Liệt kê các thuộc tính EOS bạn đang kết nối:

> s3browser-cli.exe /account show EOS-HN 

Screen_Shot_2023_10_27_at_15_14_29

Update thuộc tính của EOS

> s3browser-cli.exe /account update EOS-HN enable-ssl true
> s3browser-cli.exe /account show EOS-HN

Screen_Shot_2023_10_27_at_15_16_37
Các bạn có thể tham khảo các lệnh khác của s3browser-cli tại đây https://s3browser.com/s3cmd.aspx

3) Thao tác với dữ liệu và EOS bucket bằng đối tượng File. Các câu lệnh theo sau File bao gồm: upload, download, delete, list, sync, copy, move.

Để liệt kê các bucket trong EOS chúng ta dùng lệnh list

> s3browser-cli.exe /file list EOS-HN

Screen_Shot_2023_10_27_at_15_19_30

Để liệt kê các file và folder trong bucket trong EOS chúng ta dùng lệnh list và tên bucket

> s3browser-cli.exe /file list EOS-HN ali-hn
> s3browser-cli.exe /file list EOS-HN ali-hn/test-folder

Screen_Shot_2023_10_27_at_15_20_33

Để đưa dữ liệu lên EOS ta dùng lệnh upload:

> s3browser-cli.exe /file upload EOS-HN c:\Windows\iis.log ali-hn

Screen_Shot_2023_10_27_at_15_21_27

Để lấy dữ liệu từ EOS về máy ta dùng lệnh download:

> s3browser-cli.exe /file download EOS-HN c:\Windows\iis.log ali-hn/test-folder c:\downloads

Screen_Shot_2023_10_27_at_15_22_24

> s3browser-cli.exe /file download EOS-HN ali-hn/test-folder/* c:\downloads

Screen_Shot_2023_10_27_at_15_23_11

Một lưu ý nữa là s3browser-cli không có lệnh tạo thư mục trên EOS. Các bạn sẽ tạo thư mục bằng cách upload 1 file từ máy tính lên 1 thư mục chưa có trên EOS bucket để hệ thống tự tạo thư mục.

> s3browser-cli.exe /file upload EOS-HN c:\Windows\iis.log ali-hn/history
> s3browser-cli.exe /file list EOS-HN ali-hn

Screen_Shot_2023_10_27_at_15_24_33

Để đồng bộ dữ liệu từ thư mục trên máy lên EOS bucket ta dùng lệnh sync.

> s3browser-cli.exe /file sync EOS-HN c:\inetpub\history s3:ali-hn/history ncdhs
  • ncd: upload các file mới (new), có thay đổi (changed) và đã bị xoá (deleted)
  • h: sử dụng hash để so sánh file ở 2 nơi
  • s: sync mà không hiện bảng yêu cầu xác nhận

Screen_Shot_2023_10_27_at_15_27_06

Đồng bộ dữ liệu từ EOS bucket về thư mục trên máy

> s3browser-cli.exe /file sync EOS-HN s3:ali-hn/logs c:\download\logs ncdhs

Screen_Shot_2023_10_27_at_15_28_20
Screen_Shot_2023_10_27_at_15_28_50

Các bạn có thể tham khảo các lệnh khác của s3browser-cli tại đây https://s3browser.com/s3cmd.aspx

4) Kết hợp với Task Schedular trên Windows để đồng bộ dữ liệu định kỳ lên EOS bucket

Mở Task Schedular: Trong khung tìm kiếm nhập taskschd.msc để mở Windows Task Schedular
Screen_Shot_2023_10_27_at_15_29_50

Cấu hình theo các bước dưới đây

  • Menu Action > Create Task …
    Screen_Shot_2023_10_27_at_15_31_13
  • Tab General: Name: EOS-HN
    Screen_Shot_2023_10_27_at_15_35_12
  • Tab Trigger:

    • Begin the task: on a schedule
    • Daily
    • Recur every: 1 days
    • Repeat task every: 1 hour
    • Stop task if it runs longer than 1 hour
    • Enabled

Screen_Shot_2023_10_27_at_15_38_04

  • Tab Actions:

    • Action: Start a program
    • Program/script: Browse… "C:Program FilesS3 Browsers3browser-cli.exe"
    • Add arguments (optional) /file sync EOS-HN c:inetpubhistory s3:ali-hn/history ncdhs
  • Click OK to finish

Screen_Shot_2023_10_27_at_15_39_41

  • The result:
    Screen_Shot_2023_10_27_at_15_40_32
0 0 0
Share on

Alibaba Cloud Vietnam

46 posts | 5 followers

You may also like

Comments