如何创建 s3ql 文件系统并在启动时自动挂载?
我一直在 Ubuntu 10.04 上尝试 s3ql,用它来挂载 Amazon S3 存储桶。但是,我真的希望它能够自动安装它们。有谁知道该怎么做?
解决方案:
感谢 s3ql 的 Nikratio 的帮助,我终于能够在系统启动时自动挂载S3存储桶。您肯定会想查看手册,但以下是如何操作的基础知识去做吧!
第一步是创建 authinfo 文件。该文件应放置在将使用该文件的用户的主目录中的 .s3ql 目录中。 authinfo 文件包含登录信息,允许 s3ql 在没有提示的情况下挂载存储桶。以下是 authinfo 文件的示例。第一行包含您的 Amazon 安全凭证。第二个包含您的存储桶的位置和密码。如果需要,您可以向此文件添加多个存储桶行,但我在本示例中仅使用一个。此时,存储桶密码可以是任何内容。
backend s3 machine any login ASDFGHJKL password ZXCVBNM
storage-url s3://mybucket password mypassword
存储桶名称必须是唯一的。没有两个用户可以拥有相同的存储桶名称,因此最好登录 Amazon Web Services 并尝试不同的名称,直到找到可用的名称。一旦找到一个,您需要将其删除,因为 s3ql 在创建 s3ql 文件系统时会重新创建它。如果存储桶已存在,您将收到错误消息。
要创建文件系统,请使用以下命令:
mkfs.s3ql s3://mybucket
它将提示您输入加密密码。这应该与 authinfo 文件中的存储桶密码相同。
现在您的文件系统已创建,您可以使用以下命令挂载它:
mount.s3ql s3://mybucket /mnt/s3/bucket
当然,您的存储桶名称和挂载点会有所不同。
现在,如果我们想在启动时自动挂载这个存储桶,我们需要在 /etc/init.d 中添加一个 upstart 脚本。幸运的是,s3ql 附带了一个 s3ql.conf。
我在 mount.s3ql 命令中添加了“--allow-other”,以允许除 root 之外的用户访问已安装的存储桶。
#
# This file can be placed in /etc/init. It defines an upstart job that
# takes care of mounting and unmounting an S3QL file system.
#
description "S3QL Backup File System"
author "Nikolaus Rath <[email protected]>"
start on (filesystem and net-device-up IFACE=eth0)
stop on runlevel [016]
env BUCKET="s3://mybucket"
env MOUNTPOINT="/mnt/s3/bucket"
expect stop
script
# Redirect stdout and stderr into the system log
DIR=$(mktemp -d)
mkfifo "$DIR/LOG_FIFO"
logger -t s3ql -p local0.info < "$DIR/LOG_FIFO" &
exec > "$DIR/LOG_FIFO"
exec 2>&1
rm -rf "$DIR"
# Check and mount file system
fsck.s3ql --batch "$BUCKET"
exec mount.s3ql --upstart --allow-other "$BUCKET" "$MOUNTPOINT"
end script
pre-stop script
umount.s3ql "$MOUNTPOINT"
end script
添加此脚本后,理论上您应该能够重新启动并自动安装您的存储桶,但这是我遇到的麻烦。我的没有安装。
我的问题是由于 upstart 以 root 身份运行脚本,但我以另一个用户身份创建了文件系统。当我将 .s3ql 目录从我登录的用户的主目录复制到 /root 后,问题就解决了。
我希望这对其他人有帮助。尽管我使用已安装的 S3 铲斗的时间不长,但我对最初测试的结果印象深刻。
另外,这个答案是在找到解决方案大约一周后写的。我想我已经涵盖了所有内容,但如果您发现我遗漏了某个步骤,请告诉我,我会添加它。您还需要阅读手册,如果您打算的话,它确实值得一读使用s3ql。
I've been experimenting with s3ql on Ubuntu 10.04, using it to mount Amazon S3 buckets. However, I'd really like it to mount them automatically. Does anyone know how to do that?
Solution:
Thanks to help from Nikratio of s3ql I'm finally able to mount S3 buckets automatically when the system boots. You'll definitely want to look at the manual, but here's the basics of how to do it!
The first step is to create an authinfo file. This file should be placed in a .s3ql directory within the home directory of the user who will be using it. The authinfo file contains login info allowing s3ql to mount buckets without prompting. Below is an example of what your authinfo file should look like. The first line contains your Amazon Security Credentials. The second contains the location and password for your bucket. You can add multiple bucket-lines to this file if needed, but I'm only using one in this example. At this point, the bucket password can be anything.
backend s3 machine any login ASDFGHJKL password ZXCVBNM
storage-url s3://mybucket password mypassword
The bucket name has to be unique. No two users can have the same bucket name, so its a good idea to log into Amazon Web Services and try different names until you find one that's available. Once you've found one, you'll need to delete it, since s3ql will re-create it when it creates your s3ql filesystem. If the bucket already exists, you'll receive an error.
To create the file system, use the command:
mkfs.s3ql s3://mybucket
It will prompt you for your encryption password. This should be the same as the bucket password in the authinfo file.
Now that your file system is created, you can mount it using the command:
mount.s3ql s3://mybucket /mnt/s3/bucket
Of course, your bucket name and mount point will vary.
Now, if we want to mount this bucket automatically on boot, we need to add an upstart script to /etc/init. Fortunately, s3ql comes packaged with one, s3ql.conf.
I added "--allow-other" to the mount.s3ql command to allow users other than root to access the mounted bucket.
#
# This file can be placed in /etc/init. It defines an upstart job that
# takes care of mounting and unmounting an S3QL file system.
#
description "S3QL Backup File System"
author "Nikolaus Rath <[email protected]>"
start on (filesystem and net-device-up IFACE=eth0)
stop on runlevel [016]
env BUCKET="s3://mybucket"
env MOUNTPOINT="/mnt/s3/bucket"
expect stop
script
# Redirect stdout and stderr into the system log
DIR=$(mktemp -d)
mkfifo "$DIR/LOG_FIFO"
logger -t s3ql -p local0.info < "$DIR/LOG_FIFO" &
exec > "$DIR/LOG_FIFO"
exec 2>&1
rm -rf "$DIR"
# Check and mount file system
fsck.s3ql --batch "$BUCKET"
exec mount.s3ql --upstart --allow-other "$BUCKET" "$MOUNTPOINT"
end script
pre-stop script
umount.s3ql "$MOUNTPOINT"
end script
After adding this script, in theory you should be able to reboot and have your bucket automatically mounted, but this is were I ran into trouble. Mine wasn't being mounted.
My problem was caused by the fact that upstart was running the script as root, but I'd created the file system as another user. Once I copied the .s3ql directory from the home directory of the user I'd been logged-in as to /root, the problem was solved.
I hope this helps someone else out there. Although I haven't been using my mounted S3 bucket for long, I'm impressed with how my initial tests have gone.
Also, this answer was written about a week after the solution was found. I think I've covered everything, but if you find I've missed a step, let me know and I'll add it. You'll also want to read the manual, its really worth reading if you intend to use s3ql.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Nikratio 的帮助下,我终于能够在启动时自动安装我的 S3 存储桶。我已经用解决方案更新了我的问题。
With some help from Nikratio, I'm finally able to mount my S3 bucket automatically on boot. I've updated my question with the solution.