在启用配额的故障转移群集中添加共享需要 10 分钟

在启用配额的故障转移群集中添加共享需要 10 分钟

我有一个文件服务集群,其中一个文件服务器资源托管着约 50,000 个用户主目录。主目录确实有一个通过以下方式分配的配额模板:金融风险管理师

尝试使用故障转移群集管理器的“添加文件共享”向导首先检索所有定义的文件服务器群集资源上所有共享文件夹的所有配额。在此环境中,这大约需要 10 分钟。

我怎么能

  • 加快配额统计进程
  • 将配额枚举过程限制为仅单个文件服务器群集资源
  • 完全禁用配额枚举新股巫师

答案1

我最终通过完全取消使用 GUI 创建文件共享的要求解决了这个问题。相反,我记录了使用 New-SmbShare 作为共享创建过程。以这种方式添加共享会绕过 GUI 向导执行的所有预配置检查,包括配额枚举。

New-SmbShare -Name <ShareName> -ScopeName "<CAPName>" -Path "<LocalDirectoryToBeShared>" -FullAccess "Everyone" -Description "<Comment>"

New-SmbShare命令已在 Server 2012 R2 / Windows 8.1 中引入。对于以前版本(2012、2008R2、2008)的文件服务器集群,您可以借用NativeMethods导入网络共享添加来自 Netapi32.dll 的函数脚本以及有关 Fileover Cluster 范围内共享的 MSDN 博客文章

我的简化版本如下所示:

#Using Win32 API NetShareAdd via p/invoke to be able to specify the scope in SHARE_INFO_503
$signature = @"

    using System;
    using System.Runtime.InteropServices;
    using System.Collections;

    public class NativeMethods
    {
        [DllImport("Netapi32.dll")]
        public static extern uint NetShareAdd([MarshalAs(UnmanagedType.LPWStr)] string strServer, Int32 dwLevel, ref SHARE_INFO_503 buf, out uint parm_err);

        [StructLayoutAttribute(LayoutKind.Sequential)]
        struct SECURITY_DESCRIPTOR {
            public byte revision;
            public byte size;
            public short control;
            public IntPtr owner;
            public IntPtr group;
            public IntPtr sacl;
            public IntPtr dacl;
        }

        public enum SHARE_TYPE : uint
        {
            STYPE_DISKTREE = 0,
            STYPE_PRINTQ = 1,
            STYPE_DEVICE = 2,
            STYPE_IPC = 3,
            STYPE_SPECIAL = 0x80000000
        };

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        public struct SHARE_INFO_503
        {
            public string shi503_netname;
            [MarshalAs(UnmanagedType.U4)]
            public SHARE_TYPE shi503_type;
            public string shi503_remark;
            [MarshalAs(UnmanagedType.U4)]
            public int shi503_permissions;
            [MarshalAs(UnmanagedType.U4)]
            public int shi503_max_uses;
            [MarshalAs(UnmanagedType.U4)]
            public int shi503_current_uses;
            public string shi503_path;
            public string shi503_passwd;
            public string shi503_servername;
            [MarshalAs(UnmanagedType.U4)]
            public int shi503_reserved;
            public IntPtr shi503_security_descriptor;
        }


        public static uint ShareFolder(string servername, string sharename, string path, string remark)
        {
            SHARE_INFO_503 shInfo = new SHARE_INFO_503();
            shInfo.shi503_netname = sharename;
            shInfo.shi503_type = SHARE_TYPE.STYPE_DISKTREE;
            shInfo.shi503_remark = remark;
            shInfo.shi503_permissions = 0;
            shInfo.shi503_max_uses = -1;
            shInfo.shi503_current_uses = 0;
            shInfo.shi503_path = path;
            shInfo.shi503_passwd = null;
            shInfo.shi503_servername = servername;
            shInfo.shi503_reserved = 0;
            shInfo.shi503_security_descriptor = IntPtr.Zero;

            uint nRetValue = 0;
            uint param_err = 0;

            nRetValue = NetShareAdd(servername, 503, ref shInfo, out param_err);

            //Console.WriteLine("Sharing " + path + " on " + servername + " as " + sharename + " returned " + nRetValue + " (" + param_err+ ")");

            return nRetValue;
        }
    }
"@


#Import the FailoverClusters PowerShell module if it is not already imported
Import-Module FailoverClusters

#Add the function type that will be used to share the folder in the defined scope
Add-Type -TypeDefinition $signature

使用很简单:

[NativeMethods]::ShareFolder("<CAPname>", "<ShareName>", "<LocalDirectoryToBeShared>", "<Comment>")

ShareFolder函数在成功执行后返回 0 并立即完成,即使启用了配额也是如此。要在托管 CAP/文件服务器资源的集群节点之一上运行。您可能必须在之后修复共享 ACL,因为默认共享创建 ACL 是公正的Everyone:Read,无法使用此方法指定。

相关内容