SOGo
SOGo 提供了一个富含 AJAX 的 Web 界面,并通过使用 CalDAV、CardDAV 和 GroupDAV 等标准协议以及 Microsoft ActiveSync 支持多个原生客户端。本文解释了如何使用 SOGo 设置群件服务器。
安装
注意事项
SOGo 可以使用许多不同的用户身份验证源,包括但不限于 Active Directory、OpenLDAP、MySQL/MariaDB、PostgreSQL,如果您包含 PAM,可能还有许多其他来源。本文将重点介绍使用集中管理的用户数据库进行身份验证,并提供全局地址列表。
此外,必须使用 mariadb 或 postgresql 来存储用户的日历和地址簿。在撰写本文时,SOGo 文档明确偏好 MariaDB(或 MySQL),但如果您已经安装了 PostgreSQL,则使用它可能更有意义。也可能支持其他 SQL 实现,但目前未涵盖。
最后,目前有两个版本的 SOGo 正在积极维护。SOGo-2.x 使用类似于桌面客户端的外观和感觉,而 SOGo-3.x 使用更现代的界面,借鉴了 Google 使用 AngularJS。两个版本之间的说明和配置是可互换的。
先决条件
- 对于本地数据库,安装 MySQL 或 PostgreSQL。
- 对于本地邮件服务器,安装 Dovecot 和 Postfix。
- 对于本地 Web 服务器,安装 Apache HTTP 服务器 或 nginx。
初始 Web 服务器配置
Apache
按照 Apache HTTP 服务器 中的说明安装和配置 apache 并配置 TLS 连接。将 SOGo 添加到 Apache 配置,将以下行追加到 /etc/httpd/conf/httpd.conf
文件或 VirtualHost 条目的末尾
... # Include SOGo configuration include conf/extra/SOGo.conf
如果尚未完成,请在 /etc/httpd/conf/httpd.conf
中取消注释 mod_xml2enc 和所需的代理模块 mod_proxy{,_http,_html}
# cp /etc/httpd/conf/httpd.conf{,.bak} # sed /mod_xml2enc\.so/s/#// -i /etc/httpd/conf/httpd.conf # sed /mod_proxy\.so/s/#// -i /etc/httpd/conf/httpd.conf # sed /mod_proxy_http\.so/s/#// -i /etc/httpd/conf/httpd.conf # sed /mod_proxy_html\.so/s/#// -i /etc/httpd/conf/httpd.conf
编辑 /etc/httpd/conf/extra/SOGo.conf
文件并修改以下行(将 mail.domain.tld 替换为您所需配置的适当主机名)
... ## adjust the following to your configuration RequestHeader set "x-webobjects-server-port" "443" RequestHeader set "x-webobjects-server-name" "mail.domain.tld" RequestHeader set "x-webobjects-server-url" "https://mail.domain.tld" ...
nginx
如果使用 nginx 作为 Web 服务器,您将仅在 443 上进行配置,SSL 证书必须在配置之前就位。将以下内容添加到 /etc/nginx/nginx.conf
server { listen 443; root /usr/lib/GNUstep/SOGo/WebServerResources/; server_name mail.domain.tld server_tokens off; client_max_body_size 100M; index index.php index.html index.htm; autoindex off; ssl on; ssl_certificate path /path/to/your/certfile; #eg. /etc/ssl/certs/keyfile.crt ssl_certificate_key /path/to/your/keyfile; #eg /etc/ssl/private/keyfile.key ssl_session_cache shared:SSL:10m; #optional ssl_stapling on; #optional ssl_stapling_verify on; #optional ssl_trusted_certificate /etc/ssl/private/cacert-stapeling.pem; #optional resolver 8.8.4.4 8.8.8.8 valid=300s; #optionalresolver_timeout 10s; ssl_prefer_server_ciphers on; #optional ssl_dhparam /etc/ssl/certs/dhparam.pem; #optional add_header Strict-Transport-Security max-age=63072000; #optional add_header X-Frame-Options DENY; #optional add_header X-Content-Type-Options nosniff; location = / { rewrite ^ https://$server_name/SOGo; allow all; } location = /principals/ { rewrite ^ https://$server_name/SOGo/dav; allow all; } location ^~/SOGo { proxy_pass http://127.0.0.1:20000; proxy_redirect http://127.0.0.1:20000 default; # forward user's IP address proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header x-webobjects-server-protocol HTTP/1.0; proxy_set_header x-webobjects-remote-host 127.0.0.1; proxy_set_header x-webobjects-server-name $server_name; proxy_set_header x-webobjects-server-url $scheme://$host; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; client_max_body_size 50m; client_body_buffer_size 128k; break; } location /SOGo.woa/WebServerResources/ { alias /usr/lib/GNUstep/SOGo/WebServerResources/; allow all; } location /SOGo/WebServerResources/ { alias /usr/lib/GNUstep/SOGo/WebServerResources/; allow all; } location ^/SOGo/so/ControlPanel/Products/([^/]*)/Resources/(.*)$ { alias /usr/lib/GNUstep/SOGo/$1.SOGo/Resources/$2; } location ^/SOGo/so/ControlPanel/Products/[^/]*UI/Resources/.*\.(jpg|png|gif|css|js)$ { alias /usr/lib/GNUstep/SOGo/$1.SOGo/Resources/$2; } }
启动并测试 Web 访问
创建状态目录并启动服务
# mkdir /var/run/sogo # chown sogo:sogo /var/run/sogo # chown sogo:sogo /etc/sogo/sogo.conf # chmod 0644 /etc/sogo/sogo.conf
然后启用并启动 sogo
和 httpd
或 nginx
服务。
打开浏览器并访问 http://mail.domain.tld/SOGo/(对于 Apache)或 https://mail.domain.tld/SOGo/(对于 nginx)。暂时不要尝试登录,只需验证您可以连接并获得登录屏幕,因为身份验证源尚未设置。
SOGo 数据库配置
MySQL/MariaDB
如果您尚未这样做,请使用以下命令创建第一个 MySQL/MariaDB 数据库
# mysql_install_db --user=mysql --basedir=/usr/ --ldata=/var/lib/mysql/
启用并启动 mariadb
,然后以 root 用户身份进入 MySQL shell
# mysql -u root
在 mysql 提示符下,输入以下命令(将 SogoPW 替换为安全密码)
CREATE DATABASE sogo; CREATE USER 'sogo'@'localhost' IDENTIFIED BY 'SogoPW'; GRANT ALL PRIVILEGES ON `sogo`.* TO 'sogo'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;
从之前的 PostgreSQL 配置迁移
如果您之前使用过 PostgreSQL,则可以使用 sogo-tool 备份和恢复将用户数据迁移到 MySQL/MariaDB。详细信息显然是特定于站点的,但此示例应适用于大多数情况。使用以下命令备份完整的 sogo 数据库
# mkdir /root/sogo-backup # sogo-tool backup /root/sogo-backup ALL
现在停止 sogo 守护程序,停止 postgresql(如果未用于其他目的),并重新配置 sogo (/etc/sogo/sogo.conf),同时使用 sogo 用户和 sogo 数据库,保留最后一个路径元素(请参见下面的示例)。
要恢复所有用户数据,请运行以下命令
# for user in `ls -d /root/sogo-backup/*` do sogo-tool restore -f ALL /root/sogo-backup $(basename $user) done
只需重启 sogo 即可继续使用 MySQL/MariaDB。
PostgreSQL
如果您选择使用 PostgreSQL 而不是 MySQL/MariaDB,则旧的说明已保留以方便使用。如果这是一个新安装,建议您仅使用 MySQL/MariaDB 来存储 sogo/openchange 数据。
初始化默认数据库并启动 PostgreSQL(请务必将 en_US.UTF-8 替换为适合您安装的区域设置)
# mkdir -p /var/lib/postgres/data # chown -R postgres:postgres /var/lib/postgres # su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'"
然后启动并启用 postgresql
服务。
为 PostgreSQL 创建 sogo 用户和 sogo DB(不要为 sogo 用户选择强密码,只需使用“sogo”即可,这只是暂时的,稍后会更改)
# su - postgres $ createuser --no-superuser --no-createdb --no-createrole --encrypted --pwprompt sogo $ createdb -O sogo sogo
编辑 openchange DB 的访问配置
# cp /var/lib/postgres/data/pg_hba.conf{,.bak} # sed \ 's/D$/D\n\n#Configuration for OpenChange/' \ -i /var/lib/postgres/data/pg_hba.conf # sed \ 's/ange$/ange\nhost\topenchange\topenchange\t127.0.0.1\/32\t\tmd5/' \ -i /var/lib/postgres/data/pg_hba.conf # chown postgres:postgres /var/lib/postgres/data/pg_hba.conf{,.bak}
重启 postgresql
服务。
配置用户数据库
Active Directory
如果使用 Active Directory 进行用户身份验证,无论是使用 Samba(遵循 Samba/Active Directory 域控制器 文章)还是使用 Microsoft 服务器,邮件用户所需的属性已存在于默认架构中。但是,用户需要同时设置 mail 和 proxyAddresses 属性。标记为 SMTP(而不是 smtp)的 proxyAddress 属性是默认邮件地址。如果使用内部和外部域,您将需要将 SMTP 设置为用户的外部地址,因为这将是外发邮件中的 SMTP 发件人地址和信封发件人。此外,mail 属性也必须设置为用户的外部电子邮件地址。
对于 Samba,您可以使用 ldbedit 命令来编辑用户。在此示例中,我们将修改“Administrator”用户,并为 postmaster 以及内部和外部电子邮件地址添加别名。在以下命令中将 vim 替换为您首选的编辑器
# LDB_MODULES_PATH="/usr/lib/samba/ldb" ldbedit -e vim -H /var/lib/samba/private/sam.ldb '(samaccountname=administrator)'
重要的是要同时更改 mail 属性(这将用于组扩展和全局地址列表功能)和主 SMTP 地址。proxyAddresses 的 smtp 条目充当别名。添加以下属性(再次,将 internal.domain.tld 和 domain.tld 替换为适当的值)
... mail: administrator@domain.tld proxyAddresses: SMTP:administrator@domain.tld proxyAddresses: smtp:postmaster@internal.domain.tld proxyAddresses: smtp:postmaster@domain.tld proxyAddresses: smtp:administrator@internal.domain.tld ...
如果使用 Microsoft 的 Active Directory 用户和计算机 MMC 管理单元来编辑用户,您将需要从“工具”菜单中启用“显示高级功能”,并使用“属性编辑器”选项卡。
接下来,允许守护程序使用 LDAP 在目录中查找用户。为此,创建一个非特权用户用于 LDAP 查找,并选择性地(推荐)设置密码永不过期。如果使用 Samba,请执行以下命令。请务必设置适当的强密码
# samba-tool user create ldap --description="Unprivileged user for LDAP lookups" # samba-tool user setexpiry ldap --noexpiry
最后,对于 Samba 4.3.8 或 4.2.2 之后的版本,默认情况下禁用非加密通信。如果您无法启用 TLS 或 StartTLS,请将以下配置项添加到 /etc/samba/smb.conf
的 [global] 部分
ldap server require strong auth = no
MySQL/MariaDB
以下过程适用于 mariadb 10.1.25-1,但也应适用于 MySQL。
- 确保已在数据库中创建 sogo 用户(请参阅 #MySQL/MariaDB)。
- 确保存在一个名为 sogo 的数据库,其数据库方案为 utf8(而不是 utf8mb4)。这是必要的,因为否则会自动创建 sogo_sessions_folder 表将会失败
SQL: SELECT count(*) FROM sogo_sessions_folder; ERROR: Table 'sogo.sogo_sessions_folder' doesn't exist SQL: CREATE TABLE sogo_sessions_folder ( c_id VARCHAR(255) PRIMARY KEY, c_value VARCHAR(255) NOT NULL, c_creationdate INT NOT NULL, c_lastseen INT NOT NULL); ERROR: Specified key was too long; max key length is 767 bytes <-- This happens because VARCHAR(255) is too big as primary key for utf8mb4
方案可以通过以下方式更改
ALTER SCHEMA `sogo` DEFAULT CHARACTER SET utf8
更新:似乎有办法解决此问题,可以使用 utf8mb4。请查看 SOGo 安装指南 pdf 的第 33 页及之后。
sogo_users 表必须手动创建
更改用户并创建带有注释的表,解释每列的含义(请参阅 https://www.sogo.nu/files/docs/SOGoInstallationGuide.html#Authentication-using-SQL)
USE sogo; CREATE TABLE `sogo`.`sogo_users` ( `c_uid` VARCHAR(128) NOT NULL COMMENT 'c_uid: will be used for authentication - it’s a username or username@domain.tld', `c_name` VARCHAR(128) NOT NULL COMMENT 'c_name: will be used to uniquely identify entries - which can be identical to c_uid', `c_password` VARCHAR(128) NOT NULL COMMENT 'c_password: password of the user, plain text, crypt, md5 or sha encoded', `c_cn` VARCHAR(128) NULL COMMENT 'c_cn: the user’s common name', `mail` VARCHAR(128) NOT NULL COMMENT 'mail: the user’s email address', PRIMARY KEY (`c_uid`));
创建一个用户
- 生成密码的 MD5 校验和(截至 2017 年 8 月,MD5 对于密码检查仍然是安全的。最重要的是,Web 访问无论如何都应该通过 SSL 完成)。
echo -n 'mypassword' | md5sum 34819d7beeabb9260a5c854bc85b3e44 -
- 为此用户创建条目
INSERT INTO `sogo`.`sogo_users` (`c_uid`, `c_name`, `c_password`, `c_cn`, `mail`) VALUES ('username', 'username', '34819d7beeabb9260a5c854bc85b3e44', 'Archie Username', 'archie@example.com');
OpenLDAP
待添加...
PostgreSQL
待添加...
Dovecot 配置
基本配置
创建一个非常基本的 dovecot 配置布局
# install -vdm755 /etc/dovecot/conf.d # cp /usr/share/doc/dovecot/example-config/dovecot.conf /etc/dovecot/ # cp -r /usr/share/doc/dovecot/example-config/conf.d /etc/dovecot/conf.d.dist
从 /etc/dovecot/dovecot.conf
文件中删除 submission 协议(这将由 postfix 处理)。此外,如果您不希望提供 POP3 支持,请删除 pop3
... protocols = imap lmtp ...
然后使用以下内容创建文件 /etc/dovecot/conf.d/local.conf
auth_mechanisms = plain login disable_plaintext_auth = no ssl = no auth_username_format = %n mail_location = /home/vmail/%Lu/Maildir
启用并启动 dovecot
。
用户源
Active Directory
添加 LDAP 查找配置 /etc/dovecot/conf.d/ldap.conf
passdb ldap { driver = ldap args = /etc/dovecot/dovecot-ldap-passdb.conf } userdb ldap { driver = ldap args = /etc/dovecot/dovecot-ldap-userdb.conf }
设置权限
# chmod 0644 /etc/dovecot/conf.d/ldap.conf # chown root:root /etc/dovecot/conf.d/ldap.conf
创建 LDAP 用户和密码配置文件(将 dc=internal,dc=domain,dc=tld、INTERNAL 和 ldapPW 替换为适当的值)。如果您未在目录中启用 TLS 配置,请删除下面的 tls 行
/etc/dovecot/dovecot-ldap-passdb.conf
hosts = localhost auth_bind = yes auth_bind_userdn = INTERNAL\%u ldap_version = 3 tls = yes base = dc=internal,dc=domain,dc=tld scope = subtree deref = never pass_filter = (&(objectClass=person)(sAMAccountName=%u)(mail=*))
/etc/dovecot/dovecot-ldap-userdb.conf
hosts = localhost dn = cn=ldap,cn=Users,dc=internal,dc=domain,dc=tld dnpass = ldapPW ldap_version = 3 tls = yes base = cn=Users,dc=internal,dc=domain,dc=tld user_attrs = =uid=5000,=gid=5000,=home=/home/vmail/%Lu,=mail=maildir:/home/vmail/%Lu/Maildir/ user_filter = (&(objectClass=person)(sAMAccountName=%u)(mail=*)) # Attributes and filter to get a list of all users iterate_attrs = sAMAccountName=user iterate_filter = (objectClass=person)
设置权限
# chown root:root /etc/dovecot/dovecot-ldap-{pass,user}db.conf # chmod 0600 /etc/dovecot/dovecot-ldap-userdb.conf # chmod 0644 /etc/dovecot/dovecot-ldap-passdb.conf
创建 SASL 配置 /etc/dovecot/conf.d/sasl.conf
service auth { unix_listener /var/spool/postfix/private/auth { mode = 0660 user = postfix group = postfix } }
设置权限
# chmod 0644 /etc/dovecot/conf.d/sasl.conf # chown root:root /etc/dovecot/conf.d/sasl.conf
重新加载 Dovecot 以使配置生效
# dovecot reload
Maria DB
待添加...
OpenLDAP
待添加...
PostgreSQL
待添加...
测试 Dovecot 认证
创建 vmail 用户和组
# groupadd -g 5000 vmail # useradd -u 5000 -g vmail -s /usr/bin/nologin -d /home/vmail -m vmail # chmod 750 /home/vmail
打开 telnet 会话并进行测试(您输入的命令以粗体显示,将 Administrator 替换为有效的用户帐户,将 UserPass 替换为您的真实密码)
telnet localhost 143 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE AUTH=PLAIN AUTH=LOGIN] Dovecot ready. a LOGIN Administrator UserPass . OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS SPECIAL-USE BINARY MOVE] Logged in a LOGOUT * BYE Logging out . OK Logout completed. Connection closed by foreign host.
如果返回的结果不是 OK,请返回并仔细检查配置,然后再继续。
LMTP 配置
创建 LMTP 配置文件 /etc/dovecot/conf.d/lmtp.conf
mail_location = /home/vmail/%Lu/Maildir service lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp { mode = 0600 user = postfix group = postfix } user = vmail } protocol lmtp { postmaster_address = postmaster@domain.tld }
# chmod 0644 /etc/dovecot/conf.d/lmtp.conf # dovecot reload
TLS 配置
将您的证书放入到位,并创建 TLS 配置文件 /etc/dovecot/conf.d/tls.conf
(根据需要调整路径和名称)。密钥文件应归 root 用户所有,权限为 0600。任何中间证书都应在公钥证书之后连接
ssl = yes ssl_cert = </etc/dovecot/ssl/host.domain.tld.pem ssl_key = </etc/dovecot/ssl/host.domain.tld.key
# chmod 644 /etc/dovecot/conf.d/tls.conf # chmod 600 /etc/dovecot/ssl/host.domain.tld.key
将 imaps 协议添加到 /etc/dovecot/dovecot.conf
文件
... protocols = imap imaps lmtp ...
从 local.conf
中删除之前显式定义的值,并重新加载 Dovecot
# sed -e '/^ssl/d' -e '/disable_plaintext/s/no/yes/' \ -i /etc/dovecot/conf.d/local.conf # dovecot reload
Sieve 配置
如果您希望支持 sieve 配置,请安装 pigeonhole 并编辑 /etc/dovecot/dovecot.conf
。取消注释 protocols 行,并将 sieve 添加为服务。删除 submission(这将由 Postfix 或 Exim 处理)和 pop3(如果您不打算提供 pop 访问)
... protocols = imap imaps lmtp sieve ...
将以下内容追加到 /etc/dovecot/conf.d/local.conf
... plugin { sieve_before = /home/vmail/sieve/spam-global.sieve sieve=/home/vmail/%Lu/dovecot.sieve sieve_dir=/home/vmail/%Lu/sieve }
创建全局 sieve 目录
mkdir -p /home/vmail/sieve/
使用以下内容创建 /home/vmail/sieve/spam-global.sieve
文件
require "fileinto"; if header :contains "X-Spam-Flag" "YES" { fileinto "Spam"; }
设置目录(和文件)的权限
chown -R vmail:vmail /home/vmail/sieve
修改 /etc/dovecot/conf.d/lmtp.conf
文件,添加下面的粗体文本
mail_location = /home/vmail/%Lu/Maildir service lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp { mode = 0600 user = postfix group = postfix } user = vmail } protocol lmtp { postmaster_address = postmaster@domain.tld mail_plugins = sieve } plugin { sieve_before = /home/vmail/sieve/spam-global.sieve sieve = /home/vmail/%Lu/dovecot.sieve sieve_dir = /home/vmail/%Lu/sieve }
重新加载 dovecot
Postfix 配置
基本配置
创建最小的 Postfix 配置。将 server.internal.domain.tld 替换为有效的内部 FQDN)
# postconf -e myhostname=server.internal.domain.tld # postconf -e mydestination=localhost
如果此服务器将可从 Internet 访问,请将 HELO/EHLO 值设置为与从 Internet 看到的 FQDN 匹配(替换 mail.domain.tld)
# postconf -e smtp_helo_name=mail.domain.tld # postconf -e smtpd_banner='$smtp_helo_name ESMTP $mail_name'
启用并启动 postfix
。
配置 Postfix 以使用 vmail 用户和组
# postconf -e virtual_minimum_uid=5000 # postconf -e virtual_uid_maps=static:5000 # postconf -e virtual_gid_maps=static:5000 # postconf -e virtual_mailbox_base=/home/vmail # postfix reload
用户源
Active Directory
安装 postfix-ldap 并通过将以下行粘贴到文件 /etc/postfix/ldap-alias.cf
中(以 root 身份)为 Postfix 创建 LDAP 别名和组映射(将 dc=internal,dc=domain,dc=tld 替换为适当的值,并将 ldapPW 替换为 ldap 用户的密码)。如果未为您的目录配置 TLS,请删除 start_tls 行
# Directory settings server_host = 127.0.0.1 search_base = dc=internal,dc=domain,dc=tld scope = sub version = 3 start_tls = yes # User Binding bind = yes bind_dn = cn=ldap,cn=users,dc=internal,dc=domain,dc=tld bind_pw = ldapPW # Filter query_filter = (&(objectclass=person)(proxyAddresses=smtp:%s)) result_attribute = samaccountname result_format = %s@internal.domain.tld
创建组映射
# sed -e '/^query/d' \ -e '/^result/d' \ /etc/postfix/ldap-alias.cf > /etc/postfix/ldap-group.cf
将以下行追加到新创建的 /etc/postfix/ldap-group.cf
(在 #Filter 部分中)
query_filter = (&(objectclass=group)(mail=%s)) special_result_attribute = member leaf_result_attribute = mail
设置权限
# chmod 0600 /etc/postfix/ldap-{alias,group}.cf
接下来测试我们的用户查找映射(组尚未创建)(替换 internal.domain.tld)
# postmap -q administrator@domain.tld ldap:/etc/postfix/ldap-alias.cf # postmap -q administrator@internal.domain.tld ldap:/etc/postfix/ldap-alias.cf
以下输出应显示在两个命令中
Administrator@internal.domain.tld
将任何其他托管域追加到下面的第一个命令,添加映射,然后重新加载 Postfix 配置(再次替换域值)
# postconf -e virtual_mailbox_domains="domain.tld, internal.domain.tld" # postconf -e virtual_alias_maps="ldap:/etc/postfix/ldap-alias.cf, ldap:/etc/postfix/ldap-group.cf" # postfix reload
Maria DB
待添加...
OpenLDAP
待添加...
PostgreSQL
待添加...
SASL 配置
修改默认 smtpd 实例
# postconf -e smtpd_sasl_type=dovecot # postconf -e smtpd_sasl_path=private/auth # postconf -e smtpd_sasl_auth_enable=yes # postconf -e smtpd_relay_restrictions="permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination"
LMTP 配置
使用 dovecot LMTP 进行传递
# postconf -e virtual_transport=lmtp:unix:private/dovecot-lmtp
TLS 配置
如果您打算使用 STARTTLS(您应该这样做),请启用邮件提交端口并限制为经过身份验证的客户端。编辑 /etc/postfix/master.cf
中的以下行
submission inet n - n - - smtpd -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_sasl_type=dovecot -o smtpd_sasl_path=private/auth -o smtpd_sasl_security_options=noanonymous -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o smtpd_sender_login_maps=ldap:/etc/postfix/ldap-sender.cf -o smtpd_sender_restrictions=reject_sender_login_mismatch -o smtpd_recipient_restrictions=reject_non_fqdn_recipient,reject_unknown_recipient_domain,permit_sasl_authenticated,reject
添加 SSL 证书。如果您打算将 Postfix 放在 chroot jail 中(本指南中未讨论),则需要将这些证书放在 Postfix 配置文件目录中,而不是默认的 /etc/ssl/private 目录中。此外,任何中间证书都应与链中的第一个公钥证书连接,并且密钥文件应归 root 用户所有,权限模式为 0400(替换 mail.domain.tld)
# postconf -e smtpd_tls_key_file=/etc/postfix/ssl/mail.domain.tld.key # postconf -e smtpd_tls_cert_file=/etc/postfix/ssl/mail.domain.tld.pem
创建映射以验证经过身份验证的用户的地址 /etc/postfix/ldap-sender.cf
。如果未为您的目录配置 TLS,请删除 start_tls 行
# Directory settings server_host = localhost search_base = dc=internal,dc=domain,dc=tld version = 3 scope = sub start_tls = yes # User Binding bind = yes bind_dn = cn=ldap,cn=Users,dc=internal,dc=domain,dc=tld bind_pw = ldapPW # Filter query_filter = (&(objectclass=person)(proxyAddresses=smtp:%s)) leaf_result_attribute = proxyAddresses result_attribute = sAMAccountName
设置权限
# chown root:root /etc/postfix/ldap-sender.cf # chmod 0640 /etc/postfix/ldap-sender.cf
如果您想在默认 SMTP 端口上启用 TLS,则应使其成为可选的。如果您使其成为必需的,您将无法接收来自 Internet 上许多主机的邮件。
# postconf -e smtpd_tls_security_level=may
重新加载 postfix 以应用配置更改
# postfix reload
测试 Postfix SASL 配置
首先获取用户名和密码的 base64 编码版本(将 Administrator 替换为有效的用户名,将 UserPass 替换为您的真实密码)
$ echo -ne '\000Administrator\000UserPass' | openssl base64
您应该收到类似于以下的输出
AEFkbWluaXN0cmF0b3IAVXNlclBhc3M=
现在,打开 telnet 会话并进行测试(您输入的命令以粗体显示,将 host.domain.tld 替换为真实的外部 FQDN,将 AEFkbWluaXN0cmF0b3IAVXNlclBhc3M= 替换为上一个命令的结果)
$ telnet localhost 25 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 host.domain.tld ESMTP Postfix ehlo host.domain.tld 250-host.domain.tld 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-AUTH PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN AUTH PLAIN AEFkbWluaXN0cmF0b3IAVXNlclBhc3M= 235 2.7.0 Authentication successful quit 221 2.0.0 Bye Connection closed by foreign host.
如果返回的结果不是 235 消息,则说明有问题,您应该立即进行故障排除,而不是稍后进行。
SOGo 配置
基本配置
编辑 SOGo http 配置文件 /etc/httpd/conf/extra/SOGo.conf
,并注释掉以下行以进行测试(直到 SSL 证书就位且配置完成)
## adjust the following to your configuration # RequestHeader set "x-webobjects-server-port" "443" # RequestHeader set "x-webobjects-server-name" "yourhostname" # RequestHeader set "x-webobjects-server-url" "https://yourhostname"
在 /etc/sogo/sogo.conf
中创建合适的 SOGo 配置文件(将粗体项目替换为适当的值)。如果使用 PostgreSQL,请将“mysql:”行替换为适当的“postgresql:”行(如上所述)
{ /* Database Configuration */ SOGoProfileURL = "mysql://sogo:SogoPW@localhost/sogo/sogo_user_profile"; OCSFolderInfoURL = "mysql://sogo:SogoPW@localhost/sogo/sogo_folder_info"; OCSSessionsFolderURL = "mysql://sogo:SogoPW@localhost/sogo/sogo_sessions_folder"; /* Mail */ SOGoDraftsFolderName = Drafts; SOGoSentFolderName = Sent; SOGoTrashFolderName = Trash; SOGoJunkFolderName = Junk; SOGoIMAPServer = localhost; SOGoSieveServer = sieve://127.0.0.1:4190; SOGoSMTPServer = 127.0.0.1; SOGoMailDomain = internal.domain.tld; SOGoMailingMechanism = smtp; SOGoForceExternalLoginWithEmail = NO; SOGoMailSpoolPath = /var/spool/sogo; NGImap4ConnectionStringSeparator = "/"; /* Notifications */ SOGoAppointmentSendEMailNotifications = YES; SOGoACLsSendEMailNotifications = NO; SOGoFoldersSendEMailNotifications = NO; /* Authentication */ SOGoPasswordChangeEnabled = YES; /* Web Interface */ SOGoPageTitle = SOGo; SOGoVacationEnabled = YES; SOGoForwardEnabled = YES; SOGoSieveScriptsEnabled = YES; SOGoMailAuxiliaryUserAccountsEnabled = YES; SOGoTrustProxyAuthentication = NO; SOGoXSRFValidationEnabled = NO; /* General */ SOGoLanguage = English; SOGoTimeZone = America/Chicago; SOGoCalendarDefaultRoles = ( PublicDAndTViewer, ConfidentialDAndTViewer ); SOGoSuperUsernames = (administrator); SxVMemLimit = 384; //WOPidFile = "/var/run/sogo/sogo.pid"; SOGoMemcachedHost = "127.0.0.1"; /* Debug */ //SOGoDebugRequests = YES; //SoDebugBaseURL = YES; //ImapDebugEnabled = YES; //LDAPDebugEnabled = YES; //PGDebugEnabled = YES; //MySQL4DebugEnabled = YES; //SOGoUIxDebugEnabled = YES; //WODontZipResponse = YES; //WOLogFile = /var/log/sogo/sogo.log; }
然后发出以下命令
# chown sogo:sogo /etc/sogo/sogo.conf # chmod 0600 /etc/sogo/sogo.conf # mkdir /var/spool/sogo # chown sogo:sogo /var/spool/sogo # chmod 700 /var/spool/sogo
SOGo 用户源
Active Directory
修改 /etc/sogo/sogo.conf
文件并添加 LDAP 用户源(和全局地址列表)。将以下内容放在 Web Interface 部分之前。如果未为您的目录配置 TLS,请排除 LDAP URI 末尾的“/????!StartTLS”字符串
/* User Authentication */ SOGoUserSources = ( { id = directory; displayName = "Active Directory"; canAuthenticate = YES; type = ldap; CNFieldName = cn; IDFieldName = sAMAccountName; UIDFieldName = sAMAccountName; baseDN = "dc=internal,dc=domain,dc=tld"; bindDN = "cn=ldap,cn=Users,dc=internal,dc=domain,dc=tld"; bindFields = (sAMAccountName); bindPassword = "ldapPW"; hostname = ldap://server.internal.domain.tld:389/????!StartTLS; }, { id = sambaShared; displayName = "Shared Addressbook"; canAuthenticate = NO; isAddressBook = YES; type = ldap; CNFieldName = cn; IDFieldName = mail; UIDFieldName = mail; hostname = ldap://server.internal.domain.tld:389/????!StartTLS; baseDN = "dc=internal,dc=domain,dc=tld"; bindDN = "cn=ldap,cn=Users,dc=internal,dc=domain,dc=tld"; bindPassword = "ldapPW"; filter = "((NOT isCriticalSystemObject='TRUE') AND (mail=\'*\') AND (NOT objectClass=contact))"; //Uncomment to list local users in WebUI without searching (small directories only) //listRequiresDot = NO; }, { id = sambaContacts; displayName = "Shared Contacts"; canAuthenticate = NO; isAddressBook = YES; type = ldap; CNFieldName = cn; IDFieldName = mail; UIDFieldName = mail; hostname = ldap://server.internal.domain.tld:389/????!StartTLS; baseDN = "dc=internal,dc=domain,dc=tld"; bindDN = "cn=ldap,cn=Users,dc=internal,dc=domain,dc=tld"; bindPassword = "ldapPW"; filter = "((((objectClass=person) AND (objectClass=contact) AND ((uidNumber>=2000) OR (mail='*'))) AND (NOT isCriticalSystemObject='TRUE') AND (NOT showInAdvancedViewOnly='TRUE') AND (NOT uid=Guest)) OR (((objectClass=group) AND (gidNumber>=2000)) AND (NOT isCriticalSystemObject='TRUE') AND (NOT showInAdvancedViewOnly='TRUE')))"; mapping = { displayname = ("cn"); //Uncomment to list contacts in WebUI without searching (few contacts only) //listRequiresDot = NO; }; } );
Maria DB
出于调试目的,请编辑 /etc/sogo/sogo.conf
以启用所有调试开关
/* Debug */ SOGoDebugRequests = YES; SoDebugBaseURL = YES; ImapDebugEnabled = YES; LDAPDebugEnabled = YES; PGDebugEnabled = YES; MySQL4DebugEnabled = YES; SOGoUIxDebugEnabled = YES; WODontZipResponse = YES; WOLogFile = /var/log/sogo/sogo.log;
如果出现问题,请通过以 root 身份运行 journalctl -xe
进行检查。
进一步修改 /etc/sogo/sogo.conf
文件以包含 SQL 作为用户源(将密码更改为为 sogo mysql 用户选择的密码)
SOGoUserSources = ( { type = sql; id = directory; viewURL = "mysql://sogo:yoursogopassword@127.0.0.1:3306/sogo/sogo_users"; canAuthenticate = YES; isAddressBook = YES; userPasswordAlgorithm = md5; } );
或者,可以使用视图而不是直接使用表。有关 SOGoUserSources 可用值的更多信息,请访问此处:https://sogo.nu/files/docs/SOGoInstallationGuide.html#_authentication_using_sql
OpenLDAP
待添加...
PostgreSQL
待添加...
完成配置
现在启用并启动 memcached
服务,然后重启 sogo
服务。通过访问 http://server.internal.domain.tld/SOGo/ 进行测试。
ActiveSync 配置
Apache
要添加 ActiveSync 支持,只需取消注释 /etc/httpd/conf/extra/SOGo.conf
中的以下行
... ProxyPass /Microsoft-Server-ActiveSync \ http://127.0.0.1:20000/SOGo/Microsoft-Server-ActiveSync \ retry=60 connectiontimeout=5 timeout=3600 ...
如果您有少量用户,这将导致扩展的锁定延迟,因此需要进行一些调整。您可能会注意到,上面的行已从 360 秒更改为 3600 秒(或一小时)。这是因为 EAS 设备需要将其 HTTP 连接保持打开很长时间(长达一小时)。因此,您需要告诉 SOGo(见下文)接受该超时。重新加载 httpd
服务,然后再继续。
nginx
将以下内容添加到 /etc/nginx/nginx.com
中 SOGo 的服务器定义
... location ^~ /Microsoft-Server-ActiveSync { proxy_pass http://127.0.0.1:20000/SOGo/Microsoft-Server-ActiveSync; proxy_redirect http://127.0.0.1:20000/Microsoft-Server-ActiveSync /; } location ^~ /SOGo/Microsoft-Server-ActiveSync { proxy_pass http://127.0.0.1:20000/SOGo/Microsoft-Server-ActiveSync; proxy_redirect http://127.0.0.1:20000/SOGo/Microsoft-Server-ActiveSync /; } ...
可能需要对下面 SOGo 部分中的参数进行其他调整(特别是 timeout、retry 和 next host 值)。
SOGo
如上文针对列出的 HTTP 服务器所述,使用 EAS 需要进行一些调整。虽然下面的超时时间(59 分钟)适用于上面设置的 HTTP 会话超时时间,但 worker 的数量取决于您必须支持的并发 EAS 客户端的数量。简而言之,您始终需要比 EAS 客户端更多的 worker,以允许启动另一个 worker 进行推送操作。此外,同步间隔将允许您减少服务器上的负载,从而减少延迟,并且这取决于客户端的总数。SOGo 配置指南(可在 https://sogo.nu/files/docs/SOGoInstallationGuide.pdf 中找到)列出了两个示例配置。本文选择了 100 个用户和 10 个 EAS 用户的示例。将以下行追加到 /etc/sogo/sogo.conf
,确保它们位于右大括号(“}”)字符之前
/* ActiveSync */ WOWorkersCount = 15; WOWatchDogRequestTimeout = 59; SOGoMaximumPingInterval = 3540; SOGoMaximumSyncInterval = 3540; SOGoInternalSyncInterval = 30;
最后,重启 sogo
服务。