こんにちは!社会人一年目?のタレカツです!
今回はローカル上に構築したS3互換APIを機能を提供するオブジェクトストレージとS3の同期をしてみました。ローカルには分散ストレージシステムであるCephを構築して、オブジェクトストレージインターフェースの機能である、Ceph object gatewayを使用してawsコマンドなども試しました。
今回は構築方法については触れませんが、以下のドキュメントを参考に構築しています。バージョンはUbuntu22.04を使用しています。
Ceph設定
Object Gateway用のユーザを作成
ユーザを以下のコマンドで作成します。アクセスキーとシークレットキーが作成されるので、記録しておきます。
root@ceph1:~# radosgw-admin user create --uid=tarekatsu --display-name="Tarekatsu"
{
"user_id": "tarekatsu",
"display_name": "Tarekatsu",
"email": "",
"suspended": 0,
"max_buckets": 1000,
"subusers": [],
"keys": [
{
"user": "tarekatsu",
"access_key": "CEPH_RGW_ACCESS_KEY",
"secret_key": "CEPH_RGW_SECRET_KEY"
}
],
"swift_keys": [],
"caps": [],
"op_mask": "read, write, delete",
"default_placement": "",
"default_storage_class": "",
"placement_tags": [],
"bucket_quota": {
"enabled": false,
"check_on_raw": false,
"max_size": -1,
"max_size_kb": 0,
"max_objects": -1
},
"user_quota": {
"enabled": false,
"check_on_raw": false,
"max_size": -1,
"max_size_kb": 0,
"max_objects": -1
},
"temp_url_keys": [],
"type": "rgw",
"mfa_ids": []
}
Object Gatewayに対してawsコマンドの実行
Cephが動いているubuntuでaws configureを実行して、先ほどのアクセス情報を入力します。この時regionに関してはaws上のS3ではないので、設定しなくて大丈夫です。
root@ceph1:~# aws configure --profile tarekatsu-rgw
AWS Access Key ID [None]: CEPH_RGW_ACCESS_KEY
AWS Secret Access Key [None]: CEPH_RGW_SECRET_KEY
Default region name [None]:
Default output format [None]:
バケットを作成しますが、この際にCEPH_RGW_ENDPOINTは動作しているIPアドレスと設定したポート番号を指定します。create-bucketをした後にバケットが、作成されたことがわかります。
root@ceph1:~# aws s3api create-bucket --endpoint-url=http://CEPH_RGW_ENDPOINT --profile tarekatsu-rgw --bucket tarekatsu-bucket
root@ceph1:~# aws s3 ls --endpoint-url=http://CEPH_RGW_ENDPOINT --profile tarekatsu-rgw
2025-10-06 11:55:57 tarekatsu-bucket
次にテキストファイルを作成して、アップロードをしました。以下のファイルアップロードを行いました。
root@ceph1:~# vi tarekatu-test.txt
root@ceph1:~# cat tarekatu-test.txt
Tarekatsu-test
root@ceph1:~# aws s3 cp --endpoint-url=http://CEPH_RGW_ENDPOINT --profile tarekatsu-rgw tarekatu-test.txt s3://tarekatsu-bucket/
upload: ./tarekatu-test.txt to s3://tarekatsu-bucket/tarekatu-test.txt
別から接続して確認するのと、GUI環境でも確認したかったので、別で動作しているWindowsにS3 browserをインストールして接続してみました。アクセスキーやIP、ポートは先ほどと同じです。
ダウンロードして確認したところ中身も先ほど作成したものと一致しました。
オープンソースのrcloneを使用したS3への同期
今回aws s3 syncコマンドを用いて同期しようと考えたのですが、一回のコマンドで二つのプロファイルを使用する方法がわからなかったので、rcloneというクラウドストレージのデータを管理するための、コマンドラインプログラムを使用して同期をやってみました。
rcloneのインストールと設定
パッケージマネージャを使用してインストールしましたが、古いバージョンでインストールことがあるため、ほかのインストール方法が推奨されていました。
root@ceph1:~# apt install rclone
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
rclone
0 upgraded, 1 newly installed, 0 to remove and 100 not upgraded.
Need to get 11.7 MB of archives.
After this operation, 42.6 MB of additional disk space will be used.
Get:1 http://jp.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 rclone amd64 1.53.3-4ubuntu1.22.04.3 [11.7 MB]
Fetched 11.7 MB in 11s (1,084 kB/s)
Selecting previously unselected package rclone.
(Reading database ... 77243 files and directories currently installed.)
Preparing to unpack .../rclone_1.53.3-4ubuntu1.22.04.3_amd64.deb ...
Unpacking rclone (1.53.3-4ubuntu1.22.04.3) ...
Setting up rclone (1.53.3-4ubuntu1.22.04.3) ...
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
以下のようにrcloneコマンドを使用して、CephとS3用の設定を登録します。長くなるので全部は張りませんが、設定を選択していきます。
root@ceph1:~# rclone config
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> Ceph
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 Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, Tencent COS, etc)
\ "s3"
5 / Backblaze B2
\ "b2"
6 / Box
\ "box"
7 / Cache a remote
\ "cache"
8 / Citrix Sharefile
\ "sharefile"
9 / Dropbox
\ "dropbox"
10 / Encrypt/Decrypt a remote
\ "crypt"
11 / FTP Connection
\ "ftp"
12 / Google Cloud Storage (this is not Google Drive)
\ "google cloud storage"
13 / Google Drive
\ "drive"
14 / Google Photos
\ "google photos"
最終的にcephとS3の設定がされるまで進めます。
root@ceph1:~# rclone config
Current remotes:
Name Type
==== ====
Ceph s3
S3 s3
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>
rcloneを用いたストレージ操作
それぞれ、rcloneを使ってアップロードされているファイルの確認を行いました。S3には登録した権限でアクセスできるS3を作成して、テスト用のファイルを上げています。
アップロードされたファイルの確認は以下で行いました。
root@ceph1:~# rclone ls Ceph:
15 tarekatsu-bucket/tarekatu-test.txt
root@ceph1:~# rclone ls S3:ceph-sync-bucket
30723 test/backup.png
最後にCephからS3へのファイルの同期を行いました。rclone syncコマンドでデータも正常に同期していることが確認できました。
rcloneの今回のオプションでは同期先のデータが削除されました。もし、元々あったデータを残したい場合は、rcloneの別バージョンを試すか、rclone copyコマンドにしてください。
root@ceph1:~# rclone sync Ceph:tarekatsu-bucket S3:ceph-sync-bucket --progress
Transferred: 15 / 15 Bytes, 100%, 78 Bytes/s, ETA 0s
Checks: 1 / 1, 100%
Deleted: 1
Transferred: 1 / 1, 100%
Elapsed time: 0.3s
おわりに
今回はコマンドを叩いて一時的に同期を行いましたが、ファイル操作などがあった際に継続的に同期する方法を試したいと思います。