2013年4月19日金曜日

Samba4 で Active Directory / インストール編 - わたしもやってみた -

はじめに

いつの間にか Samba4 がリリースされているではないか!
これで念願の Active Directory だ!!
仕事場では、あぁそれ Active Directory ね。
ふ~んって羨ましそうに横目にみていたのが
なんとわが家にも!
いい時代になったなぁと。

今回は、ビルドとインストール。
Samba4 HOWTO にある Build_Samba をベースに
先人の方々の情報も踏まえつつ、わたしもやってみたいと思います。
ではでは Getting Started!!

環境

OS ContOS 6.4(CentOS-6.4-i386-minimal.iso)
Samba 4.0.5
Bind 9.8.2
NTP ntp-4.2.6p5


環境設定

とりあえず SELinux と Fire Wall を止めておく。
ActiveDirectoryが構築できてから設定しょう…

まずは、SELinux から
/etc/selinux ディレクトリにある config ファイルを開き 以下のように変更する。

/etc/selinux/config
...
SELINUX=disabled
...

そして、Fire Wall

service iptables stop
service ip6tables stop
chkconfig iptables off
chkconfig ip6tables off

一応、確認する。

getenforce
iptables -L
ip6tables -L


ビルドに必要なライブラリーを揃える

何はともあれ yum の update から

yum update

そして、必要なライブラリーのインストール
…結構盛りだくさん。

yum install gcc libacl-devel libblkid-devel gnutls-devel \
      readline-devel python-devel gdb pkgconfig krb5-workstation \
      zlib-devel setroubleshoot-server \
      setroubleshoot-plugins policycoreutils-python \
      libsemanage-python setools-libs-python setools-libs \
      popt-devel libpcap-devel sqlite-devel libidn-devel \
      libxml2-devel libacl-devel libsepol-devel libattr-devel \
      keyutils-libs-devel cyrus-sasl-devel cups-devel

Samba4 の HOWTO 的には以上でよいらしいのだけど configure で perl が必要だといわれる。
また、バックエンドの DNS に Bind を使いたい。
それから、--with-ads も使いたい。などその他諸々で以下のライブラリーを追加することにした。

yum install bind bind-libs bind-utils wget\
      perl autoconf automake openldap-devel pam-devel


ビルドとインストール

いよいよ、Samba4 を make する。
作業フォルダは /root/work とします。
では、ソースを取ってきて展開するところまで

mkdir /root/work
cd /root/work
wget http://www.samba.org/samba/ftp/stable/samba-4.0.5.tar.gz
tar -zxvf samba-4.0.5.tar.gz
ソースの取得について

git から取ってくるのがいいらしいのだけど、チェックアウト?に時間が掛かったので
wget で gz にアーカイブされたものを取ってくることにした。

次に configure

cd /root/work/samba-4.0.5
./configure --with-ads --with-shared-modules=idmap_ad \
            --enable-debug --enable-selftest

仕上げに make と make install

make
make install

これで /usr/local/samba/ にインストールされる。
インストールできているか Version を確認してみる。

/usr/local/samba/bin/smbclient --version


起動スクリプトの作成

やっぱり、起動スクリプトは、ほしい。
ソースからインストールするとこのへんが無かったりするので大変だ!
/etc/rc.d/init.d ディレクトリに 以下のような内容でファイルを作成し samba4 の名前で保存する。

/etc/rc.d/init.d/samba4
#! /bin/bash
#
# samba4       Bring up/down samba4 service 
#
# chkconfig: - 90 10
# description: Activates/Deactivates all samba4 interfaces configured to \
#              start at boot time.
#
### BEGIN INIT INFO
# Provides: 
# Should-Start: 
# Short-Description: Bring up/down samba4
# Description: Bring up/down samba4
### END INIT INFO
# Source function library.
. /etc/init.d/functions

if [ -f /etc/sysconfig/samba4 ]; then
 . /etc/sysconfig/samba4
fi

CWD=$(pwd)
prog="samba4"

start() {
     # Attach irda device 
     echo -n $"Starting $prog: "
 /usr/local/samba/sbin/samba
 sleep 2
 if ps ax | grep -v "grep" | grep -q /samba/sbin/samba ; then success $"samba4 startup"; else failure $"samba4 startup"; fi
     echo
}
stop() {
     # Stop service.
     echo -n $"Shutting down $prog: "
 killall samba
 sleep 2
 if ps ax | grep -v "grep" | grep -q /samba/sbin/samba ; then failure $"samba4 shutdown"; else success $"samba4 shutdown"; fi
     echo
}
status() {
 /usr/local/samba/sbin/samba --show-build
}

# See how we were called.
case "$1" in
start)
 start
     ;;
stop)
 stop
     ;;
status)
 status irattach
 ;;
restart|reload)
 stop
 start
 ;;
*)
     echo $"Usage: $0 {start|stop|restart|status}"
     exit 1
esac

exit 0

サービスに登録する。

chmod 755 /etc/rc.d/init.d/samba4
chkconfig --add samba4
chkconfig samba4 on


NTP のインストール

これで、終わりと思いきや、まだ NTP の設定が必要なようです。
Active Directory では、それぞれのPCの時間が合っていないとうまく動かないとのことです。
yum でインストールしたいところなのですが
yum で入る NTP は、signed ntp が サポートされていないらしく(Version 4.2.6以上)
これがないと Active Directory の時間合わせがうまく動かないようです。
ここも、ソースからのインストールになってしまいます。

まずは、ソースを取ってきて展開するところまで
同じく作業フォルダは /root/work とします。

cd /root/work
wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.6p5.tar.gz
tar -zxvf ntp-4.2.6p5.tar.gz

次に configure そして make と make install

cd /root/work/ntp-4.2.6p5
./configure --enable-ntp-signd
make
make install

ここでもやはり、起動スクリプトがほしい…
/etc/rc.d/init.d ディレクトリに 以下のような内容でファイルを作成し ntp の名前で保存する。

/etc/rc.d/init.d/ntp
#! /bin/bash
#
# ntp Bring up/down ntp service
#
#chkconfig: - 99 30
#description: Bring up/down ntp
#
### BEGIN INIT INFO
# Provides:
# Should-Start:
# Short-Description: Bring up/down ntp
# Description: Bring up/down ntp
### END INIT INFO
# Source function library.
. /etc/init.d/functions
 
CWD=$(pwd)
NTPD=/usr/local/bin/ntpd
prog="ntp"
start() {
 # Attach irda device
 echo -n $"Starting $prog: "
 $NTPD -p /var/run/ntpd.pid
 sleep 2
 if ps ax | grep -v "grep" | grep -q $NTPD ; then success $"ntp startup"; else failure $"ntp startup"; fi
 echo
}
stop() {
# Stop service.
 echo -n $"Shutting down $prog: "
 kill -9 `cat /var/run/ntpd.pid` > /dev/null 2>&1
 sleep 2
 if ps ax | grep -v "grep" | grep -q $NTPD ; then failure $"ntp shutdown"; else success $"ntp shutdown"; fi
 echo
}
# See how we were called.
case "$1" in
start)
 start
 ;;
stop)
 stop
 ;;
restart|reload)
 stop
 start
 ;;
*)
 echo $"Usage: $0 {start|stop|restart}"
 exit 1
esac

exit 0

サービスに登録する。

chmod 755 /etc/rc.d/init.d/ntp
chkconfig --add ntp
chkconfig ntp on

設定ファイルを作成する。
ソースからインストールすると何もないようです…
/etc ディレクトリに 以下のような内容でファイルを作成し ntp.conf の名前で保存する。

/etc/ntp.conf
server 127.127.1.0
fudge 127.127.1.0 stratum 10
server 0.pool.ntp.org iburst prefer
server 1.pool.ntp.org iburst prefer
driftfile /var/lib/ntp/ntp.drift
logfile /var/log/ntp
ntpsigndsocket /usr/local/samba/var/lib/ntp_signd/
restrict default kod nomodify notrap nopeer mssntp
restrict 127.0.0.1
restrict 0.pool.ntp.org mask 255.255.255.255 nomodify notrap nopeer noquery
restrict 1.pool.ntp.org mask 255.255.255.255 nomodify notrap nopeer noquery

早速、確認の意味も含め時刻を合わせてみる。

ntpdate ntp.nict.jp


おわりに

やっぱり、ソースのインストールとなるといろいろ大変だなぁというのが正直なところ。
起動スクリプト、コマンドパス、ファイルパス、バージョンアップ…
yum でインストールできる日が早く来ないかなぁと思う。
イケイケの Fedora に 慎重派の CentOS わたしは、そんなイメージだ。
CentOS の yum は、まだ、先にかなぁ。

参考URL
https://wiki.samba.org/index.php/Samba4
https://wiki.samba.org/index.php/Build_Samba
https://wiki.samba.org/index.php/Samba_4/OS_Requirements
https://wiki.samba.org/index.php/Samba4/InitScript
https://wiki.samba.org/index.php/Configure_NTP
http://opentodo.net/2013/01/samba4-as-ad-domain-controller-on-centos-6/
http://d.hatena.ne.jp/rti7743/20110425/1303688263