阿里云对象存储 OSS

当前,以演示站点域名moredoc.mnt.ltd和对象存储绑定的域名static.moredoc.mnt.ltd来作为配置演示,其他配置项仅作为参考。

步骤

1. 开通阿里云对象存储OSS

地址:https://www.aliyun.com/product/oss

阿里云对象存储 OSS - 图1

2. 创建私有 Bucket

地址:https://oss.console.aliyun.com/bucket

阿里云对象存储 OSS - 图2

3. 创建Access Key

地址: https://ram.console.aliyun.com/manage/ak

如已有Access Key,则可跳过创建

阿里云对象存储 OSS - 图3

4. 配置

修改 app.toml 下的cloudStore

  1. [cloudStore]
  2. # 存储类型,填oss,即阿里云对象存储
  3. storeType = "oss"
  4. # 存储绑定的域名,带 http:// 或 https:// ,可以为空。
  5. domain = "https://static.moredoc.mnt.ltd"
  6. # 阿里云的 AccessKey ID
  7. accessKey = "AccessKey ID"
  8. # 阿里云的 AccessKey Secret
  9. secretKey = "AccessKey Secret"
  10. # 对象存储的bucket
  11. bucket = "moredoc-private"
  12. # 对象存储 endpoint
  13. endpoint = "oss-cn-shenzhen.aliyuncs.com"

5. 迁移与重启

迁移本地的 uploadsdocuments 到对象存储

  1. ./moredoc migrateCloudstore

重启文库程序。

配置参考

完整配置参考示例如下:

  1. # 程序运行级别:debug、info、warn、error,生产环境使用 info及其以上级别
  2. level = "debug"
  3. # 日志编码方式,支持:json、console
  4. logEncoding = "console"
  5. # 程序运行端口
  6. port = "8880"
  7. # 数据库配置
  8. [database]
  9. driver = "mysql"
  10. dsn = "root:root@tcp(localhost:3306)/moredoc?charset=utf8mb4&loc=Local&parseTime=true"
  11. showSQL = true
  12. maxOpen = 10
  13. maxIdle = 10
  14. # JSON Web Token 配置
  15. [jwt]
  16. # 生成 token 的密钥,请务必修改!!!
  17. secret = "moredoc"
  18. # token 过期时间
  19. expireDays = 365
  20. [cloudStore]
  21. # 存储类型,填oss,即阿里云对象存储
  22. storeType = "oss"
  23. # 存储绑定的域名,带 http:// 或 https:// ,可以为空。
  24. domain = "https://static.moredoc.mnt.ltd"
  25. # 阿里云的 AccessKey ID
  26. accessKey = "AccessKey ID"
  27. # 阿里云的 AccessKey Secret
  28. secretKey = "AccessKey Secret"
  29. # 对象存储的bucket
  30. bucket = "moredoc-private"
  31. # 对象存储 endpoint
  32. endpoint = "oss-cn-shenzhen.aliyuncs.com"