ubuntu 使用s3fs配置自动挂载对象存储

一、环境准备

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 一下

相关推荐
衫水1 小时前
ubuntu系统如何检查和安装以及运行redis
redis·ubuntu·bootstrap
苏宸啊1 小时前
Linux权限
linux·运维·服务器
Gofarlic_oms11 小时前
Windchill用户登录与模块访问失败问题排查与许可证诊断
大数据·运维·网络·数据库·人工智能
xqhoj2 小时前
Linux——make、makefile
linux·运维·服务器
文亭湖畔程序猿2 小时前
Debian 12 日常命令 & nano 快捷键速查表
运维·debian
张童瑶2 小时前
Linux 在线安装编译Python3.11
linux·运维·python3.11
ziqibit2 小时前
debian Live with Persistence 持久化U盘的debian系统
运维·debian
Shi_haoliu2 小时前
SolidTime 在 Rocky Linux 9.5 上的完整部署流程
linux·运维·nginx·postgresql·vue·php·laravel
Lkygo2 小时前
LlamaIndex使用指南
linux·开发语言·python·llama
qq_254617773 小时前
nslookup 这个命令解析dns,和系统接口gethostbyname解析区别在哪?
linux·网络