将Samba 4.1 作为 Active Directory 配置教程

确保你的机器上安装了超过 2.5 的 python 版本

下载 Samba 4.1 包

注意:我们可以从他们的 Samba 源目录下载 Samba4 包。
但是使用以下命令,我们将下载可用的 Samba4 的最新版本。
如果要下载特定版本的 Samba4.
我建议我们手动下载该软件包。

下载 Samba 4.X

# git clone git://git.samba.org/samba.git samba-master

下载后执行:

# cd samba-master  (主目录的名称可能因下载的包而异)
# ./configure  
# make

说明:

我们可以使用其他选项运行上述配置步骤

  • 如果你在没有任何另外参数的情况下运行 configure 命令,那么 samba 将默认安装在 /usr/local/samba 中,否则使用 --prefix 选项指定不同的安装目录
  • 我们还可以对 Samba 使用 --enable-debug 和 --enable-selftest,因为它会包含另外的调试信息,可以诊断问题,或者我们也可以就输出错误联系 Samba4 开发人员。
# make install

如果上述步骤完成且没有任何错误,则我们可以继续进行配置步骤

将新路径位置添加到 samba 的 bash 文件中

# vi ~/.bashrc
export PATH=$PATH:/usr/local/samba/sbin:/usr/local/samba/bin
# . .bashrc

在运行配置步骤之前,请确保以下内容已准备就绪

# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.20.42 test test.example.com
# vi /etc/resolv.conf
search example.com
nameserver 10.10.20.42
# hostname
test.example.com

Provision Samba

# samba-tool domain provision 
Realm [EXAMPLE.COM]: EXAMPLE.COM 
Domain [EXAMPLE]: EXAMPLE 
Server Role (dc, member, standalone) [dc]: dc 
DNS backend (SAMBA_INTERNAL, BIND9_FLATFILE, BIND9_DLZ, NONE) [SAMBA_INTERNAL]: BIND9_FLATFILE 
Administrator password: [Give Administrator Password]
Retype password: [Retype Administrator Password]
Looking up IPv4 addresses 
Looking up IPv6 addresses 
No IPv6 address will be assigned Setting up share.ldb 
Setting up secrets.ldb 
Setting up the registry 
Setting up the privileges database 
Setting up idmap db 
Setting up SAM db 
Setting up sam.ldb partitions and settings Setting up sam.ldb rootDSE 
Pre-loading the Samba 4 and AD schema Adding DomainDN: DC=example,DC=com 
Adding configuration container Setting up sam.ldb schema 
Setting up sam.ldb configuration data 
Setting up display specifiers 
Modifying display specifiers 
Adding users container 
Modifying users container 
Adding computers container 
Modifying computers container 
Setting up sam.ldb data Setting up well known security principals 
Setting up sam.ldb users and groups 
Setting up self join Adding DNS accounts 
Creating CN=MicrosoftDNS,CN=System,DC=example,DC=com 
See /usr/local/samba/private/named.conf for an example configuration include file for BIND and /usr/local/samba/private/named.txt for further documentation required for secure DNS updates 
Setting up sam.ldb rootDSE marking as synchronized 
Fixing provision GUIDs A Kerberos configuration suitable for Samba 4 has been generated at /usr/local/samba/private/krb5.conf 
安装上述文件后,您的Samba4服务器将准备好使用服务器角色:active directory域控制器
主机名:测试NetBIOS域:示例DNS域:EXAMPLE.com域SID:S-1-5-21-3668134952-3729197751-3642420168

一旦我们成功运行了配置步骤,就可以运行和测试 samba

# samba
# ps -ef | grep samba
root 20465 1 0 10:26 ? 00:00:00 samba
root 20466 20465 0 10:26 ? 00:00:00 samba
root 20467 20465 0 10:26 ? 00:00:00 samba
root 20468 20465 0 10:26 ? 00:00:00 samba
root 20469 20465 0 10:26 ? 00:00:00 samba
root 20470 20465 0 10:26 ? 00:00:00 samba
root 20471 20465 0 10:26 ? 00:00:00 samba
root 20472 20466 0 10:26 ? 00:00:00 /usr/local/samba/sbin/smbd -D --option=serverrole check:inhibit=yes --foreground
root 20473 20465 0 10:26 ? 00:00:00 samba
root 20474 20465 0 10:26 ? 00:00:00 samba
root 20475 20465 0 10:26 ? 00:00:00 samba
root 20476 20465 0 10:26 ? 00:00:00 samba
root 20477 20465 0 10:26 ? 00:00:00 samba
root 20478 20465 0 10:26 ? 00:00:00 samba
root 20481 20472 0 10:26 ? 00:00:00 /usr/local/samba/sbin/smbd -D --option=serverrole check:inhibit=yes --foreground
root 21502 21310 0 11:15 pts/2 00:00:00 grep samba

samba已经在运行。

检查版本

# samba -V
Version 4.1.0pre1-GIT-55add52

运行配置命令后,应自动创建以下文件。

  • /usr/local/samba/private/named.conf
  • /usr/local/samba/private/dns/example.com.zone
  • /usr/local/samba/private/krb5.conf

现在检查我们是否能够使用 smbclient 连接 samba 服务器。

# smbclient -L localhost -U% 
Domain=[EXAMPLE] OS=[Unix] Server=[Samba 4.1.0pre1-GIT-55add52] 
        Sharename       Type      Comment 
        ---------       ----      ------- 
        netlogon        Disk 
        sysvol          Disk 
        IPC$          IPC       IPC Service (Samba 4.1.0pre1-GIT-55add52) 
 Domain=[EXAMPLE] OS=[Unix] Server=[Samba 4.1.0pre1-GIT-55add52] 
        Server               Comment 
        ---------            ------- 
        Workgroup            Master 
        --------        -----

当你运行上述命令时,你应该得到上面的输出。

配置 BIND 服务器

说明:

确保绑定版本是 9.8/9.9

# rpm -q bind
bind-9.8.2-0.17.rc1.el6_4.4.i686

这是我的 named.conf 文件的副本
在下面的允许查询部分中,我们可以使用“任何”参数或者提及要使用 DNS 服务器的网络子网,例如:192.168.0.0/24

# vi /etc/named.conf
 options {
        listen-on port 53 { 127.0.0.1; 10.10.20.42; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        forwarders { 8.8.8.8; 8.8.4.4; };
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { localhost; any; };
        recursion yes;
        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;
        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";
        managed-keys-directory "/var/named/dynamic";
 };
 logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
 };
 zone "." IN {
        type hint;
        file "named.ca";
 };
 include "/etc/named.rfc1912.zones";
 include "/etc/named.root.key";
 include "/usr/local/samba/private/named.conf";

重启你的命名服务器

# service named restart

检查 DNS 服务器是否在本地主机上工作

# ping google.com
PING google.com (74.125.236.32) 56(84) bytes of data.
64 bytes from maa03s04-in-f0.1e100.net (74.125.236.32): icmp_seq=1 ttl=56 time=19.1 ms
64 bytes from maa03s04-in-f0.1e100.net (74.125.236.32): icmp_seq=2 ttl=56 time=18.7 ms

如果你得到

unknown host google.com

再次检查绑定配置文件。
确保在 linux 机器中正确设置时区设置和时间,因为在某些情况下这是 DNS 服务器失败的另一个原因。

验证 Samba 服务器是否正在侦听 DNS 服务器

# host -t SRV _kerberos._udp.example.com.
_kerberos._udp.example.com has SRV record 0 100 88 test.example.com.
# host -t SRV _ldap._tcp.example.com.
_ldap._tcp.example.com has SRV record 0 100 389 test.example.com.
# host -t A samba.example.com.
samba.example.com has address 10.10.20.42

说明:

如果我们在使用上面的最后一个命令时出错

Host samba.example.com. not found: 3(NXDOMAIN)

然后按照下面提到的步骤

# vi /usr/local/samba/private/dns/example.com.zone
Add a last line
samba IN A 10.10.20.42

重新启动绑定服务器并再次尝试上述命令。
你应该得到肯定的答复。

配置 Kerberos

将 /etc 中的 krb5.conf 文件替换为在配置步骤后创建的文件 krb5.conf

示例 krb

# vi /etc/krb5.conf
[libdefaults]
default_realm = ${REALM}
dns_lookup_realm = false
dns_lookup_kdc = true

测试 Kerberos

# kinit administrator@EXAMPLE.COM
Password:
Warning: Your password will expire in 41 days on Wed Jan 17 10:26:06 2013
日期:2020-06-02 22:17:15 来源:oir作者:oir