Поиск по этому блогу

пятница, 5 февраля 2010 г.

Домен на линуксе

Если нам нужна база с централизованным хранением пользоветелей, доменный логон на рабочие станции и нет острой необходимости в групповых политиках, то можно и на линуксе домен поднять.


В этом нам помогут: Ubuntu Server 9.04, Samba и OpenLDAP.
В одной фирме у меня в распоряжении уже был линуксовый домен на умирающей Fedora. С ним бял связан рад проблем, которые не решались из-за устаревания софта и невозможности корректного обновления. Решено было развернуть домен на новой системе и перенести туда старую базу. В убунте, начиная с релиза 8.10, есть одна неприятная, на первый взгляд особенность — OpenLDAP. Ибо это «какой-то неправильный LDAP». Первое время пытался понять как его нужно конфигурировать, но потом плюнул и собрался было оставить затею с убунтой, но вовремя набрел на это замечательное How-to: http://ubuntuforums.org/showthread.php?t=1184288&highlight=ubuntu+9.04+pdc. Смысл прост: если нам не нравится новый подход к настройке лдапа, то мы будем настраивать его по-старому =). Как основу взял этот ман, но с небольшими лирическими отступлениями.

# sudo su
# aptitude update
# aptitude upgrade
# aptitude install slapd ldap-utils db4.2-util samba smbclient samba-doc smbldap-tools ldap-auth-client

Для того, чтобы вернуться к старой схеме конфигурировани лдапа, в файле /etc/default/slapd меняем:
...
SLAPD_CONF=/etc/ldap/slapd.conf
...

Копируем схему самбы в каталог лдапа:

# gunzip /usr/share/doc/samba-doc/examples/LDAP/samba.schema.gz
# cp -v /usr/share/doc/samba-doc/examples/LDAP/samba.schema /etc/ldap/schema

Генерируем пароль лдап админа:

# slappasswd

Пишем конфиг лдапа:

# nano /etc/ldap/slapd.conf
# Remember to replace suffix "dc=ubuntudom,dc=org" with your domain name
# Change the rootpw entry with the results from slappaswd (Must match the same you pasted on init.ldif)

# /etc/ldap/slapd.conf
# This is the main slapd configuration file. See slapd.conf(5) for more
# info on the configuration options.

#######################################################################
# Global Directives:

# Features to permit
#allow bind_v2

# Schema and objectClass definitions
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/nis.schema
include /etc/ldap/schema/inetorgperson.schema
include /etc/ldap/schema/samba.schema
include /etc/ldap/schema/misc.schema

# Where the pid file is put. The init.d script
# will not stop the server if you change this.
pidfile /var/run/slapd/slapd.pid

# List of arguments that were passed to the server
argsfile /var/run/slapd/slapd.args

# Read slapd.conf(5) for possible values
loglevel 0

# Where the dynamically loaded modules are stored
modulepath /usr/lib/ldap
moduleload back_bdb

# The maximum number of entries that is returned for a search operation
sizelimit 500

# The tool-threads parameter sets the actual amount of cpu's that is used
# for indexing.
tool-threads 1

#######################################################################
# Specific Backend Directives for bdb:
# Backend specific directives apply to this backend until another
# 'backend' directive occurs
backend bdb
#checkpoint 512 30

#######################################################################
# Specific Backend Directives for 'other':
# Backend specific directives apply to this backend until another
# 'backend' directive occurs
#backend <other>

#######################################################################
# Specific Directives for database #1, of type bdb:
# Database specific directives apply to this databasse until another
# 'database' directive occurs
database bdb

# The base of your directory in database #1
suffix "dc=ubuntudom,dc=org"

# rootdn directive for specifying a superuser on the database. This is needed
# for syncrepl.
rootdn "cn=admin,dc=ubuntudom,dc=org"
rootpw {SSHA}iPFTqrtwr3yT3XGQot2wxCuuljKA9vMU

# Where the database file are physically stored for database #1
directory "/var/lib/ldap"

# For the Debian package we use 2MB as default but be sure to update this
# value if you have plenty of RAM
dbconfig set_cachesize 0 2097152 0

# Sven Hartge reported that he had to set this value incredibly high
# to get slapd running at all. See http://bugs.debian.org/303057
# for more information.

# Number of objects that can be locked at the same time.
dbconfig set_lk_max_objects 1500
# Number of locks (both requested and granted)
dbconfig set_lk_max_locks 1500
# Number of lockers
dbconfig set_lk_max_lockers 1500

# Indexing options for database #1
#index objectClass eq, pres
index ou,cn,sn,mail,givenname eq,pres,sub
index uidNumber,gidNumber,memberUid eq,pres
index loginShell eq,pres
index uniqueMember eq,pres
index uid pres,sub,eq
index displayName pres,sub,eq
index sambaSID eq
index sambaPrimaryGroupSID eq
index sambaDomainName eq
index default sub
#index uid pres,eq,sub

# Save the time that the entry gets modified, for database #1
lastmod on

# Where to store the replica logs for database #1
# replogfile /var/lib/ldap/replog

# The userPassword by default can be changed
# by the entry owning it if they are authenticated.
# Others should not be able to see it, except the
# admin entry below
# These access lines apply to database #1 only
access to attrs=userPassword,shadowLastChange
by dn="cn=admin,dc=ubuntudom,dc=org" write
by anonymous auth
by self write
by * none

# Ensure read access to the base for things like
# supportedSASLMechanisms. Without this you may
# have problems with SASL not knowing what
# mechanisms are available and the like.
# Note that this is covered by the 'access to *'
# ACL below too but if you change that as people
# are wont to do you'll still need this if you
# want SASL (and possible other things) to work
# happily.
access to dn.base="" by * read

# The admin dn has full write access, everyone else
# can read everything.
access to *
by dn="cn=admin,dc=ubuntudom,dc=org" write
by * read

# For Netscape Roaming support, each user gets a roaming
# profile for which they have write access to
#access to dn=".*,ou=Roaming,o=morsnet"
# by dn="cn=admin,dc=example,dc=ch" write
# by dnattr=owner write

#######################################################################
# Specific Directives for database #2, of type 'other' (can be bdb too):
# Database specific directives apply to this databasse until another
# 'database' directive occurs
#database <other>

# The base of your directory for database #2
#suffix "dc=debian,dc=org"

Дальше удаляем базу, созданную при установке slapd, добавляем свои данные и запускаем сервер с новой базой.
Как добавлять данные в новый домен можно посмотреть по ссылке выше, я же делаю импорт со старого контроллера.

На старом dc:

# /etc/init.d/slapd stop
# slapcat -v -l master.ldif
# scp master.ldif suparoot@newdc:/home/suparoot
На новом dc:

# /etc/init.d/slapd stop
# rm -rf /var/lib/ldap/*
# slapadd -v -l /home/suparoot/master.ldif
# chown -R openldap:openldap /var/lib/ldap
# /etc/init.d/slapd start

Следующая команда должна вывести всю базу:

# ldapsearch -xLLL -b «dc=ubuntudom»

Дальше настроим самбу:

# mkdir -v -p /var/lib/samba/netlogon
# chmod 775 /var/lib/samba/netlogon
# nano /etc/samba/smb.conf
[global]
# Domain name ..
workgroup = UBUNTUDOM
# Server name - as seen by Windows PCs ..
netbios name = PDC
server string = Domain Controller
# Be a PDC ..
domain logons = Yes
domain master = Yes
preferred master = yes
# Be a WINS server ..
wins support = Yes

obey pam restrictions = Yes
dns proxy = No
os level = 255
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0
panic action = /usr/share/samba/panic-action %d
pam password change = Yes

# Allows users on WinXP PCs to change their password when they press Ctrl-Alt-Del
unix password sync = no
ldap passwd sync = yes

# Printing from PCs will go via CUPS ..
#load printers = yes
#printing = cups
#printcap name = cups

load printers = no
show add printer wizard = no
printcap name = /dev/null
disable spoolss = yes

# Use LDAP for Samba user accounts and groups ..
passdb backend = ldapsam:ldap://localhost

# This must match init.ldif ..
ldap suffix = dc=ubuntudom,dc=org
# The password for cn=admin MUST be stored in /etc/samba/secrets.tdb
# This is done by running 'sudo smbpasswd -w'.
ldap admin dn = cn=admin,dc=ubuntudom,dc=org

# 4 OUs that Samba uses when creating user accounts, computer accounts, etc.
# (Because we are using smbldap-tools, call them 'Users', 'Computers', etc.)
ldap machine suffix = ou=Computers
ldap user suffix = ou=SambaUsers
ldap group suffix = ou=SambaGroups
ldap idmap suffix = ou=SambaGroups
# Samba and LDAP server are on the same server in this example.
ldap ssl = no

# Scripts for Samba to use if it creates users, groups, etc.
add user script = /usr/sbin/smbldap-useradd -m '%u'
delete user script = /usr/sbin/smbldap-userdel %u
add group script = /usr/sbin/smbldap-groupadd -p '%g'
delete group script = /usr/sbin/smbldap-groupdel '%g'
add user to group script = /usr/sbin/smbldap-groupmod -m '%u' '%g'
delete user from group script = /usr/sbin/smbldap-groupmod -x '%u' '%g'
set primary group script = /usr/sbin/smbldap-usermod -g '%g' '%u'
add machine script = /usr/sbin/smbldap-useradd -w '%u'

# Values used when a new user is created ..
# (Note: '%L' does not work properly with smbldap-tools 0.9.4-1)
logon drive =
logon home =
logon path =
logon script = logon.bat

# This is required for Windows XP client ..
server signing = auto
server schannel = Auto

[netlogon]
comment = Network Logon Service
path = /var/lib/samba/netlogon
admin users = root
guest ok = Yes
browseable = Yes
writable = Yes

Добавляем пароль админа и перезапускаем самбу:

# /etc/init.d/samba restart
# smbpasswd -W
...
# /etc/init.d/samba restart

Дальше настраиваем smbldap-tools — набор утилит, при помощи которых добавляются и удаляются пользователи, меняется их группа и т.д.
Сначала выдергиваем SID нашего контроллера:

# net getlocalsid

Затем скриптом настраиваем наши утилиты:

# gunzip /usr/share/doc/smbldap-tools/configure.pl.gz
# chmod +x /usr/share/doc/smbldap-tools/configure.pl
# cd /usr/share/doc/smbldap-tools/
# ./configure.pl

И добавляем в базу стандартные группы:

# smbldap-populate

Дальше нужно переиндексировать базу:

# etc/init.d/slapd stop
# slapindex
# chown openldap:openldap /var/lib/ldap/*
# /etc/init.d/slapd start

Добавляем в базу наших админов и проверяем:

# smbldap-useradd -a -m -P alexander
# /usr/sbin/smbldap-groupmod -m 'alexander' 'Administrators'
# /usr/sbin/smbldap-groupmod -m 'root' 'Administrators'
# smbldap-groupshow Administrators
# smbldap-usershow alexander
# getent group

# getent passwd

О том, как добавить линуксовых клиентов я писал тут

1 комментарий:

  1. Почему воруем статьи с чужих блогов? Где ссылка на источник?

    ОтветитьУдалить