一、环境准备
1.有访问对象存储权限的AKSK
2.服务器、对象存储
二、实施步骤
sudo apt update
sudo apt install s3fs
echo "AK:SK" >/home/ubuntu/.passwd-s3fs ---位置自定义
chmod 600 /home/ubuntu/.passwd-s3fs ---权限必须要有
mkdir /data
sudo s3fs yyy1 /data -o passwd_file=/home/ubuntu/.passwd-s3fs -o url=http://s3.cn-northwest-1.amazonaws.com.cn -o allow_other -o endpoint=cn-northwest-1
allow_other --其他用户也能看到 如只想让root看或者挂载用户看就不加
vi /usr/local/bin/mount-s3.sh
准备启动脚本
#!/bin/bash
# 定义变量
BUCKET_NAME="yyy1"
MOUNT_POINT="/data"
PASSWD_FILE="/home/ubuntu/.passwd-s3fs"
REGION="cn-northwest-1"
URL="http://s3.cn-northwest-1.amazonaws.com.cn"
# 检查挂载点是否存在,不存在则创建
if [ ! -d "$MOUNT_POINT" ]; then
mkdir -p "$MOUNT_POINT"
fi
# 尝试挂载S3存储桶
s3fs "$BUCKET_NAME" "$MOUNT_POINT" -o passwd_file="$PASSWD_FILE" -o url="$URL" -o allow_other -o endpoint="$REGION"
# 检查挂载是否成功
if mount | grep -q "s3fs on $MOUNT_POINT"; then
echo "S3 bucket $BUCKET_NAME mounted successfully on $MOUNT_POINT"
else
echo "Failed to mount S3 bucket $BUCKET_NAME on $MOUNT_POINT"
exit 1
fi
sudo chmod +x /usr/local/bin/mount-s3.sh
加权限
vi /etc/systemd/system/mount-s3.service
[Unit]
Description=Mount S3 bucket on /data
After=network.target
Requires=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/mount-s3.sh
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
sudo systemctl enable mount-s3.service
sudo systemctl start mount-s3.service
三、测试验证
reboot测试一下 重启机器是否会成功挂载
测试验证成功
关闭的话:
sudo systemctl disable mount-s3.service
sudo systemctl stop mount-s3.service
在reboot 一下
补充:
centos 7 挂载 腾讯云对象存储
yum install automake gcc-c++ git libcurl-devel libxml2-devel fuse-devel make openssl-devel -y
git clone https://github.com/tencentyun/cosfs /usr/cosfs #获取源码
cd /usr/cosfs
./autogen.sh
./configure
make
sudo make install
cosfs --version #查看 cosfs 版本号
echo bucketname:SecretId:SecretKey /etc/passwd-cosfs
chmod 640 /etc/passwd-cosfs
mkdir -p /cos
cosfs <BucketName-APPID> <MountPoint> -ourl=<CosDomainName> -odbglevel=info #这是版本1.0.5以上的方法
v1.0.5 之前版本 COSFS 的挂载命令如下:
cosfs <APPID>:<BucketName> <MountPoint> -ourl=<CosDomainName>
<MountPoint> 为本地挂载目录(如 /mnt)。
<CosDomainName> 为存储桶对应的访问域名,形式为 http://cos.<Region>.myqcloud.com(适用于XML API,请勿在该参数中携带存储桶名称),其中 <Region> 为地域简称, 如: ap-guangzhou 、 eu-frankfurt 等。更多地域信息,请查阅 可用地域。
-odbglevel 指定日志级别。
cosfs examplebucket-1250000000 /cos -ourl=http://cos.ap-guangzhou.myqcloud.com -odbglevel=info -onoxattr
echo "" >~/.passwd-s3fs
cosfs loo-165456466 /ry_test_obs -ourl=http://cos.ap-chengdu.myqcloud.com -opasswd_file=/root/.passwd-s3fs -odbglevel=info -onoxattr
centos 7 挂载 AWS对象存储
echo "AK:SK" >~/.passwd-s3fs
s3fs tes /test -o passwd_file=~/.passwd-s3fs -o allow_other -o url=http://s3.cn-north-1.amazonaws.com.cn -o endpoint=cn-north-1