1. LNMP环境搭建
1.1 nginx安装配置
systemctl stop firewalld
setenforce 0
yum install epel-release -y
yum update
yum install vim nginx net-tools wget -y
cd /etc/nginx
mv nginx.conf nginx.bak
vim nginx.conf
user nginx; pid /var/run/nginx.pid; worker_processes 4; events { use epoll; worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; include /etc/nginx/proxy.conf; sendfile on; keepalive_timeout 65; include /etc/nginx/vhosts/*.conf; server { listen 80; server_name localhost; location / { root html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }
vim proxy.conf
#!nginx (-) # proxy.conf proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 64m; client_body_buffer_size 128k; proxy_connect_timeout 120; proxy_send_timeout 120; proxy_read_timeout 120; send_timeout 600; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_headers_hash_max_size 51200; proxy_headers_hash_bucket_size 6400;
vim gzip.conf
gzip on; # gzip_http_version 1.1; gzip_disable "MSIE [1-6]\."; gzip_disable "Mozilla/4"; gzip_comp_level 3; gzip_proxied any; gzip_vary on; gzip_buffers 4 16k; gzip_min_length 1100; gzip_types text/plain text/xml text/css applicatoin/xml application/xhtml+xml application/rss+xml application/atom_xml application/javascript application/x-javascript;
mkdir vhosts;cd vhosts
vim mailserver.conf
server { listen 80; server_name mail-admin.meskvm.com; index index.php; root /usr/local/postfixadmin; #postfixadmin目录location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
}
server {
listen 80;
server_name mail.meskvm.com;
index index.php;
root /data/nginx/roundcube; #roundcube 目录location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }<br />}
systemctl start nginx
systemctl enable nginx
1.2 php安装配置
yum install php php-fpm lighttpd-fastcgi php-adodb php-bcmath php-Analog php-cli php-dba php-devel php-embedded php-enchant php-gd php-geshi php-getid3 php-gliph php-hamcrest php-idn php-imap php-interbase php-intl php-latte php-layers-menu php-ldap php-lessphp php-libdmtx php-libpuzzle php-magickwand php-mapi php-mapserver php-markdown php-masterminds-html5 php-mbstring php-mcrypt php-mysql php-odbc php-pclzip php-pdo php-pear php-pecl php-phpass php-process php-spsell php-punic php-recode php-redis php-redland php-scssphp php-sentry php-shout php-silex php-simplepie php-snmp php-soap php-tcpdf php-tidy php-tracy php-twig php-voms-admin php-when php-xapian php-xcache php-xml php-xmlrpm php-zipstream php-zmq php-zte -y
vim /etc/php.ini #修改以下内容
date.timezone = "Asia/Shanghai" session.save_path = "/dev/shm" post_max_size = 128M upload_max_filesize = 128M
systemctl start php-fpm
systemctl enable php-fpm
1.3 mariadb安装配置
yum install mariadb mariadb-server mariadb-libs -y
systemctl start mariadb
mysqladmin -u root password
systemctl restart mariadb
mysql -u root -p
MariaDB [(none)]> create database postfix character set utf8; MariaDB [(none)]> grant all privileges on postfix.* to postfix@localhost identified by ‘postfix’; MariaDB [(none)]> create database roundcubemail character set utf8; MariaDB [(none)]> grant all privileges on roundcube.* to postfix@localhost identified by ‘postfix’; MariaDB [(none)]> flush privileges;
mariadb enable mariadb
2. 邮件服务相关组件安装配置
2.1 postfix安装配置
yum install postfix -y
cd /etc/postfix
mv main.cf main.bak
vim main.cf
###############MAIN CONFIGURE################### myhostname = mail.meskvm.com mydomain = meskvm.com myorigin = $mydomain inet_interfaces = all mydestination = localhost mynetworks = 0.0.0.0/0 disable_dns_lookups = no default_destination_concurrency_limit = 80 default_process_limit = 100 mail_max_userip_connections = 50 net_interfaces = ipv4###############Virtual mail configure#############
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
vitual_mailbox_base = /data/mailbox
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_uid_maps = static:8
virtual_gid_maps = static:12
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
proxy_read_maps = local_recipient_maps mydestination virtual_alias_maps virtual_alias_domains virtual_mailbox_maps virtual_mailbox_domains relay_recipient_maps relay_domains canonical_maps sender_canonical_maps recipient_canonical_maps relocated_maps transport_maps mynetworks $virtual_mailbox_limit_maps
###############SASL SUPPORT FOR CLIENTS############
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_security_options = noanonymous
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain = $mydomain
broken_sasl_auth_clients = yes
smtpd_sender_login_maps = mysql:/etc/postfix/mysql_sender_login_maps.cf, mysql:/etc/postfix/mysql_virtual_alias_maps.cf
##########mail monitor##########
recipient_bcc_maps = hash:/etc/postfix/recipient_bcc
sender_bcc_maps = hash:/etc/postfix/sender_bcc
smtpd_sender_restrictions = reject_sender_login_mismatch, reject_authenticated_sender_login_mismatch, reject_non_fqdn_sender,
check_recipient_access hash:/etc/postfix/local_recipientsmtpd_recipient_restrictions = check_sender_access hash:/etc/postfix/local_senders, permit_sasl_authenticated, reject_invalid_hostname, reject_non_fqdn_hostname, reject_unknown_sender_domain, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_pipelining, reject_unauth_destination, reject_sender_login_mismatch, reject_authenticated_sender_login_mismatch
smtpd_tls_key_file = /etc/pki/dovecot/private/dovecot.pem
smtpd_tls_cert_file = /etc/pki/dovecot/certs/dovecot.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtp_connect_timeout = 120s
tls_random_source = dev:/dev/urandom
###############Mail Quota configure###############
message_size_limit = 204800000
maximal_queue_lifetime = 1d
bounce_queue_lifetime = 1d
#####sendgroupmail contraint#########
smtpd_restriction_classes = send_all, local_only
send_all = check_sender_access hash:/etc/postfix/send_all, reject
local_only = check_recipient_access hash:/etc/postfix/my_rcpt, reject
mv master.cf master.bak
vim master.cf
smtp inet n - n - - smtpd submission inet n - n - - smtpd -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smptd_sasl_path=private/auth -o smtpd_sasl_security_options=noanonymous -o smtpd_sasl_local_domain=$myhostname -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o smtpd_sender_login_maps=hash:/etc/postfix/virtual -o smtpd_sender_restrictions=reject_sender_login_mismatch -o smtpd_recipient_restrictions=reject_non_fqdn_recipient,reject_unknown_recipient_domain,permit_sasl_authenticated,reject smtps inet n - n - - smtpd -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject pickup unix n - n 60 1 pickup -o content_filter= -o receive_override_options=no_header_body_checks cleanup unix n - n - 0 cleanup qmgr unix n - n 300 1 qmgr tlsmgr unix - - n 1000? 1 tlsmgr rewrite unix - - n - - trivial-rewrite bounce unix - - n - 0 bounce defer unix - - n - 0 bounce trace unix - - n - 0 bounce verify unix - - n - 1 verify flush unix n - n 1000? 0 flush proxymap unix - - n - - proxymap proxywrite unix - - n - 1 proxymap smtp unix - - n - - smtp relay unix - - n - - smtp showq unix n - n - - showq error unix - - n - - error retry unix - - n - - error discard unix - - n - - discard local unix - n n - - local virtual unix - n n - - virtual lmtp unix - - n - - lmtp anvil unix - - n - 1 anvil scache unix - - n - 1 scache maildrop unix - n n - - pipe flags=DRhu user=mail argv=/usr/local/bin/maildrop -d ${recipient} uucp unix - n n - - pipe flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient) ifmail unix - n n - - pipe flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient) bsmtp unix - n n - - pipe flags=Fq. user=bsmtp argv=/usr/local/sbin/bsmtp -f $sender $nexthop $recipient dovecot unix - n n - - pipe flags=DRhu user=mail:mail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient} vacation unix - n n - - pipe flags=Rq user=vacation argv=/var/spool/vacation/vacation.pl -f ${sender} -d ${recipient}
vim mysql_relay_domains_maps.cf
hosts = localhost #port = 23306 user = postfix password = postfix dbname = postfix query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '1'
vim mysql_sender_login_maps.cf
hosts = localhost #port = 23306 user = postfix password = postfix dbname = postfix #query = SELECT username FROM mailbox WHERE username = '%s' AND active = '1' table = mailbox select_field = username where_field = username
vim mysql_virtual_alias_maps.cf
hosts = localhost #port = 23306 user = postfix password = postfix dbname = postfix query = SELECT goto FROM alias WHERE address='%s' AND active = '1' #table = alias #select_field = goto #where_filed = address
vim mysql_virtual_domains_maps.cf
hosts = localhost #port = 23306 user = postfix password = postfix dbname = postfix query = SELECT domain FROM domain WHERE domain='%s' AND active = '1' #table = domain #select_field = domain #where_field = domain
vim mysql_virtual_mailbox_limit_maps.cf
hosts = localhost #port = 23306 user = postfix password = postfix dbname = postfix query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1' #table = mailbox #select_field = quota #where_field = username
vim mysql_virtual_mailbox_maps.cf
hosts = localhost #port = 23306 user = postfix password = postfix dbname = postfix query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1' #table = mailbox #select_field = maildir #where_field = username
echo "meskvm.com OK" > local_domains
postmap hash:/etc/postfix/local_domains
systemctl start postfix
systemctl enable postfix
2.1 dovecot安装配置
yum install dovecot* -y
cd /etc/dovecot
mv dovecot.conf dovecot.bak
vim dovecot.conf
# 2.2.10: /etc/dovecot/dovecot.conf # OS: Linux 3.10.0-514.el7.x86_64 x86_64 CentOS Linux release 7.3.1611 (Core) xfs auth_mechanisms = plain login cram-md5 dict { quotadict = mysql:/etc/dovecot/dovecot-dict-quota.conf } disable_plaintext_auth = no first_valid_gid = 12 first_valid_uid = 8 info_log_path = /var/log/dovecot_info.log listen = * log_path = /var/log/dovecot.log mail_location = maildir:/data/mailbox/%d/%n mail_max_userip_connections = 50 mail_plugins = quota managesieve_notify_capability = mailto managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date mbox_write_locks = fcntl passdb { args = /etc/dovecot/dovecot-sql.conf driver = sql } plugin { autocreate = Trash autocreate2 = Junk autocreate3 = Drafts autocreate4 = Sent autosubscribe = Trash autosubscribe2 = Junk autosubscribe3 = Drafts autosubscribe4 = Sent quota = dict:user::proxy::quotadict quota_rule = *:storage=2G } service auth { unix_listener /var/spool/postfix/private/auth { group = postfix mode = 0600 user = postfix } unix_listener auth-client { group = mail mode = 0600 user = mail } unix_listener auth-userdb { group = mail mode = 0600 user = mail } } service dict { unix_listener dict { group = mail mode = 0600 user = mail } } service imap-login { inet_listener imap { port = 143 } inet_listener imaps { port = 993 ssl = yes } } service pop3-login { inet_listener pop3 { port = 110 } inet_listener pop3s { port = 995 ssl = yes } } ssl_cert = </etc/pki/dovecot/certs/dovecot.pem ssl_key = </etc/pki/dovecot/private/dovecot.pem userdb { args = /etc/dovecot/dovecot-sql.conf driver = sql } protocol lda { mail_plugins = quota } protocol pop3 { mail_plugins = quota pop3_client_workarounds = outlook-no-nuls oe-ns-eoh pop3_uidl_format = %08Xu%08Xv } protocol imap { mail_plugins = quota imap_quota autocreate }
vim dovecot-dict-quota.conf
map { pattern = priv/quota/storage table = quota2 username_field = username value_field = bytes } map { pattern = priv/quota/messages table = quota2 username_field = username value_field = messages }
vim dovecot-sql.conf
driver = mysql connect = host=localhost dbname=postfix user=postfix password=postfix default_pass_scheme = MD5#following should all be on one line
password_query = SELECT username as user, password, concat('/data/mailbox/', maildir) as userdb_home, concat('maildir:/data/mailbox', maildir) as userdb_mail, 8 as userdb_uid, 12 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1'
#user
user_query = SELECT concat('/data/mailbox/', maildir) as home, concat('maildir:/data/mailbox/', maildir) as mail, 8 AS uid, 12 AS gid, CONCAT('*:messages=100000:bytes=', quota) as quota_rule FROM mailbox WHERE username = '%u'AND active = '1'
systemctl start dovecot
systemctl enable dovecot
2.3 postfixadmin安装配置
cd /usr/local/src
wget https://sourceforge.net/projects/postfixadmin/files/postfixadmin/postfixadmin-3.0.2/postfixadmin-3.0.2.tar.gz
tar -zxvf postfixadmin-3.0.2.tar.gz
mv postfixadmin-3.0.2 /usr/local/postfixadmin
cd /usr/local/postfixadmin
vim config.inc.php #打开配置文件并修改以下内容
$CONF['configured'] = true; $CONF['default_language'] = 'cn'; $CONF['database_type'] = 'mysql'; $CONF['database_type'] = 'mysql'; $CONF['database_host'] = 'localhost'; $CONF['database_user'] = 'postfix'; $CONF['database_password'] = 'postfix'; $CONF['database_name'] = 'postfix'; $CONF['encrypt'] = 'dovecot:CRAM-MD5'; $CONF['dovecotpw'] = "/usr/bin/doveadm pw"; $CONF['quota'] = 'YES';
在浏览器打开页面mail-admin.meskvm.com/setup.php 如下图
按照提示修改config.inc.php相关内容,并创建安装密码,并创建管理员和密码。 如下图
按照提示转入登陆页,并登录。原目录下的setup.php文件可删除。 登录页面如下图所示
创建域 如下图所示
创建用户 如下图
2.3 roundcube安装配置
cd /usr/local/src
wget https://github.com/roundcube/roundcubemail/releases/download/1.2.5/roundcubemail-1.2.5.tar.gz
tar -zxvf roundcubemail-1.2.5.tar.gz
mv roundcubemail-1.2.5 /data/nginx/roundcube
cd /data/nginx/roundcube
cp config/config.inc.php.sample config/config.inc.php
vim config/config.inc.php #修改以下内容
$config['db_dsnw'] = 'mysql://postfix:postfix@localhost/roundcubemail'; $config['smtp_server'] = 'ssl://mail.meskvm.com'; $config['smtp_port'] = 465; $config['smtp_user'] = '%u'; $config['smtp_pass'] = '%p';
mysql -u postfix -ppostfix roundcubemail < SQL/mysql_initial.sql
用浏览器打开地址 mail.meskvm.com从网页登录邮箱。如下图
为roundcube安装修改密码插件
vim config/config.inc.php #打开配置文件并修改以下内容
$config['plugins'] = array(
'archive',
'zipdownload',
'password',
);
cd plugins/password
cp config.inc.php.dist config.inc.php
vim config.inc.php #打开配置文件并修改以下内容
$config['password_dovecotpw'] = '/usr/bin/doveadm pw'; $config['password_db_dsn'] = 'mysql://postfix:postfix@localhost/postfix'; $config['password_query'] = 'UPDATE mailbox SET password=%D WHERE username=%u'; // $config['password_crypt_hash'] = 'md5'; $config['password_dovecotpw_with_method'] = true;
在网页端修改用户密码。如下图
为roundcube安装公共通讯录插件
cd /data/nginx/roundcube/plugins
git clone https://github.com/JohnDoh/Roundcube-Plugin-Global-Address-Book.git
mv Roundcube-Plugin-Global-Address-Book globaladdressbook
vim ../config/config.inc.php #打开配置文件修改以下内容
$config['plugins'] = array( 'archive', 'zipdownload', 'password', 'globaladdressbook', );
mv globaladdressbook/config.inc.php.dist globaladdressbook/config.inc.php
vim globaladdressbook/config.inc.php #打开文件并修改以下内容
$config['globaladdressbook_user'] = '[global_addressbook@%d]'; $config['globaladdressbook_perms'] = 3; $config['globaladdressbook_admin'] = 'test@meskvm.com';
测试并查看公共通讯录。 如下图
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于