CentOS7加入AD域(winbind)
CentOS7加入AD域(winbind)

CentOS7加入AD域(winbind)

前言

AD域(Active Directory)是Windows服务器的活动目录,在目录中可以收录公司的电脑账号,用户账号,组等信息,以提供更好的安全性和更便捷的管理能力。域的最大好处之一就是其安全性 – 所有账号不会在本地计算机认证,而是连接到域控制器寻求认证。

CentOS7加入AD域的方法很多,常用的有winbind和realm两种。winbind是一种成熟的方案,兼容多种操作系统版本,但配置步骤繁琐复杂,且易出错。realm是一种非常简便的配置方案,在新版本系统中使用较多,在centos6和更低版本系统使用较少。

一、环境信息

AD域信息

域名:anyamaze.com

主机名:myad

IP : 192.168.111.137

系统版本:windows server 2016

linux客户端信息
主机名:mynode1.anyamaze.com

IP: 192.168.111.141

二、安装过程

(一)AD域服务器部署

1.部署windows Server2016操作系统

2.选择“服务器管理器—管理—添加角色和功能—基于角色或基于功能的安装—Active Directory域服务”根据提示依次安装

3.修改主机名,将服务器提示为域控服务器

(二)CentOS7加入域配置

1.安装相关包

yum install -y samba samba-common samba-client samba-winbind* krb5-workstation ntp bind-utils

2.设置服务开机自启动

systemctl enable smb
systemctl enable winbind

3.设置主机名

hostnamectl set-hostname mynode1.anyamaze.com

4.配置域名解析

192.168.111.137 myad myad.anyamaze.com
192.168.111.141 mynode1 mynode1.anyamaze.com

5.配置DNS解析

配置网卡DNS解析,解析地址为AD域服务器IP,如需其它DNS,可放在AD域服务器IP之后

vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
...
DNS1=192.168.111.137

#重启网卡,使配置生效
systemctl restart network

检查/etc/resolv.conf文件内容

vim /etc/resolv.conf
search anyamaze.com
nameserver 192.168.111.137

需确保resolve.conf文件DNS解析内容为AD域服务器,如果需要其它DNS,可向后追加。

检测解析是否生效

ping anyamaze.com
nslookup anyamaze.com

注意:确保ping的返回ip为AD域服务器ip,确保nslookup解析域名的服务器IP是AD域服务器IP。如果ping不通域名或解析的地址不是AD域服务器IP,需要检查DNS是否正确,检查AD域服务器防火墙是否关闭。

6.修改配置文件

vi /etc/nsswitch.conf
...
passwd:     files winbind sss
shadow:     files winbind sss
group:      files winbind sss

配置内容加入winbind,且winbind在sss之前

7.修改/etc/krb5.conf

[libdefaults]
......
 default_realm = ANYAMAZE.COM
......
[realms]
ANYAMAZE.COM = {
   kdc = 192.168.111.137
 }
[domain_realm]
 anyamaze.com = ANYAMAZE.COM
 .anyamaze.com = ANYAMAZE.COM

8.修改/etc/samba/smb.conf

[global]
   workgroup = ANYAMAZE
   password server = myad.anyamaze.com
   realm = ANYAMAZE.COM
   security = ads
   idmap config * : range = 16777216-33554431
   template shell = /bin/bash
   kerberos method = secrets only
   winbind use default domain = false
   winbind offline logon = false
   encrypt passwords = yes
   winbind enum users = yes
   winbind enum groups = yes
   template homedir = /home/%U

global中必须保证以上参数内容配置正确,其它参数可保持默认配置。如果linux系统有图形化界面,也可通过setup命令,完成步骤7和步骤8的配置内容,效果一样。

检查配置是否正确

testparm /etc/samba/smb.conf

9.编辑文件/etc/pam.d/system-auth和/etc/pam.d/password-auth,尾部追加session required pam_mkhomedir.so 内容

vi /etc/pam.d/system-auth
......
session required pam_mkhomedir.so

vi /etc/pam.d/password-auth
......
session required pam_mkhomedir.so

10.加入AD域

net ads join -U administrator

输入正确的administrator用户密码

11.重启服务

systemctl restart smb
systemctl restart winbind

12.查看是否加入域成功

wbinfo -t

返回结果为checking the trust secret for domain ANYAMAZE via RPC calls succeeded说明加入域成功

加入成功后,去AD域服务器可查到到刚刚加入域的机器

13.常规域指令

# 查看域信息
net ads info
# 查看域连接状态
wbinfo -t
# 查看域组
wbinfo -g
# 查看域用户
wbinfo -u
#查看域用户属性id
id user1@anyamaze.com

(三)常见报错:

报错内容1:

[root@mynode1 ~]# id user1
id: user1: no such user
[root@mynode1 ~]# id user1@anyamaze.com
id: user1@anyamaze.com: no such user

原因:1.通过wbinfo -t检查是否加入域成功;2.AD域用户没有配置uid和gid,主组没有配置gid,需要去AD域上进行配置

报错内容2:

[root@mynode1 ~]# net ads join -U administrator
Enter administrator's password:
Using short domain name -- ANYAMAZE
Joined 'MYNODE1' to dns domain 'anyamaze.com'
No DNS domain configured for mynode1. Unable to perform DNS Update.
DNS update failed: NT_STATUS_INVALID_PARAMETER

原因:DNS更新失败,但不影响使用,可以加--no-dns-updates屏蔽,如:net ads join -U administrator --no-dns-updates。

关于原因官网 https://wiki.samba.org/index.php/Setting_up_Samba_as_a_Domain_Member 有详细解释,但是按照官网的信息调整hosts后,依然没有达到效果。

报错内容3:

[root@mynode1 ~]# wbinfo -t
could not obtain winbind interface details: WBC_ERR_WINBIND_NOT_AVAILABLE
could not obtain winbind domain name!
checking the trust secret for domain (null) via RPC calls failed
failed to call wbcCheckTrustCredentials: WBC_ERR_WINBIND_NOT_AVAILABLE
Could not check secret

原因:加入域失败,按照操作步骤检查dns解析以及相关配置过程

报错内容4:

[root@mynode1 ~]# net ads leave -U administrator
Enter administrator's password:
kinit succeeded but ads_sasl_spnego_gensec_bind(KRB5) failed for ldap/myad.anyamaze.com with user[administrator] realm[ANYAMAZE.COM]: An invalid parameter was passed to a service or function.
Deleted account for 'MYNODE1' in realm 'ANYAMAZE.COM'

原因:linux和AD域服务器时间相差较大,必须保证linux客户端和AD域时间一致

参考连接:

https://wiki.samba.org/index.php/Setting_up_Samba_as_a_Domain_Member

https://www.freesion.com/article/44621398696/

https://www.server-world.info/en/

**更多资讯,关注我们**

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注