Thiết lập máy chủ Ubuntu 11.10 và cài đặt ISPConfig 3

Thảo luận trong 'Thế giới WebMaster' bắt đầu bởi bboy_nonoyes, 12 Tháng 8 2012.

  1. (Lượt xem: 4,207)

    ISPconfig là một phần mềm quản lý hosting mã nguồn mở, cho phép bạn cấu hình các dịch vụ thông qua một trình duyệt web: Apache web server, Postfix mail server, MySQL, BIND hoặc MyDNS nameserver, PureFTPd, SpamAssassin, ClamAV... Trong bài viết sau chúng tôi sẽ hướng dẫn các bạn cách tạo một máy chủ Ubuntu 11.10 (Oneiric Ocelot) cho việc cài đặt ISPConfig 3, sau đó tiến hành cài đặt ISPConfig 3.
    1. Các yêu cầu

    - Hướng dẫn này chỉ làm việc với ISPConfig 3, bạn không thể áp dụng cho phiên bản khác.
    - Để cài đặt được hệ thống này bạn cần:
    • CD cài đặt Ubuntu 11.10 server, tải về tại đây (bản i386 ), hoặc tại đây (bản x86_64).
    • Một kết nối Internet tốc độ cao.
    2. Lưu ý

    Trong phần minh họa sau chúng tôi sử dụng hostname server1.example.com với địa chỉ IP 192.168.0.100 và gateway 192.168.0.1. Bạn cần có sự thay thế cho phù hợp với mình.
    3. Cài đặt Ubuntu Server

    Cho đĩa cài đặt Ubuntu vào hệ thống và khởi động từ nó. Chọn ngôn ngữ của bạn:
    [IMG]
    Sau đó chọn Install Ubuntu Server:
    [IMG]
    Chọn lại ngôn ngữ lần nữa:
    [IMG]
    Lựa chọn vị trí:
    [IMG]
    [IMG]
    [IMG]
    Nếu bạn chọn sự kết hợp ít gặp giữa ngôn ngữ và vị trí của mình (chẳng hạn như ngôn ngữ là tiếng Anh nhưng vị trí là Đức), trình cài đặt có thể thông báo với bạn rằng không xác định được sự kết hợp này. Vì vậy phần locale bạn phải chọn thủ công, ví dụ en_US.UTF-8:
    [IMG]
    Chọn kiểu keyboard (bạn sẽ được yêu cầu nhập vào một phím bất kỳ, và trình cài đặt sẽ tự động nhận dạng kiểu keyboard của bạn dựa trên phím được nhập vào):
    [IMG]
    [IMG]
    Sau đó quá trình cài đặt bắt đầu và tiến hành kiểm tra CD, phần cứng, cấu hình mạng với DHCP nếu có một DHCP server trong mạng:
    [IMG]
    [IMG]

    Còn tiếp...
  2. Facebook comment - Thiết lập máy chủ Ubuntu 11.10 và cài đặt ISPConfig 3

  3. Nhập vào hostname. Trong ví dụ này chúng tôi sử dụng hệ thống server1.example.com, do đó nhập server1:
    [IMG]
    Kiểm tra xem trình cài đặt có phát hiện chính xác múi giờ của bạn hay không. Nếu đúng hãy chọn Yes.
    [IMG]
    Bây giờ cần tạo phân vùng cho ổ đĩa cứng của bạn. Để đơn giản ta chọn Guided - use entire disk and set up LVM – điều này sẽ tạo một volume group với hai volume logic (một cho tập tin hệ thống và một cho swap). Tất nhiên bạn cũng có thể chọn theo ý muốn.
    [IMG]
    Chọn ổ đĩa muốn phân vùng:
    [IMG]
    Khi được hỏi "Write the changes to disks and configure LVM?", chọn Yes.
    [IMG]
    Với lựa chọn Guided - use entire disk and set up LVM, lúc này việc phân vùng sẽ tạo một volume group sử dụng toàn bộ không gian đĩa cứng. Bạn có thể nhập vào dung lượng cho volume logic và swap.
    [IMG]
    Khi được hỏi "Write the changes to disks?" chọn Yes.
    [IMG]
    Sau đó, phân vùng mới sẽ được khởi tạo và định dạng.
    [IMG]
    Tiếp theo là quá trình cài đặt hệ thống:
    [IMG]
    Tạo một user, ví dụ Administrator với tên Administrator và đặt password cho nó (tuyệt đối không sử dụng tên admins bởi nó đã được dành riêng trong Ubuntu 11.10):
    [IMG]
    [IMG]
    [IMG]
    [IMG]
    Bạn sẽ được hỏi có cần mã hóa private directory hay không, ở đây tôi không cần nên chọn No:
    [IMG]
    Tiếp theo chúng ta cấu hình các gói quản lý apt gets, để trống phần HTTP nếu không sử dụng proxy server để kết nối Internet.
    [IMG]
    [IMG]
    Cấu hình việc cập nhật hệ thống: Ở đây nếu muốn tự làm việc này bằng tay, bạn có thể chọn No automatic updates.
    [IMG]
    Chúng ta cần một DNS, mail và LAMP server, nhưng không nên chọn bất cứ thứ gì nhằm có toàn quyền kiểm soát những thứ được cài trên hệ thống của mình. Sau đó chúng ta có thể cài lại bằng tay. Chỉ cần chọn OpenSSH server để có thể kết nối trực tiếp tới hệ thống với một SSH client như PuTTy, sau khi việc cài đặt hoàn tất:
    [IMG]
    Quá trình cài đặt sẽ được tiếp tục:
    [IMG]
    Cài đặt GRUB boot loader:
    [IMG]
    Chọn Yes khi được hỏi "Install the GRUB boot loader to the master boot record?":
    [IMG]
    Sau khi hoàn tất việc cài đặt, bỏ đĩa cài khỏi ổ CD và nhấn Continue để reboot hệ thống.
    [IMG]

    Còn tiếp...
  4. 4. Lấy quyền root

    Sau khi reboot, bạn có thể đăng nhập với tài khoản vừa tạo ra (administrator). Bởi vì bạn cần chạy những dòng lệnh tiếp theo với quyền root nên cần thêm từ sudo sau mỗi lệnh, hoặc trở thành root ngay bây giờ:
    sudo su
    Bạn cũng có thể kích hoạt đăng nhập root bằng cách chạy lệnh:
    sudo passwd root
    Và tạo ra một mật khẩu root. Sau đó bạn có thể đăng nhập trực tiếp với quyền root. Tuy nhiên điều này không được khuyến cáo từ các nhà phát triển và cộng đồng Ubuntu bởi nhiều lý do.
    5. Cài đặt SSH Server (tùy chọn không bắt buộc)

    Nếu bạn không cài đặt OpenSSH server trong quá trình cài đặt, bạn có thể cài bằng lệnh:
    apt-get install ssh openssh-server
    Từ đây bạn có thể dùng chương trình SSH Client như PuTTY để kết nối từ máy trạm tới Ubuntu 11.10 Server và tiếp tục các bước tiếp theo.
    6. Cài đặt vim-nox (không bắt buộc)

    Do chúng tôi sử dụng vi là chương trình text editor. Nhưng theo mặc định, vi tạo một số hành động lạ với Ubuntu và Debian, để sửa lỗi này ta cần cài vim-nox:
    pt-get install vim-nox
    (Bạn không cần cài vim-nox nếu bạn sử dụng joe hay nano).
    7. Cấu hình network:

    Bởi vì trình cài đặt Ubuntu đã cấu hình hệ thống để có các thiết lập mạng thông qua DHCP, mà ta cần một địa chỉ IP tĩnh nên sẽ cấu hình lại /etc/network/interfaces và điều chỉnh nếu cần. Ví dụ chúng ta có địa chỉ IP 192.168.0.100:
    vi /etc/network/interfaces
    Mã:
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
     
    # The loopback network interface
    auto lo
    iface lo inet loopback
     
    # The primary network interface
    auto eth0
    iface eth0 inet static
            address 192.168.0.100
            netmask 255.255.255.0
            network 192.168.0.0
            broadcast 192.168.0.255
            gateway 192.168.0.1

    Khởi động lại mạng:
    /etc/init.d/networking restart
    Chỉnh sửa /etc/hosts như sau:
    vi /etc/hosts


    Bây giờ chạy:
    echo server1.example.com > /etc/hostname
    /etc/init.d/hostname restart

    Sau đó chạy tiếp:
    hostname
    hostname -f

    Cả hai sẽ hiển thị server1.example.com.
    8. Chỉnh sửa /etc/apt/sources.list và cập nhật Linux

    Sửa lại /etc/apt/sources.list. Cho đĩa cài đặt vào, chắc chắn rằng universe multiverse repositories được bật:
    vi /etc/apt/sources.list
    Mã:
    #
     
    # deb cdrom:[Ubuntu-Server 11.10 _Oneiric Ocelot_ - Release amd64 (20111011)]/ dists/oneiric/main/binary-i386/
    # deb cdrom:[Ubuntu-Server 11.10 _Oneiric Ocelot_ - Release amd64 (20111011)]/ dists/oneiric/restricted/binary-i386/
    # deb cdrom:[Ubuntu-Server 11.10 _Oneiric Ocelot_ - Release amd64 (20111011)]/ oneiric main restricted
     
    #deb cdrom:[Ubuntu-Server 11.10 _Oneiric Ocelot_ - Release amd64 (20111011)]/ dists/oneiric/main/binary-i386/
    #deb cdrom:[Ubuntu-Server 11.10 _Oneiric Ocelot_ - Release amd64 (20111011)]/ dists/oneiric/restricted/binary-i386/
    #deb cdrom:[Ubuntu-Server 11.10 _Oneiric Ocelot_ - Release amd64 (20111011)]/ oneiric main restricted
     
    # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
    # newer versions of the distribution.
    deb http://de.archive.ubuntu.com/ubuntu/ oneiric main restricted
    deb-src http://de.archive.ubuntu.com/ubuntu/ oneiric main restricted
     
    ## Major bug fix updates produced after the final release of the
    ## distribution.
    deb http://de.archive.ubuntu.com/ubuntu/ oneiric-updates main restricted
    deb-src http://de.archive.ubuntu.com/ubuntu/ oneiric-updates main restricted
     
    ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    ## team. Also, please note that software in universe WILL NOT receive any
    ## review or updates from the Ubuntu security team.
    deb http://de.archive.ubuntu.com/ubuntu/ oneiric universe
    deb-src http://de.archive.ubuntu.com/ubuntu/ oneiric universe
    deb http://de.archive.ubuntu.com/ubuntu/ oneiric-updates universe
    deb-src http://de.archive.ubuntu.com/ubuntu/ oneiric-updates universe
     
    ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    ## team, and may not be under a free licence. Please satisfy yourself as to
    ## your rights to use the software. Also, please note that software in
    ## multiverse WILL NOT receive any review or updates from the Ubuntu
    ## security team.
    deb http://de.archive.ubuntu.com/ubuntu/ oneiric multiverse
    deb-src http://de.archive.ubuntu.com/ubuntu/ oneiric multiverse
    deb http://de.archive.ubuntu.com/ubuntu/ oneiric-updates multiverse
    deb-src http://de.archive.ubuntu.com/ubuntu/ oneiric-updates multiverse
     
    ## N.B. software from this repository may not have been tested as
    ## extensively as that contained in the main release, although it includes
    ## newer versions of some applications which may provide useful features.
    ## Also, please note that software in backports WILL NOT receive any review
    ## or updates from the Ubuntu security team.
    deb http://de.archive.ubuntu.com/ubuntu/ oneiric-backports main restricted universe multiverse
    deb-src http://de.archive.ubuntu.com/ubuntu/ oneiric-backports main restricted universe multiverse
     
    deb http://security.ubuntu.com/ubuntu oneiric-security main restricted
    deb-src http://security.ubuntu.com/ubuntu oneiric-security main restricted
    deb http://security.ubuntu.com/ubuntu oneiric-security universe
    deb-src http://security.ubuntu.com/ubuntu oneiric-security universe
    deb http://security.ubuntu.com/ubuntu oneiric-security multiverse
    deb-src http://security.ubuntu.com/ubuntu oneiric-security multiverse
     
    ## Uncomment the following two lines to add software from Canonical's
    ## 'partner' repository.
    ## This software is not part of Ubuntu, but is offered by Canonical and the
    ## respective vendors as a service to Ubuntu users.
    # deb http://archive.canonical.com/ubuntu oneiric partner
    # deb-src http://archive.canonical.com/ubuntu oneiric partner
     
    ## Uncomment the following two lines to add software from Ubuntu's
    ## 'extras' repository.
    ## This software is not part of Ubuntu, but is offered by third-party
    ## developers who want to ship their latest software.
    # deb http://extras.ubuntu.com/ubuntu oneiric main
    # deb-src http://extras.ubuntu.com/ubuntu oneiric main

    Chạy lệnh:
    apt-get update
    Cập nhật cơ sở dữ liệu của apt package:
    apt-get upgrade
    Cuối cùng khởi động lại hệ thống:
    reboot
    9. Thay đổi Shell mặc định

    /bin/sh là một symlink tới /bin/dash, tuy nhiên chúng ta cần /bin/bash chứ không phải /bin/dash. Vì vậy thay đổi nó bằng lệnh:
    dpkg-reconfigure dash
    Use dash as the default system shell (/bin/sh)? <-- chọn No
    Nếu không làm điều này, cài đặt ISPConfig sẽ thất bại.
    10. Vô hiệu hóa AppArmor

    AppArmor là một phần mở rộng bảo mật (tương tự SELinux). Mặc dù nó mang lại nhiều khả năng bảo mật nhưng cũng gây nhiều phiến phức. Vì vậy bạn có thể vô hiệu hóa nó (sẽ là cần thiết để cài đặt ISPConfig sau này):
    /etc/init.d/apparmor stop
    update-rc.d -f apparmor remove
    apt-get remove apparmor apparmor-utils

    11. Đồng bộ hóa đồng hồ hề thống

    Đây là một ý tưởng tốt để đồng bộ hệ thống thời gian với NTP (network time protocol). Chỉ cần chạy:
    apt-get install ntp ntpdate
  5. 12. Cài đặt Postfix, Courier, Saslauthd, MySQL, rkhunter, binutils

    Chúng ta có thể cài đặt toàn bộ chương trình này bằng dòng lệnh:
    Mã:
    apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl getmail4 rkhunter binutils maildrop
    Bạn sẽ nhận được những câu hỏi sau:
    New password for the MySQL "root" user: <-- yourrootsqlpassword
    Repeat password for the MySQL "root" user: <-- yourrootsqlpassword
    Create directories for web-based administration? <-- No
    General type of mail configuration: <-- Internet Site
    System mail name: <-- server1.example.com
    SSL certificate required <-- Ok

    Sửa lại file cấu hình của mysql để MySQL có thể giao tiếp trên tất cả các giao thức, không chỉ mình localhost, bằng cách sửa file /etc/mysql/my.cnf và tắt dòng: bind-address = 127.0.0.1:
    vi /etc/mysql/my.cnf
    Mã:
    [...]
    # 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
    [...]

    Sau đó restart MySQL:
    /etc/init.d/mysql restart
    Bây giờ kiểm tra kết nối mạng có được kích hoạt:
    netstat -tap | grep mysql
    Đầu ra sẽ trông như thế này;
    Mã:
    root@server1:~# netstat -tap | grep mysql
    tcp        0      0 *:mysql                *:*                    LISTEN      22355/mysqld
    root@server1:~#
    Trong quá trình cài đặt, chứng chỉ SSL cho IMAP-SSL và POP3-SSL sẽ được tạo với hostname localhost. Để thay đổi tên cho đúng hostname Server1.example.com, chỉ cần xóa chứng thư này:
    cd /etc/courier
    rm -f /etc/courier/imapd.pem
    rm -f /etc/courier/pop3d.pem

    Và sửa đổi hai tập tin sau đây, thay thế CN=localhost bằng CN=server1.example.com (bạn cũng có thể đổi thành giá trị khác nếu cần thiết).
    vi /etc/courier/imapd.cnf
    Mã:
    [...]
    CN=server1.example.com
    [...]
    vi /etc/courier/pop3d.cnf
    Mã:
    [...]
    CN=server1.example.com
    [...]
    Sau đó tạo lại chứng thư:
    mkimapdcert
    mkpop3dcert

    Khởi động lại Courier-IMAP-SSL và Courier-POP3-SSL:
    /etc/init.d/courier-imap-ssl restart
    /etc/init.d/courier-pop-ssl restart

    13. Cài đặt Amavisd-new, SpamAssassin, và Clamav

    Bạn sử dụng dòng lệnh sau để cài đặt Amavisd-new, SpamAssassin, và Clamav:
    Mã:
    apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 arj nomarch lzop cabextract apt-listchanges libnet-ldap-perl libauthen-sasl-perl clamav-docs daemon libio-string-perl libio-socket-ssl-perl libnet-ident-perl zip libnet-dns-perl
    ISPConfig 3 sử dụng Amavisd để tải bộ lọc SpamAssassin, chúng ta cần cho dừng quá trình này để giải phóng RAM:
    /etc/init.d/spamassassin stop
    update-rc.d -f spamassassin remove

    14. Cài đặt Apache2, PHP5, phpMyAdmin, FCGI, suExec, Pear, và mcrypt

    Apache2, PHP5, phpMyAdmin, FCGI, suExec, Pear, và mcrypt có thể cài đặt dễ dàng bằng lệnh sau:
    Mã:
    apt-get install apache2 apache2.2-common apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-php5 php5 php5-common php5-gd php5-mysql php5-imap phpmyadmin php5-cli php5-cgi libapache2-mod-fcgid apache2-suexec php-pear php-auth php5-mcrypt mcrypt php5-imagick imagemagick libapache2-mod-suphp libruby libapache2-mod-ruby
    Bạn sẽ thấy hai câu hỏi:
    Web server to reconfigure automatically: <-- nhập apache2
    Configure database for phpmyadmin with dbconfig-common? <-- nhập No

    Tiếp theo chạy những lệnh sau để kích hoạt các module của Apache: suexec, rewrite, ssl, actions,include (cộng với dav, dav_fs,auth_digest nếu bạn muốn dùng WebDAV):
    a2enmod suexec rewrite ssl actions include
    a2enmod dav_fs dav auth_digest

    Restart lại Apache:
    /etc/init.d/apache2 restart
    Nếu bạn muốn lưu trữ các tập tin Ruby với phần mở rộng .rb trên các trang web của mình thông qua ISPConfig, bạn cần chú thích dòng application/x-ruby rb trong /etc/mime.types:
    vi /etc/mime.types
    Mã:
    [...]
    #application/x-ruby                            rb
    [...]
    (Điều này chỉ cần thiết đối với những file .rb).
    Sau đó khởi động lại Apache:
    /etc/init.d/apache2 restart
    15. Cài đặt PureFTPd và Quota

    PureFTPd và Quota có thể cài đặt bằng lệnh:
    apt-get install pure-ftpd-common pure-ftpd-mysql quota quotatool
    Sửa lại file /etc/default/pure-ftpd-common:
    vi /etc/default/pure-ftpd-common
    Và đảm bảo chắc chắn start mode được set là standalone VIRTUALCHROOT=true:
    Mã:
    [...]
    STANDALONE_OR_INETD=standalone
    [...]
    VIRTUALCHROOT=true
    [...]
    Bây giờ chúng ta cấu hình PureFTPd để cho phép FTP và TLS. Bằng cách kết hợp phương pháp mã hóa TLS sẽ làm cho giao thức FTP được an toàn hơn rất nhiều.
    echo 1 > /etc/pure-ftpd/conf/TLS
    Để sử dụng TLS, chúng ta cần tạo chứng chỉ SSL. Ở đây chúng tôi sẽ tạo trong /etc/ssl/private/, do đó cần tạo thư mục đó trước:
    mkdir -p /etc/ssl/private/
    Tiếp theo tạo chứng chỉ SSL:
    Mã:
    openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem
     
     
     
    Country Name (2 letter code) [AU]: <-- Enter your Country Name (e.g., "DE").
    State or Province Name (full name) [Some-State]: <-- Enter your State or Province Name.
    Locality Name (eg, city) []: <-- Enter your City.
    Organization Name (eg, company) [Internet Widgits Pty Ltd]: <-- Enter your Organization Name (e.g., the name of your company).
    Organizational Unit Name (eg, section) []: <-- Enter your Organizational Unit Name (e.g. "IT Department").
    Common Name (eg, YOUR name) []: <-- Enter the Fully Qualified Domain Name of the system (e.g. "server1.example.com").
    Email Address []: <-- Enter your Email Address.
     
    Thay đổi các điều khoản của chứng chỉ SSL:
     
    chmod 600 /etc/ssl/private/pure-ftpd.pem
     
    Restart PureFTPd:
     
    /etc/init.d/pure-ftpd-mysql restart
    Sửa lại /etc/fstab. Thêm vào dòng ,usrjquota=quota.user,grpjquota=quota.group,jqfmt=vfsv0 tới partition với mount point /:

    vi /etc/fstab
    Mã:
    # /etc/fstab: static file system information.
    #
    # Use 'blkid' 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    nodev,noexec,nosuid 0      0
    /dev/mapper/server1-root /              ext4    errors=remount-ro,usrjquota=quota.user,grpjquota=quota.group,jqfmt=vfsv0 0      1
    # /boot was on /dev/sda1 during installation
    UUID=6fbce377-c3d6-4eb3-8299-88797d4ad18d /boot          ext2    defaults        0      2
    /dev/mapper/server1-swap_1 none            swap    sw              0      0
    /dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0      0
    Kích hoạt quota, chạy lệnh sau:
    mount -o remount /
    quotacheck -avugm
    quotaon -avug

    16. Cài đặt BIND DNS Server

    Bạn chạy lệnh sau để cài đặt BIND:
    apt-get install bind9 dnsutils
    17. Cài đặt logger, Webalizer, và AWstats

    apt-get install vlogger webalizer awstats
    Sau đó mở /etc/cron.d/awstats:
    vi /etc/cron.d/awstats
    Và tạo chú thích về hai việc định kỳ trong đó:
    Mã:
    #*/10 * * * * www-data [ -x /usr/share/awstats/tools/update.sh ] && /usr/share/awstats/tools/update.sh
     
    # Generate static reports:
    #10 03 * * * www-data [ -x /usr/share/awstats/tools/buildstatic.sh ] && /usr/share/awstats/tools/buildstatic.sh
    18. Cài đặt Jailkit
    Jailkit chỉ cần thiết nếu bạn muốn Chroot user SSH, cần lưu ý rằng Jailkit phải được cài đặt trước ISPConfig. Tuyệt đối không làm ngược lại.
    Mã:
    apt-get install build-essential autoconf automake1.9 libtool flex bison debhelper
     
    cd /tmp
    wget http://olivier.sessink.nl/jailkit/jailkit-2.14.tar.gz
    tar xvfz jailkit-2.14.tar.gz
    cd jailkit-2.14
    ./debian/rules binary
    Bạn sẽ nhận được thông báo:
    Mã:
    x86_64-linux-gnu-gcc -lpthread -o jk_socketd jk_socketd.o jk_lib.o utils.o iniparser.o
    jk_socketd.o: In function `main':
    /tmp/jailkit-2.14/src/jk_socketd.c:474: undefined reference to `pthread_create'
    collect2: ld returned 1 exit status
    make[2]: *** [jk_socketd] Error 1
    make[2]: Leaving directory `/tmp/jailkit-2.14/src'
    make[1]: *** [all] Error 2
    make[1]: Leaving directory `/tmp/jailkit-2.14'
    make: *** [build-arch-stamp] Error 2
    root@server1:/tmp/jailkit-2.14#
    Hãy cài đặt gcc-4.4:
    apt-get install gcc-4.4
    Và xem /usr/bin/gcc:
    ls -l /usr/bin/gcc*
    /usr/bin/gcc hiện hành phải là một symlink tới /usr/bin/gcc-4.6:
    root@server1:/tmp/jailkit-2.14# ls -l /usr/bin/gcc*
    lrwxrwxrwx 1 root root 7 2011-08-14 09:16 /usr/bin/gcc -> gcc-4.6
    -rwxr-xr-x 1 root root 259232 2011-10-05 23:56 /usr/bin/gcc-4.4
    -rwxr-xr-x 1 root root 349120 2011-09-16 16:31 /usr/bin/gcc-4.6
    root@server1:/tmp/jailkit-2.14#

    Chúng ta sẽ thay đổi điều này bằng cách liên kết /usr/bin/gcc tới /usr/bin/gcc-4.4:
    ln -sf /usr/bin/gcc-4.4 /usr/bin/gcc
    Và xây dựng Jailkit:
    make clean
    ./configure
    make
    make clean
    ./debian/rules binary

    Nếu lệnh ./debian/rules binary không đưa ra lỗi nào, bạn có thể cài đặt gói .deb như sau:
    cd ..
    dpkg -i jailkit_2.14-1_*.deb
    rm -rf jailkit-2.14*

    Cuối cùng chúng ta thay đổi symlink /usr/bin/gcc để nó trỏ tới /usr/bin/gcc-4.6 lần nữa.
    ln -sf /usr/bin/gcc-4.6 /usr/bin/gcc

    Còn tiếp...
  6. 19. Cài đặt fail2ban

    Mặc dù đây là tùy chọn không bắt buộc, nhưng chúng tôi khuyến cáo bạn cài đặt bởi màn hình ISPConfig sẽ hiển thị đăng nhập fail2ban:
    apt-get install fail2ban
    Để làm cho fail2ban theo dõi PureFTPd, SASL, và Courier, tạo file /etc/fail2ban/jail.local:
    vi /etc/fail2ban/jail.local
    Mã:
    [pureftpd]
     
    enabled  = true
    port    = ftp
    filter  = pureftpd
    logpath  = /var/log/syslog
    maxretry = 3
     
     
    [sasl]
     
    enabled  = true
    port    = smtp
    filter  = sasl
    logpath  = /var/log/mail.log
    maxretry = 5
     
     
    [courierpop3]
     
    enabled  = true
    port    = pop3
    filter  = courierpop3
    logpath  = /var/log/mail.log
    maxretry = 5
     
     
    [courierpop3s]
     
    enabled  = true
    port    = pop3s
    filter  = courierpop3s
    logpath  = /var/log/mail.log
    maxretry = 5
     
     
    [courierimap]
     
    enabled  = true
    port    = imap2
    filter  = courierimap
    logpath  = /var/log/mail.log
    maxretry = 5
     
     
    [courierimaps]
     
    enabled  = true
    port    = imaps
    filter  = courierimaps
    logpath  = /var/log/mail.log
    maxretry = 5

    Sau đó tạo 5 file bộ lọc sau:
    vi /etc/fail2ban/filter.d/pureftpd.conf
    Mã:
    [Definition]
    failregex = .*pure-ftpd: \(.*@<HOST>\) \[WARNING\] Authentication failed for user.*
    ignoreregex =
    vi /etc/fail2ban/filter.d/courierpop3.conf
    Mã:
    # Fail2Ban configuration file
    #
    # $Revision: 100 $
    #
     
    [Definition]
     
    # Option:  failregex
    # Notes.:  regex to match the password failures messages in the logfile. The
    #          host must be matched by a group named "host". The tag "<HOST>" can
    #          be used for standard IP/hostname matching and is only an alias for
    #          (?:::f{4,6}:)?(?P<host>\S+)
    # Values:  TEXT
    #
    failregex = pop3d: LOGIN FAILED.*ip=\[.*:<HOST>\]
     
    # Option:  ignoreregex
    # Notes.:  regex to ignore. If this regex matches, the line is ignored.
    # Values:  TEXT
    #
    ignoreregex =
    vi /etc/fail2ban/filter.d/courierpop3s.conf
    Mã:
    # Fail2Ban configuration file
    #
    # $Revision: 100 $
    #
     
    [Definition]
     
    # Option:  failregex
    # Notes.:  regex to match the password failures messages in the logfile. The
    #          host must be matched by a group named "host". The tag "<HOST>" can
    #          be used for standard IP/hostname matching and is only an alias for
    #          (?:::f{4,6}:)?(?P<host>\S+)
    # Values:  TEXT
    #
    failregex = pop3d-ssl: LOGIN FAILED.*ip=\[.*:<HOST>\]
     
    # Option:  ignoreregex
    # Notes.:  regex to ignore. If this regex matches, the line is ignored.
    # Values:  TEXT
    #
    ignoreregex =

    vi /etc/fail2ban/filter.d/courierimap.conf
    Mã:
    # Fail2Ban configuration file
    #
    # $Revision: 100 $
    #
     
    [Definition]
     
    # Option:  failregex
    # Notes.:  regex to match the password failures messages in the logfile. The
    #          host must be matched by a group named "host". The tag "<HOST>" can
    #          be used for standard IP/hostname matching and is only an alias for
    #          (?:::f{4,6}:)?(?P<host>\S+)
    # Values:  TEXT
    #
    failregex = imapd: LOGIN FAILED.*ip=\[.*:<HOST>\]
     
    # Option:  ignoreregex
    # Notes.:  regex to ignore. If this regex matches, the line is ignored.
    # Values:  TEXT
    #
    ignoreregex =
    vi /etc/fail2ban/filter.d/courierimaps.conf
    Mã:
    # Fail2Ban configuration file
    #
    # $Revision: 100 $
    #
     
    [Definition]
     
    # Option:  failregex
    # Notes.:  regex to match the password failures messages in the logfile. The
    #          host must be matched by a group named "host". The tag "<HOST>" can
    #          be used for standard IP/hostname matching and is only an alias for
    #          (?:::f{4,6}:)?(?P<host>\S+)
    # Values:  TEXT
    #
    failregex = imapd-ssl: LOGIN FAILED.*ip=\[.*:<HOST>\]
     
    # Option:  ignoreregex
    # Notes.:  regex to ignore. If this regex matches, the line is ignored.
    # Values:  TEXT
    #
    ignoreregex =
    Và khởi động lại fail2ban:
    /etc/init.d/fail2ban restart
    20. Cài đặt SquirrelMail

    Để cài đặt dịch vụ webmail client SquirrelMail bạn sử dụng lệnh sau:
    apt-get install squirrelmail
    Sau đó cấu hình cho nó:
    squirrelmail-configure
    Thông báo cho SquirrelMail biết chúng ta đang sử dụng Courier-IMAP/-POP3:
    Mã:
    SquirrelMail Configuration : Read: config.php (1.4.0)
    ---------------------------------------------------------
    Main Menu --
    1.  Organization Preferences
    2.  Server Settings
    3.  Folder Defaults
    4.  General Options
    5.  Themes
    6.  Address Books
    7.  Message of the Day (MOTD)
    8.  Plugins
    9.  Database
    10. Languages
     
    D.  Set pre-defined settings for specific IMAP servers
     
    C  Turn color on
    S  Save data
    Q  Quit
     
    Command >> <-- D
     
     
    SquirrelMail Configuration : Read: config.php
    ---------------------------------------------------------
    While we have been building SquirrelMail, we have discovered some
    preferences that work better with some servers that don't work so
    well with others.  If you select your IMAP server, this option will
    set some pre-defined settings for that server.
     
    Please note that you will still need to go through and make sure
    everything is correct.  This does not change everything.  There are
    only a few settings that this will change.
     
    Please select your IMAP server:
        bincimap    = Binc IMAP server
        courier    = Courier IMAP server
        cyrus      = Cyrus IMAP server
        dovecot    = Dovecot Secure IMAP server
        exchange    = Microsoft Exchange IMAP server
        hmailserver = hMailServer
        macosx      = Mac OS X Mailserver
        mercury32  = Mercury/32
        uw          = University of Washington's IMAP server
        gmail      = IMAP access to Google mail (Gmail) accounts
     
        quit        = Do not change anything
    Command >> <-- courier
     
     
    SquirrelMail Configuration : Read: config.php
    ---------------------------------------------------------
    While we have been building SquirrelMail, we have discovered some
    preferences that work better with some servers that don't work so
    well with others.  If you select your IMAP server, this option will
    set some pre-defined settings for that server.
     
    Please note that you will still need to go through and make sure
    everything is correct.  This does not change everything.  There are
    only a few settings that this will change.
     
    Please select your IMAP server:
        bincimap    = Binc IMAP server
        courier    = Courier IMAP server
        cyrus      = Cyrus IMAP server
        dovecot    = Dovecot Secure IMAP server
        exchange    = Microsoft Exchange IMAP server
        hmailserver = hMailServer
        macosx      = Mac OS X Mailserver
        mercury32  = Mercury/32
        uw          = University of Washington's IMAP server
     
        quit        = Do not change anything
    Command >> courier
     
                  imap_server_type = courier
            default_folder_prefix = INBOX.
                      trash_folder = Trash
                      sent_folder = Sent
                      draft_folder = Drafts
                show_prefix_option = false
              default_sub_of_inbox = false
    show_contain_subfolders_option = false
                optional_delimiter = .
                    delete_folder = true
     
    Press any key to continue... <-- ENTER
     
     
    SquirrelMail Configuration : Read: config.php (1.4.0)
    ---------------------------------------------------------
    Main Menu --
    1.  Organization Preferences
    2.  Server Settings
    3.  Folder Defaults
    4.  General Options
    5.  Themes
    6.  Address Books
    7.  Message of the Day (MOTD)
    8.  Plugins
    9.  Database
    10. Languages
     
    D.  Set pre-defined settings for specific IMAP servers
     
    C  Turn color on
    S  Save data
    Q  Quit
     
    Command >> <-- S
     
     
    SquirrelMail Configuration : Read: config.php (1.4.0)
    ---------------------------------------------------------
    Main Menu --
    1.  Organization Preferences
    2.  Server Settings
    3.  Folder Defaults
    4.  General Options
    5.  Themes
    6.  Address Books
    7.  Message of the Day (MOTD)
    8.  Plugins
    9.  Database
    10. Languages
     
    D.  Set pre-defined settings for specific IMAP servers
     
    C  Turn color on
    S  Save data
    Q  Quit
     
    Command >> S
     
    Data saved in config.php
    Press enter to continue... <-- ENTER
     
     
    SquirrelMail Configuration : Read: config.php (1.4.0)
    ---------------------------------------------------------
    Main Menu --
    1.  Organization Preferences
    2.  Server Settings
    3.  Folder Defaults
    4.  General Options
    5.  Themes
    6.  Address Books
    7.  Message of the Day (MOTD)
    8.  Plugins
    9.  Database
    10. Languages
     
    D.  Set pre-defined settings for specific IMAP servers
     
    C  Turn color on
    S  Save data
    Q  Quit
     
    Command >> <-- Q
    Bây giờ chúng ta sẽ cấu hình cho SquirrelMail để có thể sử dụng nó trong các trang web được tạo từ ISPConfig bằng /squirrelmail hoặc /webmail aliases. Do đó nếu trang web của bạn là www.example.com, bạn sẽ truy cập SquirrelMail bằng đường dẫn www.example.com/squirrelmail hoặc www.example.com/webmail.
    Apache của SquirrelMail được cấu hình trong tập tin /etc/squirrelmail/apache.conf, nhưng tập tin này không được tải bởi Apache vì nó không có trong thư mục /etc/apache2/conf.d/. Do đó chúng ta tạo ra một symlink có tên /etc/squirrelmail/apache.conf và tải lại Apache.
    cd /etc/apache2/conf.d/
    ln -s ../../squirrelmail/apache.conf squirrelmail.conf
    /etc/init.d/apache2 reload

    Mở /etc/apache2/conf.d/squirrelmail.conf:
    vi /etc/apache2/conf.d/squirrelmail.conf
    Và thêm vào nội dung trong phần <Directory /usr/share/squirrelmail></Directory> để đảm bảo mod_php được sử dụng cho sự truy cập vào SquirrelMail, bất kể chế độ PHP bạn chọn cho trang web của mình trong ISPConfig:
    Mã:
    [...]
    <Directory /usr/share/squirrelmail>
      Options FollowSymLinks
      <IfModule mod_php5.c>
        AddType application/x-httpd-php .php
    php_flag magic_quotes_gpc Off
    php_flag track_vars On
    php_admin_flag allow_url_fopen Off
    php_value include_path .
    php_admin_value upload_tmp_dir /var/lib/squirrelmail/tmp
    php_admin_value open_basedir /usr/share/squirrelmail:/etc/squirrelmail:/var/lib/squirrelmail:/etc/hostname:/etc/mailname
        php_flag register_globals off
      </IfModule>
      <IfModule mod_dir.c>
        DirectoryIndex index.php
      </IfModule>
     
      # access to configtest is limited by default to prevent information leak
      <Files configtest.php>
        order deny,allow
        deny from all
        allow from 127.0.0.1
      </Files>
    </Directory>
    [...]
    Tạo thư mục /var/lib/squirrelmail/tmp:
    mkdir /var/lib/squirrelmail/tmp
    Và làm cho nó thuộc sở hữu của www-data:
    chown www-data /var/lib/squirrelmail/tmp
    Tải lại Apache:
    /etc/init.d/apache2 reload
    Như vậy /etc/apache2/conf.d/squirrelmail.conf được định nghĩa với biệt danh /squirrelmail, trong thư mục cài đặt /usr/share/squirrelmail.
    Bạn có thể truy cập SquirrelMail ngay lập tức từ website của mình:
    http://192.168.0.100/squirrelmail
    http://www.example.com/squirrelmail

    Hoặc bạn có thể truy cập thông qua trình điều khiển của ISPConfig vhost mà không cần bất kỳ cầu hình nào (tất nhiên là sau khi đã cài đặt ISPConfig ở phần dưới đây):
    http://server1.example.com:8080/squirrelmail
    Nếu bạn muốn sử dụng bí danh /webmail thay cho /squirrelmail, chỉ cần mở /etc/apache2/conf.d/squirrelmail.conf:
    vi /etc/apache2/conf.d/squirrelmail.conf
    Và thêm vào dòng Alias /webmail /usr/share/squirrelmail:
    Mã:
    Alias /squirrelmail /usr/share/squirrelmail
    Alias /webmail /usr/share/squirrelmail
    [...]
    Tải lại Apache:
    /etc/init.d/apache2 reload
    Sau đó truy cập Squirrelmail:
    http://192.168.0.100/webmail
    http://www.example.com/webmail
    http://server1.example.com:8080/webmail (sau khi đã cài đặt ISPConfig)

    [IMG]
    Nếu bạn muốn định nghĩa một vhost như webmail.example.com tại nơi người dùng có thể truy cập SquirrelMail, thêm dòng /etc/apache2/conf.d/squirrelmail.conf vào cấu hình của vhost:
    vi /etc/apache2/conf.d/squirrelmail.conf
    Mã:
    [...]
    <VirtualHost 1.2.3.4:80>
      DocumentRoot /usr/share/squirrelmail
      ServerName webmail.example.com
    </VirtualHost>
    Thay thế 1.2.3.4 bởi địa chỉ IP chính xác của máy chủ. Đương nhiên phải có một bản ghi DNS cho webmail.example.com trỏ đến địa chỉ IP mà bạn sử dụng trong cấu hình của vhost. Ngoài ra hãy chắc chắn rằng vhost webmail.example.com không tồn tại trong ISPConfig (nếu không hai vhost sẽ gây trở ngại cho nhau).
    Khởi động lại Apache:
    etc/init.d/apache2 reload
    Vậy là bạn đã có thể truy cập SquirrelMail theo http://webmail.example.com.
  7. 21. Cấu hình ISPConfig 3

    Để cài đặt ISPConfig 3 từ bản mới nhất, sử dụng lệnh;
    cd /tmp
    wget http://www.ispconfig.org/downloads/ISPConfig-3-stable.tar.gz
    tar xfz ISPConfig-3-stable.tar.gz
    cd ispconfig3_install/install/

    Tiếp theo chạy:
    php -q install.php
    Bộ cài đặt ISPConfig 3 sẽ cấu hình tất cả các dịch vụ như Postfix, SASL, Courie... cho bạn.
    Mã:
    root@server1:/tmp/ispconfig3_install/install# php -q install.php
     
     
    --------------------------------------------------------------------------------
    _____ ___________  _____              __ _        ____
    |_  _/  ___| ___ \ /  __ \            / _(_)      /__  \
      | | \ `--.| |_/ / | /  \/ ___  _ __ | |_ _  __ _    _/ /
      | |  `--. \  __/  | |    / _ \| '_ \|  _| |/ _` |  |_ |
    _| |_/\__/ / |    | \__/\ (_) | | | | | | | (_| | ___\ \
    \___/\____/\_|      \____/\___/|_| |_|_| |_|\__, | \____/
                                                  __/ |
                                                |___/
    --------------------------------------------------------------------------------
     
     
    >> Initial configuration
     
    Operating System: Debian or compatible, unknown version.
     
        Following will be a few questions for primary configuration so be careful.
        Default values are in [brackets] and can be accepted with <ENTER>.
        Tap in "quit" (without the quotes) to stop the installer.
     
     
    Select language (en,de) [en]: <-- ENTER
     
    Installation mode (standard,expert) [standard]: <-- ENTER
     
    Full qualified hostname (FQDN) of the server, eg server1.domain.tld  [server1.example.com]: <-- ENTER
     
    MySQL server hostname [localhost]: <-- ENTER
     
    MySQL root username [root]: <-- ENTER
     
    MySQL root password []: <-- yourrootsqlpassword
     
    MySQL database to create [dbispconfig]: <-- ENTER
     
    MySQL charset [utf8]: <-- ENTER
     
    Generating a 2048 bit RSA private key
    ...+++
    .................................................................+++
    writing new private key to 'smtpd.key'
    -----
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    What you are about to enter is what is called a Distinguished Name or a DN.
    There are quite a few fields but you can leave some blank
    For some fields there will be a default value,
    If you enter '.', the field will be left blank.
    -----
    Country Name (2 letter code) [AU]: <-- ENTER
    State or Province Name (full name) [Some-State]: <-- ENTER
    Locality Name (eg, city) []: <-- ENTER
    Organization Name (eg, company) [Internet Widgits Pty Ltd]: <-- ENTER
    Organizational Unit Name (eg, section) []: <-- ENTER
    Common Name (eg, YOUR name) []: <-- ENTER
    Email Address []: <-- ENTER
    Configuring Jailkit
    Configuring SASL
    Configuring PAM
    Configuring Courier
    Configuring Spamassassin
    Configuring Amavisd
    Configuring Getmail
    Configuring Pureftpd
    Configuring BIND
    Configuring Apache
    Configuring Vlogger
    Configuring Apps vhost
    Configuring Firewall
    Installing ISPConfig
    ISPConfig Port [8080]: <-- ENTER
     
    Configuring DBServer
    Installing ISPConfig crontab
    no crontab for root
    no crontab for getmail
    Restarting services ...
    Rather than invoking init scripts through /etc/init.d, use the service(8)
    utility, e.g. service mysql restart
     
    Since the script you are attempting to invoke has been converted to an
    Upstart job, you may also use the stop(8) and then start(8) utilities,
    e.g. stop mysql ; start mysql. The restart(8) utility is also available.
    mysql stop/waiting
    mysql start/running, process 2302
    * Stopping Postfix Mail Transport Agent postfix
      ...done.
    * Starting Postfix Mail Transport Agent postfix
      ...done.
    * Stopping SASL Authentication Daemon saslauthd
      ...done.
    * Starting SASL Authentication Daemon saslauthd
      ...done.
    Stopping amavisd: amavisd-new.
    Starting amavisd: amavisd-new.
    * Stopping ClamAV daemon clamd
      ...done.
    * Starting ClamAV daemon clamd
    Bytecode: Security mode set to "TrustSigned".
      ...done.
    * Stopping Courier authentication services authdaemond
      ...done.
    * Starting Courier authentication services authdaemond
      ...done.
    * Stopping Courier IMAP server imapd
      ...done.
    * Starting Courier IMAP server imapd
      ...done.
    * Stopping Courier IMAP-SSL server imapd-ssl
      ...done.
    * Starting Courier IMAP-SSL server imapd-ssl
      ...done.
    * Stopping Courier POP3 server...
      ...done.
    * Starting Courier POP3 server...
      ...done.
    * Stopping Courier POP3-SSL server...
      ...done.
    * Starting Courier POP3-SSL server...
      ...done.
    * Restarting web server apache2
    ... waiting ....  ...done.
    Restarting ftp server: Running: /usr/sbin/pure-ftpd-mysql-virtualchroot -l mysql:/etc/pure-ftpd/db/mysql.conf -l pam -8 UTF-8 -O clf:/var/log/pure-ftpd/transfer.log -D -H -b -A -E -u 1000 -Y 1 -B
    Installation completed.
    root@server1:/tmp/ispconfig3_install/install#
    Các dịch vụ được cấu hình tự động nên bạn không cần thiết lập thủ công.
    Sau đó bạn có thể truy cập ISPConfig 3 theo http://server1.example.com:8080/ hoặc http://192.168.0.100:8080/. Đăng nhập vào với tên tài khoản và mật khẩu đều là admin (bạn nên thay đổi mật khẩu mặc định này sau lần đăng nhập đầu tiên).
    [IMG]
    [IMG]
    Hệ thống của bạn đã sẵn sàng để sử dụng.
    22. Các link tham khảo

    Ubuntu: http://www.ubuntu.com/
    ISPConfig: http://www.ispconfig.org/

    Đ.Hải (Nguồn HowtoForge)

Chia sẻ trang này