DC(Domain Controller)作成
DC(Domain Controller) は、最近だとSamba4でできるみたい。
なので、DC 用の仮想マシンを CentOS8 + Samba4 で、構築してみる。
仮想マシンを作って、CentOS8 をインストール(最小構成のインストールで、最低限のセットアップ)。
ホスト名やIP、ゲートウェイなどは、構想図に合わせて、設定を実施。
CentOS8 からは yum から dnf になっているようなので、dnf でパッケージの更新。
# dnf -y upgrade
ログイン時、Failed to set locale, defaulting to C
のようなエラーが出る場合、言語パックが入っていないためにでるみたい。
日本語でセットアップして、コンソールが英語のみの場合、英語の言語パックをインストールすればOK
# dnf -y install langpacks-en
NTP で時刻合わせするために、CentOS8 の NTP クライアントの chrony をインストール。
NTP の個別設定が必要な場合は、chrony.conf を編集してください。
# dnf -y install chrony # vi /etc/chrony.conf # systemctl restart chronyd # systemctl status chronyd # chronyc sources
Samba4 インストールして、DC を構築します。
CentOS8 の Samba パッケージには、必要なコマンドとかがないので、ソースからビルドする必要があります。
ビルド準備として、ビルドに必要なパッケージをインストール。
参考: Samba Wiki
# dnf -y install bind-utils # dnf -y install dnf-plugins-core # dnf -y install epel-release # dnf -y config-manager --set-enabled PowerTools # dnf -y update # dnf -y install docbook-style-xsl gcc gdb gnutls-devel gpgme-devel jansson-devel \ keyutils-libs-devel krb5-workstation libacl-devel libaio-devel \ libarchive-devel libattr-devel libblkid-devel libtasn1 libtasn1-tools \ libxml2-devel libxslt lmdb-devel openldap-devel pam-devel perl \ perl-ExtUtils-MakeMaker perl-Parse-Yapp popt-devel python3-cryptography \ python3-dns python3-gpg python36-devel readline-devel rpcgen systemd-devel \ tar zlib-devel cups-devel # dnf clean all
Samba ソースをダウンロードして、ビルド。
configure にオプションを追加して、systemd で制御する service ファイルを作成するようにします。
また、service ファイルが systemd が認識する場所に格納されないので、コピーして、自動起動できるようにしておく。
(configure のオプションで解決できると思うが。。。)
有効は、smb.conf がないので、エラーになるから後で。
# curl -OL https://download.samba.org/pub/samba/samba-latest.tar.gz # tar zxvf samba-latest.tar.gz # cd samba-4.12.0/ # ./configure --with-systemd --systemd-install-services # make # make install # cp /usr/local/samba/lib/systemd/system/smb.service /usr/lib/systemd/system/ # cp /usr/local/samba/lib/systemd/system/samba.service /usr/lib/systemd/system/ # cp /usr/local/samba/lib/systemd/system/nmb.service /usr/lib/systemd/system/ # cp /usr/local/samba/lib/systemd/system/winbind.service /usr/lib/systemd/system/ # systemctl daemon-reload # systemctl list-unit-files --type=service
.bash_profile の PATH に、Samba のパスを設定。
# vi ~/.bash_profile # cat ~/.bash_profile if [ -f ~/.bashrc ]; then . ~/.bashrc fi PATH=/usr/local/samba/bin:/usr/local/samba/sbin:$PATH:$HOME/bin export PATH # source ~/.bash_profile # samba -V
Firewall に設定を追加して、DC としてのポートを許可する。
# firewall-cmd --add-port={53,88,389,464}/{tcp,udp} --permanent # firewall-cmd --add-port={135,139,445,636}/tcp --permanent # firewall-cmd --add-port=137-138/udp --permanent # firewall-cmd --add-port=1024-5000/tcp --permanent # firewall-cmd --add-port=3268-3269/tcp --permanent # firewall-cmd --add-port=49152-65535/tcp --permanent # firewall-cmd --reload
SELinux を permissive に。
SELinux の設定を正しくすれば、enforcing のままでも動作するはず。
# vi /etc/selinux/config # cat /etc/selinux/config SELINUX=permissive SELINUXTYPE=targeted # reboot
Samba-tool を実行して、ドメイン設定を行う。
基本は、デフォルトで OK なので、Enter で。
# samba-tool domain provision --use-rfc2307 --interactive Realm [LAB.LOCAL]: Domain [LAB]: Server Role (dc, member, standalone) [dc]: DNS backend (SAMBA_INTERNAL, BIND9_FLATFILE, BIND9_DLZ, NONE) [SAMBA_INTERNAL]: DNS forwarder IP address (write 'none' to disable forwarding) [192.168.50.254]: Administrator password: Retype password:
# systemctl start samba # systemctl enable samba
Samba 動作確認。
# smbclient -L localhost -U% Sharename Type Comment --------- ---- ------- sysvol Disk netlogon Disk IPC$ IPC IPC Service (Samba 4.12.0) SMB1 disabled -- no workgroup available # smbclient //localhost/netlogon -UAdministrator -c 'ls' Enter LAB\Administrator's password: . D 0 Wed Apr 1 21:58:55 2020 .. D 0 Wed Apr 1 21:59:01 2020 52403200 blocks of size 1024. 49538124 blocks available
DC が DNS になるので、DNS 設定を書き換え。
nmtui で、NIC の DNS サーバーを DC サーバーの IP アドレス、ドメイン検索に、"lab.local" を設定する。
また、ルータの DHCP サーバーで配布する DNS サーバーアドレスも、この DC サーバーの IP アドレスに変えておくとよいかも。
# nmtui # reboot # cat /etc/resolv.conf search lab.local nameserver 192.168.200.1
DNS 動作確認
# samba-tool dns zonelist 127.0.0.1 -U Administrator
# host dc.lab.local dc.lab.local has address 192.168.200.1 # host -t SRV _ldap._tcp.lab.local _ldap._tcp.lab.local has SRV record 0 100 389 dc.lab.local. # host -t SRV _kerberos._tcp.lab.local _kerberos._tcp.lab.local has SRV record 0 100 88 dc.lab.local. # host www.yahoo.co.jp www.yahoo.co.jp is an alias for edge12.g.yimg.jp. edge12.g.yimg.jp has address 182.22.28.252
Kerberos 認証関係の設定。
# mv /etc/krb5.conf krb5.conf.org # cp -p /usr/local/samba/private/krb5.conf /etc/krb5.conf # cat /usr/local/samba/private/krb5.conf [libdefaults] default_realm = LAB.LOCAL dns_lookup_realm = false dns_lookup_kdc = true [realms] LAB.LOCAL = { default_domain = lab.local } [domain_realm] dc = LAB.LOCAL # kinit Administrator@LAB.LOCAL Password for Administrator@LAB.LOCAL: Warning: Your password will expire in 41 days on 2020年05月13日 21時59分01秒 # klist Ticket cache: FILE:/tmp/krb5cc_0 Default principal: Administrator@LAB.LOCAL Valid starting Expires Service principal 2020-04-01T22:13:30 2020-04-02T08:13:30 krbtgt/LAB.LOCAL@LAB.LOCAL renew until 2020-04-02T22:13:26
ユーザのパスワードポリシー設定。
複雑性OFF # samba-tool domain passwordsettings set --complexity=off パスワード長 8文字以上 # samba-tool domain passwordsettings set --min-pwd-length=8 パスワード有効期間 無期限 # samba-tool domain passwordsettings set --max-pwd-age=0 # samba-tool domain passwordsettings set --min-pwd-age=0 確認 # samba-tool domain passwordsettings show Password information for domain 'DC=lab,DC=local' Password complexity: off Store plaintext passwords: off Password history length: 24 Minimum password length: 8 Minimum password age (days): 0 Maximum password age (days): 0 Account lockout duration (mins): 30 Account lockout threshold (attempts): 0 Reset account lockout after (mins): 30
ここまでくれば、DC として動くようになっているはず!