完美的服务器--Ubuntu 9.04 ISPconfig设置 (中)

来源:岁月联盟 编辑:zhuzhu 时间:2009-04-28
完美的服务器--Ubuntu 9.04 ISPconfig设置 (中)内容简介:11,安装必须的软件包 这些软件包是后面的服务需要的: aptitude install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl libdb4.6-dev libpcre3 libpopt-dev

  11,安装必须的软件包

   这些软件包是后面的服务需要的:

   aptitude install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl libdb4.6-dev libpcre3 libpopt-dev lynx m4 make ncftp nmap openssl perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g build-essential

   (一行以内完成)

   12,安装Quota

   如果你之前的分区表和我的不同,你应该在这里做相应的调整

   安装

   aptitude install quota

   编辑/etc/fstab,我的是这样的:

vi /etc/fstab

 # /etc/fstab: static file system information.
    #
    # Use 'vol_id --uuid' to print the universally unique identifier for a
    # device; this may be used with UUID= as a more robust way to name devices
    # that works even if disks are added and removed. See fstab(5).
    #
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    proc            /proc           proc    defaults        0       0
    # / was on /dev/mapper/server1-root during installation
    UUID=b8d265bc-5959-404d-a68e-8dc1c76f18d6 /               ext3    relatime,errors=remount-ro,usrquota,grpquota 0       1
    # /boot was on /dev/sda5 during installation
    UUID=01e9c3c7-2ad0-4f52-a356-18290517b362 /boot           ext2    relatime        0       2
    # swap was on /dev/mapper/server1-swap_1 during installation
    UUID=c1e0bcbb-5c73-4bd2-a7b2-8beeb7526200 none            swap    sw              0       0
    /dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0
    /dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0

   启动quota

   touch /quota.user /quota.group

   chmod 600 /quota.*

   mount -o remount /

   quotacheck -avugm

   quotaon -avug

   13,DNS 服务器

   安装

   aptitude install bind9

   因为安全原因,我们应该以chroot模式运行bind

   /etc/init.d/bind9 stop

   编辑文件 /etc/default/bind9 让bind守护进程以非特权用户bind的身份运行,chroot到/var/lib/named.编辑此行: OPTIONS="-u bind" so that it reads OPTIONS="-u bind -t /var/lib/named":

vi /etc/default/bind9

   # run resolvconf?
    RESOLVCONF=yes
    # startup options for the server
    OPTIONS="-u bind -t /var/lib/named"

   在/var/lib下创建必须的文件夹

   mkdir -p /var/lib/named/etc

   mkdir /var/lib/named/dev

   mkdir -p /var/lib/named/var/cache/bind

   mkdir -p /var/lib/named/var/run/bind/run

   把配置文件夹从/etc移入到/var/lib/named/etc:

   mv /etc/bind /var/lib/named/etc

   在老文件夹里创建一个软链接到新的配置文件夹(确保bind能正常更新)

   ln -s /var/lib/named/etc/bind /etc/bind

   创建空设备和随机设备,修正文件权限:

   mknod /var/lib/named/dev/null c 1 3

   mknod /var/lib/named/dev/random c 1 8

   chmod 666 /var/lib/named/dev/null /var/lib/named/dev/random

   chown -R bind:bind /var/lib/named/var/*

   chown -R bind:bind /var/lib/named/etc/bind

   编辑/etc/default/syslogd 使得重要的登录信息能够传到系统日志编辑这行:SYSLOGD="" so that it reads: SYSLOGD="-a /var/lib/named/dev/log":

   vi /etc/defatlt/syslogd

 #
    # Top configuration file for syslogd
    #
    #
    # Full documentation of possible arguments are found in the manpage
    # syslogd(8).
    #

    #
    # For remote UDP logging use SYSLOGD="-r"
    #
    SYSLOGD="-a /var/lib/named/dev/log"
 

   重启LOG的daemon

   /etc/init.d/syslogd restart

   启动bind,检查 /var/log/syslog中的错误

   /etc/init.d/bind9 start

   14 MYSQL

   安装:

   aptitude install mysql-server mysql-client libmysqlclient15-dev

   你会被要求提供一个MYSQL ROOT密码,这个密码对root@localhost和root@server1.example.com一样有效,所以我们不一定要手动设定

   New password for the MySQL "root" user: <-- yourrootsqlpassword

   Repeat password for the MySQL "root" user: <-- yourrootsqlpassword

   我们想离MYSQL监听所有接口,不光localhost,所有我们编辑/etc/mysql/my.cnf 注释掉这行:bind-address = 127.0.0.1:

   vi /etc/mysql/my.cnf

    [...]
    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    #bind-address           = 127.0.0.1
    [...]

   然后重启MYSQL

   /etc/init.d/mysql restart

   检查网络中已经启动

   netstat -tap | grep mysql

   输出应该像这样

    root@server1:~# netstat -tap | grep mysql
    tcp        0      0 *:mysql                 *:*                     LISTEN      4318/mysqld
 root@server1:~#

  15,安装使用SMTP-AUTH和TLS的Postfix

   为了做到这些应该这样:

   aptitude install postfix libsasl2-2 sasl2-bin libsasl2-modules procmail

   你将被问及

   General type of mail configuration: <-- Internet Site

   System mail name: <-- server1.example.com

   如实回答 然后运行

   dpkg-reconfigure postfix

   你将再次被问及

   General type of mail configuration: <-- Internet Site

   System mail name: <-- server1.example.com

   Root and postmaster mail recipient: <-- [blank]

   Other destinations to accept mail for (blank for none): <-- server1.example.com, localhost.example.com, localhost.localdomain, localhost

   Force synchronous updates on mail queue? <-- No

   Local networks: <-- 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

   Use procmail for local delivery? <-- Yes

   Mailbox size limit (bytes): <-- 0

   Local address extension character: <--

   Internet protocols to use: <-- all

   然后,这样

   postconf -e 'smtpd_sasl_local_domain ='

   postconf -e 'smtpd_sasl_auth_enable = yes'

   postconf -e 'smtpd_sasl_security_options = noanonymous'

   postconf -e 'broken_sasl_auth_clients = yes'

   postconf -e 'smtpd_sasl_authenticated_header = yes'

   postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'

   postconf -e 'inet_interfaces = all'

   echo 'pwcheck_method: saslauthd' >> /etc/postfix/sasl/smtpd.conf

   echo 'mech_list: plain login' >> /etc/postfix/sasl/smtpd.conf

   然后我们创建TLS认证

   mkdir /etc/postfix/ssl

   cd /etc/postfix/ssl/

   openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024

   chmod 600 smtpd.key

   openssl req -new -key smtpd.key -out smtpd.csr

   openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt

   openssl rsa -in smtpd.key -out smtpd.key.unencrypted

   mv -f smtpd.key.unencrypted smtpd.key

   openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650

   然后我们配置postfix以启用TLS(保证你使用了正确的主机名)

   postconf -e 'myhostname = server1.example.com'

   postconf -e 'smtpd_tls_auth_only = no'

   postconf -e 'smtp_use_tls = yes'

   postconf -e 'smtpd_use_tls = yes'

   postconf -e 'smtp_tls_note_starttls_offer = yes'

   postconf -e 'smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key'

   postconf -e 'smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt'

   postconf -e 'smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem'

   postconf -e 'smtpd_tls_loglevel = 1'

   postconf -e 'smtpd_tls_received_header = yes'

   postconf -e 'smtpd_tls_session_cache_timeout = 3600s'

   postconf -e 'tls_random_source = dev:/dev/urandom'

   文件/etc/postfix/main.cf现在看起来应该像这样

cat /etc/postfix/main.cf

  # See /usr/share/postfix/main.cf.dist for a commented, more complete version

    # Debian specific:  Specifying a file name will cause the first
    # line of that file to be used as the name.  The Debian default
    # is /etc/mailname.
    #myorigin = /etc/mailname

    smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
    biff = no

    # appending .domain is the MUA's job.
    append_dot_mydomain = no

    # Uncomment the next line to generate "delayed mail" warnings
    #delay_warning_time = 4h

    readme_directory = no

    # TLS parameters
    smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
    smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
    smtpd_use_tls = yes
    smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
    smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

    # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
    # information on enabling SSL in the smtp client.

    myhostname = server1.example.com
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    myorigin = /etc/mailname
    mydestination = server1.example.com, localhost.example.com, localhost.localdomain, localhost
    relayhost =
    mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
    mailbox_command = procmail -a "$EXTENSION"
    mailbox_size_limit = 0
    recipient_delimiter =
    inet_interfaces = all
    inet_protocols = all
    smtpd_sasl_local_domain =
    smtpd_sasl_auth_enable = yes
    smtpd_sasl_security_options = noanonymous
    broken_sasl_auth_clients = yes
    smtpd_sasl_authenticated_header = yes
    smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
    smtpd_tls_auth_only = no
    smtp_use_tls = yes
    smtp_tls_note_starttls_offer = yes
    smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
    smtpd_tls_loglevel = 1
    smtpd_tls_received_header = yes
    smtpd_tls_session_cache_timeout = 3600s
    tls_random_source = dev:/dev/urandom

   saslauthd用来做认证,我们要做些设置以使它正常工作,因为POSTFIX运行chroot于/var/spool/postfix,我们应该这样:

   mkdir -p /var/spool/postfix/var/run/saslauthd

   为了激活saslauthd我们必须修改/etc/default/saslauthd这行

   :OPTIONS="-c -m /var/run/saslauthd" 成这样 OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r":

vi /etc/default/saslauthd

    # Which authentication mechanisms should saslauthd use? (default: pam)
    #
    # Available options in this Debian package:
    # getpwent  -- use the getpwent() library function
    # kerberos5 -- use Kerberos 5
    # pam       -- use PAM
    # rimap     -- use a remote IMAP server
    # shadow    -- use the local shadow password file
    # sasldb    -- use the local sasldb database file
    # ldap      -- use LDAP (configuration is in /etc/saslauthd.conf)
    #
    # Only one option may be used at a time. See the saslauthd man page
    # for more information.
    #
    # Example: MECHANISMS="pam"
    MECHANISMS="pam"
    # Additional options for this mechanism. (default: none)
    # See the saslauthd man page for information about mech-specific options.
    MECH_OPTIONS=""

    # How many saslauthd processes should we run? (default: 5)
    # A value of 0 will fork a new process for each connection.
    THREADS=5

    # Other options (default: -c -m /var/run/saslauthd)
    # Note: You MUST specify the -m option or saslauthd won't run!
    #
    # WARNING: DO NOT SPECIFY THE -d OPTION.
    # The -d option will cause saslauthd to run in the foreground instead of as
    # a daemon. This will PREVENT YOUR SYSTEM FROM BOOTING PROPERLY. If you wish
    # to run saslauthd in debug mode, please run it by hand to be safe.
    #
    # See /usr/share/doc/sasl2-bin/README.Debian for Debian-specific information.
    # See the saslauthd man page and the output of 'saslauthd -h' for general
    # information about these options.
    #
    # Example for postfix users: "-c -m /var/spool/postfix/var/run/saslauthd"
    #OPTIONS="-c -m /var/run/saslauthd"
    OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"

   将用户postfix加入saal组,(这样postfix才有权限运行saslauthd)

   adduser postfix sasl

   现在重启服务

   /etc/init.d/postfix restart

   /etc/init.d/saslauthd start

   检查SMTP-AUTH 和 TLS是否工作:

   telnet localhost 25

   连接后,输入

   ehlo localhost

   如果能看到

   250-STARTTLS

   和

   250-AUTH LOGIN PLAIN

   说明一切都很好,我的输出是

 root@server1:/etc/postfix/ssl# telnet localhost 25
    Trying ::1...
    Connected to localhost.localdomain.
    Escape character is '^]'.
    220 server1.example.com ESMTP Postfix (Ubuntu)
    ehlo localhost
    250-server1.example.com
    250-PIPELINING
    250-SIZE 10240000
    250-VRFY
    250-ETRN
    250-STARTTLS
    250-AUTH LOGIN PLAIN
    250-AUTH=LOGIN PLAIN
    250-ENHANCEDSTATUSCODES
    250-8BITMIME
    250 DSN
    quit
    221 2.0.0 Bye
    Connection closed by foreign host.
    root@server1:/etc/postfix/ssl#

   输入:

   quit

   回到系统shell

   16.Courier-IMAP/Courier-POP3

   先安装:

   aptitude install courier-authdaemon courier-base courier-imap courier-imap-ssl courier-pop courier-pop-ssl courier-ssl gamin libgamin0 libglib2.0-0

   你将被问及:

   Create directories for web-based administration? <-- No

   SSL certificate required <-- Ok

   在安装时IMAP和POP3的ssl论证是以localhost的主机名安装的,先删除这们认证

   cd /etc/courier

   rm -f /etc/courier/imapd.pem

   rm -f /etc/courier/pop3d.pem

   然后编辑两个文件/etc/courier/imapd.cnf和/etc/courier/pop3.cnf,用CN=server1.example.com 替换 CN=localhost  :

vi /etc/courier/imapd.cnf

  [...]
    CN=server1.example.com
  [...]

   vi /etc/courier/pop3d.cnf

 [...]
    CN=server1.example.com
 [...]

   重建认证

   mkimapdcert

   mkpop3dcert

   重启Courier-IMAP-SSL 和 Courier-POP3-SSL:

   /etc/init.d/courier-imap-ssl restart

   /etc/init.d/courier-pop-ssl restart

   如果你不想用ISPConfig,设置POSTFIX将邮件传到用户的邮件文件夹:

   postconf -e 'home_mailbox = Maildir/'

   postconf -e 'mailbox_command ='

   /etc/init.d/postfix restart

   如果你使用ISPConfig这一步不是必须的,因为ISPCONFIG会使用procmail做同样的事,但你得确定你在ISPCONFIG网络接口中启用了Maildir功能:

   Maildir under Management -> Server -> Settings -> EMail

  17 Apache/PHP5/Ruby/Python/WebDAV

   现在安装APACHE

   aptitude install apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2-suexec libexpat1 ssl-cert