Samba 4.9.xでActive Directoryを1から立てる


samba 4.10.2にアップデートした際にpython3関連で変更があったため「Samba 4.10.xでActive Directoryを1から立てる」という記事で内容を若干更新しています。


Samba 4.9.4に更新した際に、いろいろ修正点があったので更新。なお、この記事は、Active Directoryサーバとして使用することについてのみ解説しています。ファイルサーバとして使用することについては記述していません。

なお、過去バージョンの履歴。2018年3月版「Samba 4.7.xでActive Directoryを1から立てる」、2016年7月版「Samba 4.4.xでActive Directoryを1から立てる」、2014年2月版「Samba 4.xでActive Directoryを1から立てる

さて、Linux上でSambaを使ってActive Directoryサーバを立てるメリットは以下の点です。

その1:Windows Serverを買わなくてもActive Directoryを作れる

WindowsのCALを買わずにActive Directory環境の構築ができるため、ライセンス費用の低減になります。

その2:Active Directoryユーザの作成などのユーザ管理をWindowsマシンからWindows標準ツールで行える

ユーザーの作成/変更、コンピューターアカウントの作成、DNSの管理など、Active Directoryの管理を行う際に頻繁に使う操作については、WindowsのActive Directory管理ツールやDNS管理ツールを使用することができる。このため、普段はLinuxのCLIコマンド(samba-toolsやnetコマンドなど)を使う必要はない。

Active Directoryに参加しているWindowsマシンに、Windows機能のActive Directory管理ツールを追加インストールし、Active Directoryの管理者にてログオンすることで、管理ができる。

その3:sambaの設定は難しくない

10年ぐらい前のsambaでは、DNSサーバやLDAPサーバをsambaとは別に用意し、連携する必要がありました。いまのsambaはDNSサーバとLDAPサーバの機能が統合されているため設定が容易になりました。

Active Directory名とActive Directory上の役割、管理者パスワードを設定するぐらいで環境を作成することができます。

逆にデメリットとしてどのようなものがあるか?

その1:Active Directoryの全機能が搭載されていない

ドメイン/フォレストの機能レベルがWindows Server 2012R2レベルまで対応になったものの、「Kerberos関連機能が未搭載」となっています。(samba公式wiki「Raising the Functional Levels」)

「Windows Server 2008 R2」レベルまでであればフルサポートしています。このレベルであれば、Windows Server 2016環境でフェイルオーバークラスターマネージャーでクラスタを組むこともできました。(samba 4.7ぐらいから可能になった)


手順は、公式の「Setting up Samba as an Active Directory Domain Controller」と「Package Dependencies Required to Build Samba」を参照しながら実施していきます。

  1. CentOS7の最小インストールを実施

2. /etc/hostsの修正

自ホスト名を/etc/hostsに追加。
追加の際は、ショートのホスト名と、ドメイン付きのFQDNの両方を列挙すること。

[root@adserver ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.17.44.40    adserver adserver.adosakana.local
[root@adserver ~]#

3. 好みに応じて使うツールをインストール

セッションが途中で切れても良い様に「screen」か「tmux」と、ファイルダウンロードするためにwgetかcurlをインストールします。

[root@adserver ~]# yum install wget screen
<略>
[root@adserver ~]#

4. 必要なパッケージをインストール

Samba公式の「Package Dependencies Required to Build Samba」に記載されているパッケージをインストール

[root@adserver ~]# yum install attr bind-utils docbook-style-xsl gcc gdb krb5-workstation \
       libsemanage-python libxslt perl perl-ExtUtils-MakeMaker \
       perl-Parse-Yapp perl-Test-Base pkgconfig policycoreutils-python \
       python2-crypto gnutls-devel libattr-devel keyutils-libs-devel \
       libacl-devel libaio-devel libblkid-devel libxml2-devel openldap-devel \
       pam-devel popt-devel python-devel readline-devel zlib-devel systemd-devel \
       lmdb-devel jansson-devel gpgme-devel pygpgme libarchive-devel
<略>
[root@adserver ~]#

ここで問題発生・・・上記の説明に「RHEL7ではEPELレポジトリを追加する必要があるが、CentOS7とScientific Linux7では不要」とあるが、CentOS7環境で試してみると「perl-Test-Base」と「lmdb-devel」は無い。

ちなみにこの状態でsamab 4.9.xのconfigureを実行すると「Samba AD DC and –enable-selftest requires lmdb 0.9.16 or later」と言われて失敗します。

EPELレポジトリを追加してから、必要なパッケージのインストールをやり直します。(なお、perl-Test-Baseに関連付いていろいろパッケージが追加されます。)

[root@adserver ~]# yum install epel-release.noarch
<略>
[root@adserver ~]#

5. sambaのtar.gzをダウンロード

samba.orgからsambaをダウンロードします。

[root@adserver ~]# wget https://download.samba.org/pub/samba/stable/samba-4.9.4.tar.gz
--2018-12-28 13:10:22--  https://download.samba.org/pub/samba/stable/samba-4.9.4.tar.gz
download.samba.org (download.samba.org) をDNSに問いあわせています... 144.76.82.156, 2a01:4f8:192:486::443:2
download.samba.org (download.samba.org)|144.76.82.156|:443 に接続しています...  接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 18053738 (17M) [application/gzip]
`samba-4.9.4.tar.gz' に保存中

100%[======================================>] 18,053,738  3.65MB/s 時間 5.9s

2018-12-28 13:10:29 (2.93 MB/s) - `samba-4.9.4.tar.gz' へ保存完了 [18053738/18053738]

[root@adserver ~]# 

6. configure実施

[root@adserver ~]# tar xfz samba-4.9.4.tar.gz
[root@adserver ~]# cd samba-4.9.4/
[root@adserver samba-4.9.4]#  ./configure
Checking for program gcc or cc           : /usr/bin/gcc
Checking for program cpp                 : /usr/bin/cpp
Checking for program ar                  : /usr/bin/ar
Checking for program ranlib              : /usr/bin/ranlib
<略>
Checking if compiler accepts -fstack-protector                                                  : no
Checking if compiler accepts -fstack-clash-protection                                           : yes
'configure' finished successfully (1m24.346s)
[root@adserver samba-4.9.4]#

7. make & make install

[root@adserver samba-4.9.4]# make
WAF_MAKE=1 python ./buildtools/bin/waf build
Waf: Entering directory `/root/samba-4.9.4/bin'
<略>
Note: Writing nmblookup4.1
[4039/4039] Generating man/samba-gpupdate.8
Note: Writing samba-gpupdate.8
Waf: Leaving directory `/root/samba-4.9.4/bin'
'build' finished successfully (15m49.153s)
[root@adserver samba-4.9.4]# make install
WAF_MAKE=1 python ./buildtools/bin/waf install
Waf: Entering directory `/root/samba-4.9.4/bin'
        Selected embedded Heimdal build
Checking project rules ...
<略>
* installing bin/default/pidl/Parse::Pidl::Wireshark::NDR.3pm as /usr/local/samba/share/man/man3/Parse::Pidl::Wireshark::NDR.3pm
Waf: Leaving directory `/root/samba-4.9.4/bin'
'install' finished successfully (3m38.208s)
[root@adserver samba-4.9.4]#

8. インストール完了確認

インストールされたsambaのバージョンを確認します。

[root@adserver samba-4.9.4]# /usr/local/samba/sbin/samba -V
Version 4.9.4
[root@adserver samba-4.9.4]#

9. Active Directoryのセットアップ

ドメイン「adosakana.local」を作成します。
また、sambaの機能を使ってAD DNSを構築するので「SAMBA_INTERNAL」を選択します。

なお、「–use-rfc2307」はADにNIS連携機能を追加するオプションです。AD上にUnix用のUID/GID/shell情報なども格納できるようにします。Samba環境では有効にしておくべきものです。

また、セットアップ中、「Merge the contents of this file with your system krb5.conf or replace it with this one. Do not create a symlink!」とメッセージが出ますが、これは、この手順で自動生成されたkrb5.confをシステムのもつkrb5.confと統合しろ、というお知らせです。後の手順で対処します。

[root@adserver samba-4.9.4]# /usr/local/samba/bin/samba-tool domain provision --use-rfc2307 --interactive
Realm [example.com]:  ADOSAKANA.LOCAL
Domain [ADOSAKANA]:
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) [172.30.50.100]:  172.30.50.100
Administrator password:
Retype 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
Unable to determine the DomainSID, can not enforce uniqueness constraint on local domainSIDs

Adding DomainDN: DC=adosakana,DC=local
Adding configuration container
Setting up sam.ldb schema
Setting up sam.ldb configuration data
Setting up display specifiers
Modifying display specifiers and extended rights
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=adosakana,DC=local
Creating DomainDnsZones and ForestDnsZones partitions
Populating DomainDnsZones and ForestDnsZones partitions
Setting up sam.ldb rootDSE marking as synchronized
Fixing provision GUIDs
A Kerberos configuration suitable for Samba AD has been generated at /usr/local/samba/private/krb5.conf
Merge the contents of this file with your system krb5.conf or replace it with this one. Do not create a symlink!
Setting up fake yp server settings
Once the above files are installed, your Samba AD server will be ready to use
Server Role:           active directory domain controller
Hostname:              wk70
NetBIOS Domain:        ADOSAKANA
DNS Domain:            adosakana.local
DOMAIN SID:            S-1-5-21-3471449246-245784766-327389652
[root@adserver samba-4.9.4]#

10. sambaを起動

sambaが起動していないことを確認した上で、sambaを起動します。

[root@adserver samba-4.9.4]# ps -ef|grep samba
root      45678  17315  0 14:16 pts/0    00:00:00 grep --color=auto samba
[root@adserver samba-4.9.4]# /usr/local/samba/sbin/samba
[root@adserver samba-4.9.4]# ps -ef|grep samba
root      45684      1 18 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45686  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45687  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45688  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45689  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45690  45684 36 14:16 ?        00:00:01 /usr/local/samba/sbin/samba
root      45691  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45692  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45693  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45694  45686  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45695  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45696  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45697  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45698  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45699  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45700  45694  9 14:16 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      45701  45695  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45702  45701  9 14:16 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      45705  45698  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45706  45705 22 14:16 ?        00:00:00 python /usr/local/samba/sbin/samba_dnsupdate
root      45716  45700  0 14:16 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      45717  45700  0 14:16 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      45718  45702  1 14:16 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      45719  45702  2 14:16 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      45721  45702  0 14:16 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      45722  45700  0 14:16 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      45724  17315  0 14:16 pts/0    00:00:00 grep --color=auto samba
[root@adserver samba-4.9.4]#

11. 動作確認

CentOS内部からSMB接続を行うテストを実施。

[root@adserver samba-4.9.4]# /usr/local/samba/bin/smbclient --version
Version 4.9.4
[root@adserver samba-4.9.4]# /usr/local/samba/bin/smbclient -L localhost -U%

        Sharename       Type      Comment
        ---------       ----      -------
        netlogon        Disk
        sysvol          Disk
        IPC$            IPC       IPC Service (Samba 4.9.4)
Reconnecting with SMB1 for workgroup listing.

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------
[root@adserver samba-4.9.4]#

以前は「Domain=[ADOSAKANA.LOCAL] OS=[Unix] Server=[Samba x.y.z]」という出力もあったのですが、Samba 4.7以降では無くなっています。

netlogon共有にAdministrator権限でアクセスできるか確認。

[root@adserver samba-4.9.4]# /usr/local/samba/bin/smbclient //localhost/netlogon -UAdministrator -c 'ls'
Enter ADOSAKANA\Administrator's password:
  .                                   D        0  Fri Dec 28 14:13:09 2018
  ..                                  D        0  Fri Dec 28 14:13:15 2018

                36936068 blocks of size 1024. 33797580 blocks available
[root@adserver samba-4.9.4]#

12. AD DNSの動作テスト

AD DNSが想定通りに動作しているかテストします。

まず、どんなzoneが登録されているのか確認します。

[root@adserver samba-4.9.4]# /usr/local/samba/bin/samba-tool dns zonelist 127.0.0.1 -U Administrator
Password for [ADOSAKANA\Administrator]:
  2 zone(s) found

  pszZoneName                 : adosakana.local
  Flags                       : DNS_RPC_ZONE_DSINTEGRATED DNS_RPC_ZONE_UPDATE_SECURE
  ZoneType                    : DNS_ZONE_TYPE_PRIMARY
  Version                     : 50
  dwDpFlags                   : DNS_DP_AUTOCREATED DNS_DP_DOMAIN_DEFAULT DNS_DP_ENLISTED
  pszDpFqdn                   : DomainDnsZones.adosakana.local

  pszZoneName                 : _msdcs.adosakana.local
  Flags                       : DNS_RPC_ZONE_DSINTEGRATED DNS_RPC_ZONE_UPDATE_SECURE
  ZoneType                    : DNS_ZONE_TYPE_PRIMARY
  Version                     : 50
  dwDpFlags                   : DNS_DP_AUTOCREATED DNS_DP_FOREST_DEFAULT DNS_DP_ENLISTED
  pszDpFqdn                   : ForestDnsZones.adosakana.local
[root@adserver samba-4.9.4]#

Active Directoryで使用するDNSのSRVレコードが登録されているかをhostコマンドを使って確認します。

[root@adserver samba-4.9.4]# host -t SRV _ldap._tcp.adosakana.local 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:

_ldap._tcp.adosakana.local has SRV record 0 100 389 adserver.adosakana.local.
[root@adserver samba-4.9.4]# host -t SRV _kerberos._udp.adosakana.local 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:

_kerberos._udp.adosakana.local has SRV record 0 100 88 adserver.adosakana.local.
[root@adserver samba-4.9.4]#

ADサーバのホスト名が登録されているか確認します。

[root@adserver samba-4.9.4]# host -t A adserver.adosakana.local 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:

adserver.adosakana.local has address 172.17.15.70
[root@adserver samba-4.9.4]#

13. DNSサーバの変更

ADサーバの/etc/resolv.confを、ADサーバ自身を使う様に書き換えます。

14. /etc/krb5.conf の変更

/usr/local/samba/private/krb5.conf に元となるものが自動生成されているので、それを使用する。

[root@adserver samba-4.9.4]# ls -l /etc/krb5.conf /usr/local/samba/private/krb5.conf
-rw-r--r--. 1 root root 641 10月 30 23:40 /etc/krb5.conf
-rw-rw-rw-. 1 root root  96 12月 28 14:13 /usr/local/samba/private/krb5.conf
[root@adserver samba-4.9.4]# cat /usr/local/samba/private/krb5.conf
[libdefaults]
        default_realm = ADOSAKANA.LOCAL
        dns_lookup_realm = false
        dns_lookup_kdc = true
[root@adserver samba-4.9.4]# cp /usr/local/samba/private/krb5.conf /etc/krb5.conf
cp: `/etc/krb5.conf' を上書きしますか? y
[root@adserver samba-4.9.4]#

15. Kerberosの動作確認

「kinit administrator@ドメイン名」を実行して確認します。

[root@adserver samba-4.9.4]# kinit administrator@ADOSAKANA.LOCAL
Password for administrator@ADOSAKANA.LOCAL:
Warning: Your password will expire in 41 days on 2019年02月08日 14時13分15秒
[root@adserver samba-4.9.4]#

正常に設定されていれば、上記の様にAdministratorユーザのパスワード有効期限が表示されます。

「klist」コマンドでも確認することが出来ます。

[root@adserver samba-4.9.4]# klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: administrator@ADOSAKANA.LOCAL

Valid starting       Expires              Service principal
2018-12-28T14:26:25  2018-12-29T00:26:25  krbtgt/ADOSAKANA.LOCAL@ADOSAKANA.LOCAL
        renew until 2018-12-29T14:26:22
[root@adserver samba-4.9.4]#

なお、ドメイン名指定の大文字/小文字を間違えると下記の様なエラーとなります。

[root@adserver ~]# kinit administrator@adosakana.local
Password for administrator@adosakana.local:
kinit: KDC reply did not match expectations while getting initial credentials
[root@adserver ~]#

DNSサーバ指定が誤っている場合は下記の様なエラーです。

[root@adserver ~]# kinit administrator@ADOSAKANA.LOCAL
kinit: Cannot resolve servers for KDC in realm "ADOSAKANA.LOCAL" while getting initial credentials
[root@adserver ~]#

16. フォレストとドメインの機能レベル確認

作成したActive Directoryのドメインの機能レベルとフォレストの機能レベルを確認します。

[root@adserver samba-4.9.4]# /usr/local/samba/bin/samba-tool domain level show
Domain and forest function level for domain 'DC=adosakana,DC=local'

Forest function level: (Windows) 2008 R2
Domain function level: (Windows) 2008 R2
Lowest function level of a DC: (Windows) 2008 R2
[root@adserver samba-4.9.4]#

Samba 4.9.4でもWindows Server 2008R2が標準設定となっています。

17. firewalldの設定

CentOS7ではfirewalldによりポートが制限されています。
現状を「firewall-cmd –list-all」で確認します。

[root@adserver samba-4.9.4]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources:
  services: ssh dhcpv6-client
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
[root@adserver samba-4.9.4]#

開けるべきポートのテンプレートがあらかじめ用意されているので「firewall-cmd –get-services」を実行して確認します 。

[root@adserver samba-4.9.4]# firewall-cmd --get-services
RH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry docker-swarm dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git gre high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target jenkins kadmin kerberos kibana klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls managesieve mdns minidlna mongodb mosh mountd ms-wbt mssql murmur mysql nfs nfs3 nmea-0183 nrpe ntp openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius redis rpc-bind rsh rsyncd samba samba-client sane sip sips smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh syncthing syncthing-gui synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server
[root@adserver samba-4.9.4]#
サービス ポート プロトコル firewalld定義
DNS 53 tcp/udp dns
Kerberos 88 tcp/udp kerberos,freeipa-ldap,freeipa-ldaps
End Point Mapper (DCE/RPC Locator Service) 135 tcp freeipa-trust
NetBIOS Name Service 137 udp samba,samba-client
NetBIOS Datagram 138 udp samba,samba-client,freeipa-trust
NetBIOS Session 139 tcp samba,freeipa-trust
LDAP 389 tcp/udp freeipa-trust(ldap,freeipa-ldapはtcpのみ)
SMB over TCP 445 tcp samba,freeipa-trust(freeipa-trustはudpも含む)
Kerberos kpasswd 464 tcp/udp kpasswd,freeipa-ldap,freeipa-ldaps
LDAPS 636 tcp ldaps,freeipa-ldaps
Dynamic RPC Ports(4.7以前) 1024-1300 tcp freeipa-trust
Dynamic RPC Ports(samba 4.7以降) 49152-65535 tcp ?
Global Catalog 3268 tcp freeipa-trust
Global Catalog SSL 3269 tcp なし

・firewalldの定義「samba」「dns」「freeipa-ldaps」「freeipa-trust」を使用
・「Dynamic RPC Ports(samba 4.7以降):49152-65535」を追加するか、smb.confで「rpc server port」を定義するか。
・「Global Catalog SSL:3269」を追加

[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-service=samba
success
[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-service=dns
success
[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-service=freeipa-ldaps
success
[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-service=freeipa-trust
success
[root@adserver samba-4.9.4]# firewall-cmd --reload
success
[root@adserver samba-4.9.4]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: ssh dhcpv6-client samba dns freeipa-ldaps freeipa-trust
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

[root@adserver samba-4.9.4]#
[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-port=49152-65535/tcp
success
[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-port=3269/tcp
success
[root@adserver samba-4.9.4]# firewall-cmd --reload
success
[root@adserver samba-4.9.4]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: ssh dhcpv6-client samba dns freeipa-ldaps freeipa-trust
  ports: 49152-65535/tcp 3269/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

[root@adserver samba-4.9.4]#

18. systemdへの登録

systemdへの登録については「Managing the Samba AD DC Service Using Systemd」を参照のこと
CentOS6の場合は「Managing the Samba AD DC Service Using an Init Script

以上で設定は終了です。

Steamlink launcher for OSMCをラズパイ3のOSMCに導入


ラズパイ3をメディアプレイヤーとして置こうと思うんだけど、そこに「Steam Link now in BETA on Raspberry Pi」をインストールして、Steam Linkの端末としても使いたい。

そういうことができるのかを調べて見た。すると、「Release: Steamlink Launcher for Kodi (OSMC only)」というのを発見。ソフトウェアの配布は「https://github.com/swetoast/steamlink-launcher」で行われている。

ラズパイをメディアプレイヤーとして使うディストリビューションとして「LibreELEC」とか「OSMC」がある。

今回のプラグインはOSMC用ということなので、OSMCのSDカードイメージで起動してみる・・・が・・・「Install failed: can’t mount root」というエラー。

SDカード内にある「install.log」にログがある、というので確認してみると・・・

Thu Jan 1 00:00:07 1970 Starting OSMC installer
Thu Jan 1 00:00:13 1970 Detecting device we are running on
Thu Jan 1 00:00:13 1970 Mounting boot filesystem
Thu Jan 1 00:00:13 1970 Trying to mount to MNT_BOOT (/mnt/boot)
Thu Jan 1 00:00:13 1970 Using device->boot: /dev/mmcblk0p1 and FS: fat32
Thu Jan 1 00:00:13 1970 No preseed file was found
Thu Jan 1 00:00:13 1970 Creating root partition
Thu Jan 1 00:00:13 1970 From a root partition of /dev/mmcblk0p2, I have deduced a base device of /dev/mmcblk0
Thu Jan 1 00:00:10 1970 Determined 255 MB as end of first partition
Thu Jan 1 00:00:10 1970 Calling mkpart for device: /dev/mmcblk0 and fs: ext4 with start 257M and end 100%
Thu Jan 1 00:00:11 1970 Calling fmtpart for partition /dev/mmcblk0p2 and fstype ext4
Thu Jan 1 00:01:23 1970 Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=2 blocks, Stripe width=1024 blocks
969136 inodes, 3869440 blocks
193472 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3963617280
119 block groups
32768 blocks per group, 32768 fragments per group
8144 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables:   0/119       done                            
Writing inode tables:   0/119       done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:   0/119  2/119  4/119  6/119 50/119       done


Thu Jan 1 00:01:23 1970 Mounting root
Thu Jan 1 00:01:23 1970 Trying to mount to MNT_ROOT (/mnt/root)
Thu Jan 1 00:01:23 1970 Using device->root: /dev/mmcblk0p2
Thu Jan 1 00:01:23 1970 Error occured trying to mount root of /dev/mmcblk0p2
Thu Jan 1 00:01:23 1970 Halting Install. Error message was: can't mount root

たいしたことは書かれてない感じで・・・なぜ?

違うmicroSDカードを使ったところ、正常に起動が完了した。

まずは、Bluetoothコントローラのペアリング設定は「My OSMC」の「Network」でBluetoothを有効にしてから行う。

次に、sshでログイン(OMSCのUsernames and passwords)して、

$ sudo apt update
$ sudo apt install xz-utils
$ curl -#Of http://media.steampowered.com/steamlink/rpi/steamlink_1.0.7_armhf.deb
$ sudo dpkg -i steamlink_1.0.7_armhf.deb
$ steamlink

「steamlink」を実行するとしばらく追加のソフトインストールとかが実行されたあと、HDMI出力にsteamlinkの画面が出てくるのが確認できる。

で・・・この後、kodiのアドオンとして「Steamlink Launcher for OSMC」をインストールするわけなんだけど・・・うちではこのアドオンがうまくインストールできたように見えない・・・どうすれば


v0.0.4がリリースされたので試してみたところ、やはりうまくプラグインがインストールできた様子がない・・・ただ、v0.0.3からの変更点を見るとzipファイル内のディレクトリ構造を変えたとある。

試しに他のpluginの構造を調べて見るとzipファイル内にはプラグイン名のディレクトリを作る必要があるにも係わらず、v0.0.4のzipファイルではディレクトリが存在していない。

というわけで、zipファイルを作成しなおしたところ、問題なく動作するようになりました。

このことを報告したところ送ったzipファイルがそのまま採用されました。

2018/12/29配布のv0.0.4aは正常に動作します。

PowerCLIを使ってvSphere仮想マシンをテンプレートから連続デプロイ


RedHat OpenShift環境を作るためのansible hostsファイルがすごく難解。

おかげでいろんなhostsファイル記述を実験する羽目に・・・

仮想マシンテンプレートを作ったあと、仮想マシンのカスタマイズ仕様を元にデプロイするだけとは言え、マスタ2台、インフラノード2台、ノード2台とかを毎回作り直すのが面倒。

簡略化するためにPowerCLIを使って一括作成できるようなスクリプトを作成した。

$vcenter="testvcenter"       # 接続先vCenterホスト名 or IPアドレス
$vcenterusername="administrator@vsphere.local" # vCenterユーザ名
$vcenterpassword="test"       # vCenterパスワード
$vmtemplatename="rhel7-os311" # 仮想マシンテンプレート名
$vmcustomizespec="rhel7-base" # 仮想マシンのカスタマイズ仕様名
$datastore="vsphere10"          # デプロイ先データストア
$esxserver="172.17.44.10"       # デプロイ先ESXiサーバ
$subnetmask="255.255.0.0"       # 仮想マシンのサブネット
$defaultgw="172.17.0.1"         # 仮想マシンのデフォルトゲートウェイ

connect-vcenter -Server $vcenter -User $vcenterusername -Password $vcenterpassword -WarningAction 0

deployvm -vmname "master221" -ipaddr "172.17.44.221" -cpu 4 -memory 16
deployvm -vmname "master222" -ipaddr "172.17.44.222" -cpu 4 -memory 16
deployvm -vmname "infra-node223" -ipaddr "172.17.44.223" -cpu 2 -memory 8
deployvm -vmname "node224" -ipaddr "172.17.44.224" -cpu 2 -memory 8
deployvm -vmname "node225" -ipaddr "172.17.44.225" -cpu 2 -memory 8

Disconnect-VIServer -Confirm:$false


###########################################
### 関数名: connect-vcenter
### 役割:   指定したvCenterサーバに接続
### 入力: 「-Server vCenterサーバ名」 
###      「-User ユーザ名」
###      「-Password パスワード」 
###      「-Credential パスワードの暗号化文字列」
###       「-Password」か「-Credential」かは排他指定
### 注意: パイプライン処理不可
###########################################
function connect-vcenter{
    param(
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$Server,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$User,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$Password,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][SecureString]$Credential
    )

    # $global:DefaultVIServers が存在している場合はすでにvCenterに接続されているので処理を飛ばす
    #  vROpsと異なり接続がなくなったら変数もなくなるようだが、念のためこちらも接続中のユーザ名があることを確認
    if([String]::IsNullOrEmpty($global:DefaultVIServers.User)){
        Try {
            if($Credential){
                $pscredential=New-Object System.Management.Automation.PSCredential($User,$Credential)
                Connect-VIServer -Server $Server -Credential $pscredential -WarningAction 0 | Out-Null
                if($? -eq $false){ throw }
            }else{
                Connect-VIServer -Server $Server -User $User -Password $Password -WarningAction 0 | Out-Null
                if($? -eq $false){ throw }
            }
        } Catch {
            Write-Host "vCenterサーバへの接続に失敗しました"
            Write-Host $Error[0]
            exit 1
        }
    }
    return
}

###########################################
### 関数名: deployvm
### 役割:   仮想マシンテンプレートから仮想マシンをデプロイ
### 入力: 「-vmname 仮想マシンホスト名」 
###      「-ipaddr IPアドレス」
###      「-cpu CPU数」 
###      「-memory メモリ容量」
### 注意: 簡略化のため、下記の前提がある
###    デプロイ先のESXiサーバを、グローバル変数 $esxserver で指定していること
###    デプロイ先のデータストアを、グローバル変数 $datastore で指定していること
###    仮想マシンテンプレートを、グローバル変数 $vmtemplatename で指定していること(作成済みであること)
###    仮想マシンのカスタマイズ仕様を、グローバル変数 $vmcustomizespec で指定していること(作成済みであること)
###    グローバル変数で仮想マシンのサブネットマスク $subnetmask とデフォルトゲートウェイ $defaultgw を指定していること
###########################################
function deployvm{
    Param(
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$vmname,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$ipaddr,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][int]$cpu,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][int]$memory
    )
    Get-OSCustomizationSpec $vmcustomizespec | New-OSCustomizationSpec -Name vmtemp -Type NonPersistent
    Get-OSCustomizationNicMapping vmtemp | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ipaddr -SubnetMask $subnetmask -DefaultGateway $defaultgw
    Get-OSCustomizationSpec vmtemp | Set-OSCustomizationSpec -NamingScheme vm

    New-VM -Name $vmname -VMHost $esxserver -Template $vmtemplatename -OSCustomizationSpec vmtemp -Datastore $datastore -Confirm:$false
    Set-VM -VM $vmname -MemoryGB $memory -NumCpu $cpu -Confirm:$false
    Start-VM -VM $vmname -Confirm:$false
    Remove-OSCustomizationSpec vmtemp -Confirm:$false
}

なお、vCenterへの接続部分がごっつい関数にしてあるのは、他で使ったものの流用であるためです。

deployvmで行っていることの詳細については「PowerShellを使ってVMwareのテンプレートからデプロイで「既存のカスタマイズ仕様を使用してカスタマイズする」を行う方法」を参照のこと。

WindowsServer 2016にVMware PowerCLIをインストールする際のメモ


Windows Server 2016環境にVMware PowerCLIをインストールしたので、その手順のメモ
なお、2020年4月以降、PowerShell GalleryへのアクセスがTLS 1.2必須となったため、後半に書かれている対処方法を行う必要がある。

(1) PowerShellを起動

(2)「Install-Module -Name VMware.PowerCLI」を実行

途中、NuGetプロバイダーのインストールと、PowerCLIがあるレポジトリの追加が要求されるので、両方許可する。

Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator> Install-Module -Name VMware.PowerCLI

続行するには NuGet プロバイダーが必要です
PowerShellGet で NuGet ベースのリポジトリを操作するには、'2.8.5.201' 以降のバージョンの NuGet
プロバイダーが必要です。NuGet プロバイダーは 'C:\Program Files\PackageManagement\ProviderAssemblies' または
'C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssemblies'
に配置する必要があります。'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force' を実行して NuGet
プロバイダーをインストールすることもできます。今すぐ PowerShellGet で NuGet
プロバイダーをインストールしてインポートしますか?
[Y] はい(Y)  [N] いいえ(N)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): y

信頼されていないリポジトリ
信頼されていないリポジトリからモジュールをインストールしようとしています。このリポジトリを信頼する場合は、Set-PSReposit
ory コマンドレットを実行して、リポジトリの InstallationPolicy の値を変更してください。'PSGallery'
からモジュールをインストールしますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"): y
PS C:\Users\Administrator>

(3) 以上!


なお、その後のメモ

自己証明書を使ってるvCenterサーバに接続しようとすると下記のエラーがでる。

PS C:\Users\Administrator> Connect-VIServer -Server vcenterサーバ -User administrator@vsphere.local -Password "パスワード"
Connect-VIServer : 2018/12/20 11:25:08  Connect-VIServer                Error: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you'd like to connect once or to add a permanent exception for this server.
Additional Information: 機関 'vcenterサーバ' との SSL/TLS のセキュリティで保護されているチャネルに対する信頼関係を確立できませんでした。
発生場所 行:1 文字:1
+ Connect-VIServer -Server vcenterサーバ -User administrator@vsphere.loca ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : セキュリティ エラー: (: ) [Connect-VIServer]、ViSecurityNegotiationException
    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_CertificateError,VMware.VimAutomation.ViCore.
   Cmdlets.Commands.ConnectVIServer

PS C:\Users\Administrator>

以前は「」オプションで回避できていたが、今のPowerCLIでは「Set-PowerCLIConfiguration -InvalidCertificateAction Ignore」を設定する必要がある。(参考:New Release: VMware PowerCLI 10.0.0 )

Users\Administrator> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore

Perform operation?
Performing operation 'Update PowerCLI configuration.'?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): y

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout
                                                                                                  Seconds
-----    -----------     ------------------- ------------------------  -------------------------- -------------------
Session  UseSystemProxy  Multiple            Ignore                    True                       300
User                                         Ignore
AllUsers


PS C:\Users\Administrator>

これで接続できるようになる。

PS C:\Users\Administrator> Connect-VIServer -Server vCenterサーバ -User administrator@vsphere.local -Password "パスワード"

Name                           Port  User
----                           ----  ----
vCenterサーバ                    443   VSPHERE.LOCAL\Administrator

PS C:\Users\Administrator>

2020/07/16追記

久しぶりにやってみたら、以下のエラーになった。

PS C:\Users\Administrator> Install-Module -Name VMware.PowerCLI

続行するには NuGet プロバイダーが必要です
PowerShellGet で NuGet ベースのリポジトリを操作するには、'2.8.5.201' 以降のバージョンの NuGet
プロバイダーが必要です。NuGet プロバイダーは 'C:\Program Files\PackageManagement\ProviderAssemblies' または
'C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssemblies'
に配置する必要があります。'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force' を実行して NuGet
プロバイダーをインストールすることもできます。今すぐ PowerShellGet で NuGet
プロバイダーをインストールしてインポートしますか?
[Y] はい(Y)  [N] いいえ(N)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"):
警告: URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' から '' へダウンロードできません。
警告: 利用可能なプロバイダーの一覧をダウンロードできません。インターネット接続を確認してください。
PackageManagement\Install-PackageProvider : プロバイダー 'NuGet' について、指定された検索条件に一致するものが見つかりま
せんでした。パッケージ プロバイダーには 'PackageManagement' タグと 'Provider' タグが必要です。指定されたパッケージにこ
れらのタグがあるかどうかを確認してください。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7405 文字:21
+ ...     $null = PackageManagement\Install-PackageProvider -Name $script:N ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac
   kageProvider]、Exception
    + FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePro
   vider

PackageManagement\Import-PackageProvider : プロバイダー名 'NuGet' について、指定された検索条件に一致するものが見つかり
ませんでした。'Get-PackageProvider -ListAvailable' を使用して、このプロバイダーがシステム上に存在するか確認してください
。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7411 文字:21
+ ...     $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (NuGet:String) [Import-PackageProvider]、Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProv
   ider

警告: URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' から '' へダウンロードできません。
警告: 利用可能なプロバイダーの一覧をダウンロードできません。インターネット接続を確認してください。
PackageManagement\Get-PackageProvider : パッケージ プロバイダー 'NuGet' が見つかりません。まだインポートされていない可
能性があります。'Get-PackageProvider -ListAvailable' を実行してみてください。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7415 文字:30
+ ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvi
   der], Exception
    + FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPacka
   geProvider

Install-Module : NuGet ベースのリポジトリを操作するためには、NuGet プロバイダーが必要です。'2.8.5.201' 以降のバージョン
の NuGet プロバイダーがインストールされていることを確認してください。
発生場所 行:1 文字:1
+ Install-Module -Name VMware.PowerCLI
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Install-Module]、InvalidOperationException
    + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module

PS C:\Users\Administrator>

しかし、該当サーバでブラウザから「https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409」にアクセスしてみると、正常にファイルが取得できる。

調べて見ると、TLS 1.2アクセス必須となったためのエラーのようである。
 MasayaSawada「NuGet がmsg:unabletodownload エラーでインストールできない!
 PowerShell devblog「PowerShell Gallery TLS Support

現状SSL3とTLS1のサポートとなっている設定をTLS1.2サポートにする、という設定変更を行うことになる。

現状値の確認と変更は下記の様に行う。

PS C:\Users\Administrator> [Net.ServicePointManager]::SecurityProtocol
Ssl3, Tls
PS C:\Users\Administrator> [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
PS C:\Users\Administrator> [Net.ServicePointManager]::SecurityProtocol
Tls12
PS C:\Users\Administrator>

これを設定した後に「Install-Module -Name VMware.PowerCLI」を再実行することでダウンロードとインストールが実施されます。

なお、下記サイトに書かれている様に「[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12」というコマンドは保存されない設定を行うものであるため、PowerShell窓を閉じてしまうと元の設定に戻ります。
 しばたテックブログ「Windows PowerShellとTLS 1.2

Hyper-V統合サービスのバージョン確認


Hyper-V上でWindowsを使う場合、Hyper-V統合サービスをインストールする必要がある・・・というのが昔の設定。

いまは・・・というかWindows Server 2016以降はWindows Updateによる提供に代わりました。

これにより、古い資料では、ゲスト上にHyper-V統合サービスがインストールされているかどうかをPowerShell上で「Get-VM | Select Name, IntegrationServicesVersion」を実行し、バージョンを確認する、とかなっていたものが使えなくなっています。

Windows Server 2016環境では「
IntegrationServicesVersion」は「0.0」になります。

では、いまは、どうやってIntegration Sevices Versionを確認するのかと言えば、ゲストOS上で「REG QUERY “HKLM\Software\Microsoft\Virtual Machine\Auto” /v IntegrationServicesVersion」を実行することで確認します。いままでと異なり、ホストOS側では確認できないという点に注意が必要です。

参考資料 「クラスターの検証を実行した際に、Hyper-V 統合サービスのバージョン検証で警告が発生する」 「Manage Hyper-V Integration Services