LDAP Postfix Dovecotでメールサーバ(2)
まだ編集中
Vine Linux4.1でLDAPでログイン認証,メールサーバーの管理をするサーバーを構築した.
基本的に以下の本に書かれている方法にしたがっている.
nisサーバーの情報をmigrateする
authconfig
cd /usr/share/openldap/migration/
emacs migrate_common.ph
-
-
-
-
- -
-
-
-
$DEFAULT_BASE = "dc=labname,dc=hoge-u,dc=ac,dc=jp";
$DEFAULT_MAIL_DOMAIN = "labname.hoge-u.ac.jp";
-
-
-
-
-
-
- -
-
-
-
-
-
./migrate_all_nis_offine.sh ~/nis_migrate.ldif
Enter the NIS domain to import from (optional): labname-domain
No such map networks.byaddr. Reason: サーバドメインにそのようなマップはありません
Creating naming context entries...
Migrating groups...
Migrating hosts...
Migrating networks...
Migrating users...
Migrating protocols...
Migrating rpcs...
Migrating services...
Use of uninitialized value in string eq at /usr/share/openldap/migration/migrate_common.ph line 215.
Migrating netgroups...
Importing into LDAP...
Migrating netgroups (by user)...
Migrating netgroups (by host)...
Preparing LDAP database...
usage: slapadd [-v] [-d debuglevel] [-f configfile] [-F configdir] [-c]
[-g] [-n databasenumber | -b suffix]
[-l ldiffile] [-q] [-u] [-s] [-w]
Migration failed: saving failed LDIF to /tmp/nis.ldif.xg4782
Done.
/tmp/nis.ldif.xg4782から
Hosts Group Peopleの関係する部分だけ切り出す
fileの先頭の部分だけみればよい
切り出したものを
nis_migrate.ldif
にsave
-
-
-
-
-
- -
-
-
-
-
dn: ou=Hosts,dc=labname,dc=hoge-u,dc=ac,dc=jp
ou: Hosts
objectClass: top
objectClass: organizationalUnit
dn: cn=pc1name,ou=Hosts,dc=labname,dc=hoge-u,dc=ac,dc=jp
objectClass: top
objectClass: ipHost
objectClass: device
ipHostNumber: 192.168.1.3
cn: pc1name
...
dn: cn=staff,ou=Group,dc=labname,dc=hoge-u,dc=ac,dc=jp
objectClass: posixGroup
objectClass: top
cn: staff
userPassword: {crypt}!
gidNumber: 201
memberUid: name1
memberUid: name2
...
dn: uid=name1,ou=People,dc=labname,dc=hoge-u,dc=ac,dc=jp
uid: name1
cn: name1
objectClass: account
objectClass: posixAccount
objectClass: top
userPassword: {crypt}xxxxyyyy
loginShell: /bin/bash
uidNumber: 711
gidNumber: 200
homeDirectory: /home/name1
....
書き換える
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
dn: uid=name1,ou=People,dc=labname,dc=hoge-u,dc=ac,dc=jp
uid: name1
cn: name1
objectClass: inetOrgPerson #account から変える
objectClass: posixAccount
objectClass: top
userPassword: {crypt}xxxxyyyy
loginShell: /bin/bash
uidNumber: 711
gidNumber: 200
homeDirectory: /home/name1
sn: name1 #追記
mail:name1@labname.hoge-u.ac.jp #追記
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
以上で
必要な情報を取りだしたファイル
nis_migrate.ldif
ができた
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
ldap など必要なソフトをインストールする
Vine Linuxの場合
apt-get install openldap
など
RHELの場合
yum install openldap-servers
など
−−−−−
LDAPの設定
基本的に上記の本の通りでよい
/etc/openldap/slapd.conf
defoultから書き足した、または変更したもの
include /etc/openldap/schema/dnszone.schema
include /etc/openldap/schema/misc.schema
access to attribute=userPassword
by dn="ou=People,dc=labname,dc=hoge-u,dc=ac,dc=jp"
by anonymous auth
by self write
by * none
acess to *
by dn="cn=Manager,dc=labname,dc=hoge-u,dc=ac,dc=jp" write
by self write
by * read
database bdb
suffix "dc=labname,dc=hoge-u,dc=ac,dc=jp""
rootdn "cn=Manager,dc=labname,dc=hoge-u,dc=ac,dc=jp""
rootpw {SSHA}xxxxyyyyy
#/usr/sbin/slappawwdh -h "{SSHA}"コマンドで生成する
−−−−−−−−−−
Vine linuxの場合,
/etc/openldap/slapd.conf
の設定が終わって
/etc/rc.d/init.d/ldap restart
した後で
chown ldap /var/lib/ldap/*
を行う必要がある場合がある. おまじないとして一度実行しておいておいた方がいい.
cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
init.ldif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
dn: dc=labname,dc=hoge-u,dc=ac,dc=jp
objectclass: dcObject
objectclass: organization
o: labname
dc: labname
dn: cn=Manager,dc=labname,dc=hoge-u,dc=ac,dc=jp
objectclass: organizationalRole
cn: Manager
dn: ou=People,dc=labname,dc=hoge-u,dc=ac,dc=jp
objectclass: organizationalUnit
ou: People
dn: ou=Group,dc=labname,dc=hoge-u,dc=ac,dc=jp
objectclass: organizationalUnit
ou: Group
dn: ou=Service,dc=labname,dc=hoge-u,dc=ac,dc=jp
objectclass: organizationalUnit
ou: Service
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
ldapadd -x -D "cn=Manager,dc=labname,dc=hoge-u,dc=ac,dc=jp" -W -f init.ldif
mtaadmin.ldif
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
dn: cn=mtaAdmin,ou=Service,dc=labname,dc=hoge-u,dc=ac,dc=jp
cn: mtaAdmin
objectclass: organizationalPerson
objectclass:top
sn:mtaAdmin
userPassword: {SSHA}xxxxyyyzzz #mail管理者パスワード"mtaAdmin"を同様に生成
ldapadd -x -D "cn=Manager,dc=labname,dc=hoge-u,dc=ac,dc=jp" -W -f mtaadmin.ldif
ここでmigrateしたデータを登録
ldapadd -x -D "cn=Manager,dc=labname,dc=hoge-u,dc=ac,dc=jp" -W -f nis_migrate.ldif
/sbin/chkconfig ldap on
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
ldapの設定終わり
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
postfixの設定
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
/etc/postfix/main.cf
を以下のところだけ書き換えまたは追記する
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
myhostname =servername.labname.hoge-u.ac.jp
mydomain = labname.hoge-u.ac.jp
virtual_mailbox_domains =labname.hoge-u.ac.jp
virtual_mailbox_maps = ldap:/etc/postfix/ldap-account.cf
virtual_mailbox_base = /var/spool/mail
virtual_minimum_uid = 0
virtual_uid_maps = 8 #/etc/passwdのmailのuid
virtual_gid_maps = 12 #/etc/passwdのmailのgid
alias_maps = ldap:/etc/postfix/ldap-alias.cf
alias_database = hash:/etc/aliases
home_mailbox = Maildir/
mail_spool_directory = /var/spool/mail
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
server_host = localhost
search_base = ou=People,dc=labname,dc=hoge-u,dc=ac,dc=jp
query_filter =(mail=%s)
result_attribute = uid
result_format = %s/Maildir/
scope =sub
bind = yes
bind_dn = cn=mtaAdmin, dc=labname,dc=hoge-u,dc=ac,dc=jp
bind_pw = mtaadmin
-
-
- -
-
-
-
- server_host = localhost
-
search_base = ou=aliases,ou=Postfix,ou=Service,dc=labname,dc=hoge-u,dc=ac,dc=jp
query_filter =(cn=%s)
result_attribute = rfc822MailMember
result_format = %s/Maildir/
scope =one
bind = yes
bind_dn = cn=mtaAdmin, dc=labname,dc=hoge-u,dc=ac,dc=jp
bind_pw = mtaadmin
-
- -
mail alias
postfix-alias-init.ldif
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
dn: ou=Postfix, ou=Service, dc=labname,dc=hoge-u,dc=ac,dc=jp
objectclass: organizationalUnit
ou:Postfix
dn: ou=aliases, ou=Postfix, ou=Service,dc=labname,dc=hoge-u,dc=ac,dc=jp
objectclass: organizationalUnit
ou: aliases
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
ldapadd -x -D "cn=Manager,dc=labname,dc=hoge-u,dc=ac,dc=jp" -W -f postfix-alias-init.ldif
postfix-alias-test.ldif
-
-
-
- -
-
-
dn: cn=test,ou=aliases, ou=Postfix, ou=Service, dc=labname,dc=hoge-u,dc=ac,dc=jp
cn:test
objectclass: nisMailAlias
objectclass:top
rfc822MailMember:test111@labname.hoge-u.ac.jp
rfc822MailMember:test222@labname.hoge-u.ac.jp
-
-
-
- -
-
-
ldapadd -x -D "cn=Manager,dc=labname,dc=hoge-u,dc=ac,dc=jp" -W -f postfix-alias-test.ldif
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
/etc/rc.d/init.d/postfix restart
/sbin/chkconfig --add postfix
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
dovecot
−−−−−−−
/etc/dovecot.conf
-
-
-
-
- -
-
-
-
protocols = imap imaps pop3 pop3s
log_path =/tmp/dovecot-log
mail_location = mbox:~/mail:INBOX=/var/mail/%u
##comment outする
#passdb pam {
#
#}
passdb ldap {
args = /etc/dovecot-ldap.conf
}
#uid gid は/etc/postfix/main.cfで設定した
#virtual_uid_maps
#virtual_gid_maps
#と同じ値にする
userdb static {
args = uid=8 gid=12 home=/var/spool/mail/%u
}
userdb ldap {
args = /etc/dovecot-ldap.conf
}
#vine linuxの場合のみ設定する.RHEL5 では設定しない.
pop3_uidl_format = %u
-
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
hosts =127.0.0.1
dn = cn=mtaAdmin,ou=Service,dc=labname,dc=hoge-u,dc=ac,dc=jp
dnpass ="mtaAdmin"
base =ou=People,dc=labname,dc=hoge-u,dc=ac,dc=jp
scope = subtree
pass_attrs = uid=user,userPassword=password
pass_filter = (&(objectClass=posixAccount)(uid=%u))
-
-
-
-
- -
-
-
-
/etc/rc.d/init.d/dovecot restart
/sbin/chkconfig --add dovecot
-
-
-
-
-
-
- -
-
-
-
-
-
最後に
pop3
ldap
smtp
のポートをfirewallにあける
以上です