Azure File 服务(2):使用Powershell开发管理

发布时间:2020-05-23 11:22:38 作者:stevenlian
来源:网络 阅读:302

使用Powershell创建文件共享

 

Azure的文件存储结构如下所示,最基本的文件存储包含存储账号,文件共享,在文件共享下面你可以建立文件目录,上传文件:

Azure File 服务(2):使用Powershell开发管理

在开始使用Powershell创建文件共享之前,你需要获得Azure的账号,安装powershell,配置你的账号,请参考我以前的博客,在此不再赘述。

  1. 首先,创建Azure storage account,需要设置你的storage账号的名称,以及你的存储账号是创建在那个region,比如中国东部:

    $StorageAccountName="mystorageacctfile"

    $Location="China East"

    New-AzureStorageAccount –StorageAccountName $StorageAccountName -Location $Location

     

    Azure File 服务(2):使用Powershell开发管理

     

  2. 通过命令得到你的当前存储账号的key,设置你的当前订阅,和当前订阅的存储账号:

    #得到存储的key值

    Get-AzureStorageKey -StorageAccountName $StorageAccountName

    #设置当前订阅的默认存储

    Set-AzureSubscription -CurrentStorageAccountName $StorageAccountName -SubscriptionId $SubscriptionID

     

  3. 通过Powershell来创建Azure file 的文件存储

    #获得Azure存储的上下文

    $ctx=New-AzureStorageContext $StorageAccountName $StorageAccountKey

     

    #创建Azure file共享服务

    $share = New-AzureStorageShare $filesharename -Context $ctx

     

    #列出当前Azure文件共享服务

    Get-AzureStorageShare -Context $ctx -Name $filesharename

     

    Azure File 服务(2):使用Powershell开发管理

    Azure File 服务(2):使用Powershell开发管理

     

  4. 登陆到Azure的portal上,你可以看到已经配置好的存储账号和文件服务:

    Azure File 服务(2):使用Powershell开发管理

  5. 如果你希望你的文件服务实现跨地区的冗余,你可以在配置项进行配置:

     

    Azure File 服务(2):使用Powershell开发管理

  6. 到目前为止文件共享服务已经创建完毕了,那么我们使用Powershell来使用文件共享服务,包括创建目录,上传一个文件,列出文件:

    #创建文件共享目录

    New-AzureStorageDirectory -Share $share -Path logs

     

    #上传一个文件到文件共享目录

    Set-AzureStorageFileContent -Share $share -Source d:\hdinsight.publishsettings -Path logs

     

    # 列出目录下的所有文件

    Get-AzureStorageFile -Share $share -Path logs | Get-AzureStorageFile

     

    # List all your files

    Get-AzureStorageFile -Share $share -Path logs | Get-AzureStorageFile

    Azure File 服务(2):使用Powershell开发管理

     

    Azure File 服务(2):使用Powershell开发管理

     

  7. 和其他存储类似,你可以使用powershell在File和File之间,File和Blob之间进行拷贝:

    Start-AzureStorageFileCopy -SrcShareName $filesharename -SrcFilePath "logs/hdinsight.publishsettings" -DestShareName $filesharenamenew -DestFilePath "logs/hdinsight.publishsettings" -Context $ctx -DestContext $ctx

     

    所有相关测试脚本已经更新到了github,你可以下载源代码测试:

    https://github.com/kingliantop/azurelabs/blob/master/storage/StorageFileShare.ps1


推荐阅读:
  1. 云服务器如何创建磁盘分区
  2. 云服务器的镜像是什么

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

storage 上传文件 account

上一篇:Linux中vi不保存强制退出的命令是什么?

下一篇:HTML的option标签的使用场景

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》