OpenEluer 安装 OpenLDAP

一、版本信息

OpenEluer版本信息

查询版本信息命令 复制代码
cat /etc/os-release

OpenLDAP版本信息 2.4.44

下载地址

二、修改yum数据源

备份原有 YUM 源配置

bash 复制代码
cd /etc/yum.repos.d/
mv openEuler.repo openEuler.repo.bak  # 备份原有配置

创建阿里云 YUM 源配置文件

创建 /etc/yum.repos.d/aliyun-openeuler.repo 文件:

bash 复制代码
sudo vim /etc/yum.repos.d/aliyun-openeuler.repo

填入以下内容(适用于 openEuler 22.03 LTS SP4):

ini 复制代码
[OS]
name=openEuler-OS
baseurl=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/OS/$basearch/
metalink=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/OS/$basearch/metalink
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/OS/$basearch/RPM-GPG-KEY-openEuler

[everything]
name=openEuler-everything
baseurl=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/everything/$basearch/
metalink=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/everything/$basearch/metalink
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/everything/$basearch/RPM-GPG-KEY-openEuler

[EPOL]
name=openEuler-EPOL
baseurl=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/EPOL/main/$basearch/
metalink=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/EPOL/main/$basearch/metalink
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/OS/$basearch/RPM-GPG-KEY-openEuler

[debuginfo]
name=openEuler-debuginfo
baseurl=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/debuginfo/$basearch/
metalink=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/debuginfo/$basearch/metalink
# 调试信息通常不需要,可按需启用
enabled=0  
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/debuginfo/$basearch/RPM-GPG-KEY-openEuler

[source]
name=openEuler-source
baseurl=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/source/
metalink=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/source/metalink
# 源代码通常不需要,可按需启用
enabled=0  
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/source/RPM-GPG-KEY-openEuler

[update]
name=openEuler-update
baseurl=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/update/$basearch/
metalink=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/update/$basearch/metalink
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/OS/$basearch/RPM-GPG-KEY-openEuler

[update-source]
name=openEuler-update-source
baseurl=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/update/source/
metalink=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/update/source/metalink
# 源代码更新通常不需要,可按需启用
enabled=0  
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/openeuler/openEuler-22.03-LTS-SP4/source/RPM-GPG-KEY-openEuler

清理并生成缓存

css 复制代码
sudo yum clean all
sudo yum makecache

验证配置

复制代码
sudo yum repolist

正常输出应显示阿里云镜像源的仓库列表。

三、安装​​GNU Libtool 运行时库

安装 libtool-ltdl

​安装运行时库​​:

复制代码
bash
复制
sudo yum install -y libtool-ltdl

​安装开发库(如需编译依赖)​​:

复制代码
bash
复制
sudo yum install -y libtool-ltdl-devel

验证安装​**​

安装完成后,验证 libtool-ltdl 是否成功安装:

bash 复制代码
# 查看 Libtool 版本(间接验证) 
ldd --version 
# 或直接检查库文件 
ls /usr/lib64/libltdl.so*

四、解压OpenLDAP

上传源码包 /opt/

把下载的openldap-2.4.44.tgz安装包上传到服务中

解压源码包

bash 复制代码
tar -zxvf openldap-2.4.44.tgz
cd openldap-2.4.44

五、编译OpenLDAP

执行编译命令

css 复制代码
./configure --prefix=/usr/local/openLDAP-2.4.44 --enable-modules=yes --enable-rewrite --enable-memberof=yes  --enable-refint=yes --enable-hdb=no --enable-bdb=no --enable-overlays

注意:

编译时可以不用添加BDB或HDB数据库,上述命令中已包含,具体需要添加如下参数:

ini 复制代码
--enable-hdb=no --enable-bdb=no

执行成功后的末尾如图所示:

执行依赖检测命令,依次执行下述命令

go 复制代码
make depend
go 复制代码
make

执行测试命令

这一步会比较耗时,耐心等待执行完成

bash 复制代码
make test

执行install

go 复制代码
make install

这一步执行成功后,会在--prefix=/usr/local/openldap-2.4.44 命令目录下生成编译后的程序目录

六、设置快捷方式

对OpenLDAP客户端(bin)与服务器端(sbin)相关执行档添加软链接,也可以通过增加环境变量的方式设置

bash 复制代码
cd /usr/local/openldap-2.4.44
ln -s /usr/local/openldap-2.4.44/bin/* /usr/local/bin/
ln -s /usr/local/openldap-2.4.44/sbin/* /usr/local/sbin/

七、验证

生成初始密码密钥

复制代码
slappasswd -s bywx2020

这里的{SSHA}bd3Fb/vIKXjavSwAA8iYsaHTeC8zwOUM就是加密后生成的密钥

修改配置文件slapd.conf

bash 复制代码
vim /usr/local/openldap-2.4.44/etc/openldap/slapd.conf

追加如下内容:

bash 复制代码
#schema默认只有core.schema,各级需要添加,这里将同配置文件一个目录的schema目录中有的schema文件都加到配置文件中;
include /usr/local/openldap-2.4.44/etc/openldap/schema/collective.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/corba.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/cosine.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/duaconf.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/dyngroup.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/inetorgperson.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/java.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/misc.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/nis.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/openldap.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/pmi.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/ppolicy.schema

追加日志文件级别与路径

bash 复制代码
loglevel 256 
logfile /usr/local/openldap-2.4.44/var/slapd.log

修改域名及管理员账户名;

ini 复制代码
suffix "dc=demo,dc=com" 
rootdn "cn=admin,dc=demo,dc=com"

修改密码,使用前面slappasswd生成的密文或明文密码

复制代码
rootpw		{SSHA}P4BlRK+eYi234rwWWsYc9ziURbqWXh9B

完整示例

bash 复制代码
#
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include		/usr/local/openldap-2.4.44/etc/openldap/schema/core.schema

# Define global ACLs to disable default read access.

# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral	ldap://root.openldap.org

pidfile		/usr/local/openldap-2.4.44/var/run/slapd.pid
argsfile	/usr/local/openldap-2.4.44/var/run/slapd.args

# Load dynamic backend modules:
# modulepath	/usr/local/openldap-2.4.44/libexec/openldap
# moduleload	back_mdb.la
# moduleload	back_ldap.la

# Sample security restrictions
#	Require integrity protection (prevent hijacking)
#	Require 112-bit (3DES or better) encryption for updates
#	Require 63-bit encryption for simple bind
# security ssf=1 update_ssf=112 simple_bind=64

# Sample access control policy:
#	Root DSE: allow anyone to read it
#	Subschema (sub)entry DSE: allow anyone to read it
#	Other DSEs:
#		Allow self write access
#		Allow authenticated users read access
#		Allow anonymous users to authenticate
#	Directives needed to implement policy:
# access to dn.base="" by * read
# access to dn.base="cn=Subschema" by * read
# access to *
#	by self write
#	by users read
#	by anonymous auth
#
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn.  (e.g., "access to * by * read")
#
# rootdn can always read and write EVERYTHING!

#######################################################################
# MDB database definitions
#######################################################################

database	mdb
maxsize		1073741824
suffix		"dc=demo,dc=com"
rootdn		"cn=admin,dc=demo,dc=com"
# Cleartext passwords, especially for the rootdn, should
# be avoid.  See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw		{SSHA}P4BlRK+eYi234rwWWsYc9ziURbqWXh9B
# The database directory MUST exist prior to running slapd AND 
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory	/usr/local/openldap-2.4.44/var/openldap-data
# Indices to maintain
index	objectClass	eq


#schema默认只有core.schema,各级需要添加,这里将同配置文件一个目录的schema目录中有的schema文件都加到配置文件中;
include /usr/local/openldap-2.4.44/etc/openldap/schema/collective.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/corba.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/cosine.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/duaconf.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/dyngroup.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/inetorgperson.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/java.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/misc.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/nis.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/openldap.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/pmi.schema
include /usr/local/openldap-2.4.44/etc/openldap/schema/ppolicy.schema

loglevel    256
logfile    /usr/local/openldap-2.4.44/var/slapd.log

建立openldap-data目录

bash 复制代码
cd /usr/local/openldap-2.4.44/var/
mkdir openldap-data

八、启动OpenLDAP

bash 复制代码
/usr/local/openldap-2.4.44/libexec/slapd -d 256

验证openldap服务是否正常启动

csharp 复制代码
ldapsearch -x -b '' -s base'(objectclass=*)'

看到如下输出,则说明openldap启动成功,且可以正常使用:

相关推荐
OpenAnolis小助手5 小时前
朗空量子与 Anolis OS 完成适配,龙蜥获得抗量子安全能力
安全·开源·操作系统·龙蜥社区·龙蜥生态
墨夏1 天前
跨平台开发下的策略模式
设计模式·操作系统
fakerth2 天前
OpenHarmony介绍
操作系统·openharmony
程序员老刘3 天前
操作系统“卡脖子”到底是个啥?
android·开源·操作系统
有信仰3 天前
操作系统——虚拟内存和物理内存
操作系统
望获linux8 天前
【实时Linux实战系列】实时数据流处理框架分析
linux·运维·前端·数据库·chrome·操作系统·wpf
unfetteredman8 天前
Mac查看端口使用信息
操作系统·mac
闪电麦坤959 天前
操作系统:RPC 中可能遇到的问题(Issues in RPC)
rpc·操作系统
闪电麦坤959 天前
操作系统:远程过程调用( Remote Procedure Call,RPC)
rpc·操作系统
丐中丐99911 天前
Android系统中如何在Native层调用java实现的系统服务
android·操作系统