zoukankan      html  css  js  c++  java
  • OpenLdap+MySQL笔记

    20元现金领取地址:http://jdb.jiudingcapital.com/phone.html
    内部邀请码:C8E245J (不写邀请码,没有现金送)

    国内私募机构九鼎控股打造,九鼎投资是在全国股份转让系统挂牌的公众公司,股票代码为430719,为“中国PE第一股”,市值超1000亿元。

    最近项目原因,在CentOS下做了一套简单的LDAP服务,在此记录一二,本文强调后期碰到的问题和解决方法

    下面的链接是比较详细的安装和基本配置过程,这个链接适用于debian,但是类似的可以在其他发行版下借鉴:

    http://www.wingfoss.com/content/how-to-install-openldap-with-mysql-on-debian6

    如果从源代码安装的话,slapd不会被注册成服务,需要手动来做。下面是一个Ldap自启动的脚本,我在CentOS下试过了,可以用的

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    #!/bin/sh
    #
    # ldap This shell script takes care of starting and stopping
    # ldap servers (slapd and slurpd).
    #
    # chkconfig: - 70 40
    # description: LDAP stands for Lightweight Directory Access Protocol, used
    # for implementing the industry standard directory services.
    # processname: slapd
    # config: /etc/openldap/slapd.conf
    # pidfile: /var/run/slapd.pid
    # Source function library.
    . /etc/rc.d/init.d/functions
    # Source networking configuration.
    . /etc/sysconfig/network
    # Check that networking is up.
    [ ${NETWORKING} = "no" ] && exit 0
    [ -f /usr/local/libexec/slapd ] || exit 0
    # [ -f /usr/sbin/slurpd ] || exit 0
     
    export CPPFLAGS="-I/opt/BerkeleyDB.5.3/include"
    export LDFLAGS="-L/opt/BerkeleyDB.5.3/lib"
    export LD_LIBRARY_PATH="/opt/BerkeleyDB.5.3/lib"
     
    RETVAL=0
    # See how we were called.
    case "$1" in
            start)
            # Start daemons.
                    echo -n "Starting ldap: "
                    daemon /usr/local/libexec/slapd
                    RETVAL=$?
                    if [ $RETVAL -eq 0 ]; then
                            if grep -q "^replogfile" /etc/openldap/slapd.conf; then
                                    daemon slurpd
                                    RETVAL=$?
                                    [ $RETVAL -eq 0 ] && pidof slurpd | cut -f 1 -d " " > /var/run/slurpd
                            fi
                    fi
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ldap
    ;;
            stop)
            # Stop daemons.
                    echo -n "Shutting down ldap: "
                    killproc slapd
                    RETVAL=$?
                    if [ $RETVAL -eq 0 ]; then
                            if grep -q "^replogfile" /etc/openldap/slapd.conf; then
                            killproc slurpd
                            RETVAL=$?
                            fi
                    fi
    echo
    if [ $RETVAL -eq 0 ]; then
                    rm -f /var/lock/subsys/ldap
                    rm -f /var/run/slapd.args
                    fi
    ;;
            status)
                    status slapd
                    RETVAL=$?
                    if [ $RETVAL -eq 0 ]; then
                            if grep -q "^replogfile" /etc/openldap/slapd.conf; then
                                    status slurpd
                                    RETVAL=$?
                            fi
                    fi
    ;;
            restart)
                    $0 stop
                    $0 start
                    RETVAL=$?
    ;;
            reload)
                    killproc -HUP slapd
                    RETVAL=$?
                    if [ $RETVAL -eq 0 ]; then
                            if grep -q "^replogfile" /etc/openldap/slapd.conf; then
                                    killproc -HUP slurpd
                                    RETVAL=$?
                            fi
                    fi
    ;;
    *)
    echo "Usage: $0 start|stop|restart|status}"
    exit 1
    esac
    exit $RETVAL

    对脚本的一些说明

    • # chkconfig: - 70 40 :此行不仅仅是注释,服务注册的命令(chkconfig)会根据这行还决定服务的启动顺序
    • export是导出BerkeleyDB的库文件和头文件

    将脚本保存在/etc/init.d下,为其设置可执行权限

    1
    chmod 700 /etc/init.d/ldap

    用chkconfig命令注册脚本在启动时运行

    1
    2
    chkconfig --add ldap
    chkconfig --level 345 ldap on

    因为是基于mysql的后端数据库,所以要保证ldap在mysql启动后启动,查看相应运行级别的rc.d文件(比如在level3时,进入到/etc/rc.d/rc3.d),查看其中的链接的开头数字是否大于mysql服务的数字。关于CentOS下,服务的基本概念这里不再说了

    后续问题:长时间inactive,LDAP故障,需要重启

    LDAP上线后,发现每天晚上过来LDAP服务都不可用了。这个问题一度困扰了我很长时间,网上各种查都无果,为此还在论坛上提问了。详见http://www.linuxcast.net/ask/show/480

    最终偶然的机会,同事抱怨说Oracle数据库链接超过上线,要释放。我突然来了灵感,猜测是Mysql数据库链接自动关闭的问题,回头一查,果然mysql的如下参数设置成了8小时:

    interactive_timeout    | 28800

    wait_timeout       | 28800

    这样一来,一晚上(超过8小时)过来mysql主动将LDAP打开并保存的链接单方面关闭了,而LDAP全然不知,也没有重试链接,导致无法查询数据库。将这个值改大后可以保证一晚上不释放即可。

    后续问题:性能低下

    由于保存用户信息,用于登陆验证。用户感知登陆很慢,通常要10秒以上,才能登录。开始分析:先打开LDAP的log,在LDAP的配置文件里面配置

    loglevel   256

    然后在linux的日志服务的配置文件中添加

    local4.*   -/var/log/ldap.log

    log将输出到上面的路径下,关于linux系统日志服务的基本知识这里略过

    观察log发现search每次都要大约6秒钟的时间,是主要的性能瓶颈。最初想为LDAP加索引和缓存,索引似乎只能支持bdb,缓存似乎要另外装插件;再看mysql端是否可以优化的,用脚本创建出来的表都带有索引,于是考虑mysql查询缓存是否能帮上忙:http://blog.webwlan.net/wordpress/?p=422

    最终,尝试配置下面的配置:query_cache_size。这个值默认是0,因此,即使query_cache_type默认是启用的,也不能缓存查询结果。将query_cache_size配置成大约100M,测试LDAP,明显登录加快。再看log,查询时间缩短到1秒,暂时解决了燃眉之急。

  • 相关阅读:
    Neko's loop HDU-6444(网络赛1007)
    Parameters
    SETLOCAL
    RD / RMDIR Command
    devenv 命令用法
    Cannot determine the location of the VS Common Tools folder.
    'DEVENV' is not recognized as an internal or external command,
    How to change Visual Studio default environment setting
    error signing assembly unknown error
    What is the Xcopy Command?:
  • 原文地址:https://www.cnblogs.com/AloneSword/p/4759791.html
Copyright © 2011-2022 走看看