如何阅读Perl中的大量LDAP条目的

如何阅读Perl中的大量LDAP条目的

本文介绍了如何阅读Perl中的大量LDAP条目的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有一个LDAP脚本,以便通过一个用于读取LDAP用户信息之一。我的问题是,我回来在Active Directory中的所有用户。这是行不通的,因为目前我们的广告有10万左右的用户导致脚本崩溃由于内存限制。

I already have an LDAP script in order to read LDAP user information one by one. My problem is that I am returning all users found in Active Directory. This will not work because currently our AD has around 100,000 users causing the script to crash due to memory limitations.

我在想什么做的是试图通过用户的X数量批次,如果可能的话来处理用户,使用线程以处理一些用户可以并行的。唯一的事情是,我刚开始使用Perl,所以我想知道,如果有人可以给我如何做到这一点的总体思路。

What I was thinking of doing was to try to process users by batches of X amount of users and if possible, using threads in order to process some users in parallel. The only thing is that I have just started using Perl, so I was wondering if anyone could give me a general idea of how to do this.

推荐答案

如果你能得到执行的ldapsearch 在你的环境中工作(和它在* nix的工作和Windows,虽然语法往往是不同的),你可以尝试这样的:

If you can get the executable ldapsearch to work in your environment (and it does work in *nix and Windows, although the syntax is often different), you can try something like this:

my $LDAP_SEARCH = "ldapsearch -h $LDAP_SERVER -p $LDAP_PORT -b $BASE -D uid=$LDAP_USERNAME -w $LDAP_PASSWORD -LLL";
my @LDAP_FIELDS = qw(uid mail Manager telephoneNumber CostCenter NTLogin displayName);
open (LDAP, "-|:utf8", "$LDAP_SEARCH \"$FILTER\" " . join(" ", @LDAP_FIELDS));
while (<LDAP>) {
  # process each LDAP response
}

我用的是读取无记忆的问题近10万LDAP条目(尽管它仍然需要30分钟以上)。你需要定义 $ FILTER (或留空),当然所有的LDAP服务器/用户名/密码件。

I use that to read nearly 100K LDAP entries without memory problems (although it still takes 30 minutes or more). You'll need to define $FILTER (or leave it blank) and of course all the LDAP server/username/password pieces.

如果你想/需要做一个更纯粹的Perl版本,我有更好的运气的Net :: LDAP 而不是网:: LDAP ::前preSS ,特别是大型的查询。

If you want/need to do a more pure-Perl version, I've had better luck with Net::LDAP instead of Net::LDAP::Express, especially for large queries.

这篇关于如何阅读Perl中的大量LDAP条目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 00:31