Instalando e Configurando o ISPConfig no Debian Squeeze
O ISPConfig é um utilitário de administração via web que oferece a possibilidade de administrar o Apache, Bind, Proftpd, MySQL, Postfix e outros serviços através de uma interface centralizada. Ele se propõe a ser uma ferramenta completa para gerenciamento de servidores de shared-hosting similar ao cPanel, mas com a vantagem de ser aberto (disponibilizado dentro da licença BSD) e gratuito, sem limitações com relação a modificações ou mesmo ao uso para fins comerciais.
Com alguns servidores dedicados e o ISPConfig, você pode muito bem abrir sua própria empresa de hospedagem. Ele oferece interfaces de administração separadas para administradores(acesso completo), revendedores (que podem criar novas contas, sem alterar as configurações administrativas), webmasters (que podem criar contas de e-mail, ter acesso às estatísticas de acesso e assim por diante) e usuários finais, que tem acesso apenas às suas contas de email.
A maior vantagem do ISPConfig é que ele trabalha diretamente com os daemons referentes a cada serviço, o que permite que ele trabalhe em qualquer distribuição que inclua versões suportadas dos serviços. Isso permite que você o utilize sobre o Debian, CentOS, Ubuntu, ou outra distribuição de sua escolha.
Prepare o seu sistema com o seguinte script Easy-Debian para que não falte nenhum pacote ou configuração.
O que vou utilizar:
- Servidor Debian
- IP: 192.168.1.31/24
- Hostname: isp.douglasqsantos.com.br
Vamos fazer um update dos repositórios e vamos fazer um upgrade do sistema
aptitude update && aptitude dist-upgrade -y
Agora vamos instalar os pacotes para o acesso ao servidor via ssh
aptitude install ssh openssh-server -y
Agora vamos acertar o /etc/hosts
vim /etc/hosts 127.0.0.1 localhost 192.168.1.31 isp.douglasqsantos.com.br isp # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
Agora vamos acertar o hostname da nossa máquina
vim /etc/hostname isp.douglasqsantos.com.br
Agora vamos mandar o sistema reconhecer o novo nome do servidor
/etc/init.d/hostname.sh start
Agora vamos testar o nome do nosso servidor
hostname -f isp.douglasqsantos.com.br
Agora vamos acertar o shell default do sistema, quando for questionado pelo menu selecione No
dpkg-reconfigure dash
Agora vamos instalar os pacotes para o ntp que vai sincronizar o horário do nosso sistema
aptitude install ntp ntpdate -y
Agora vamos instalar os serviços de email e o banco de dados
aptitude 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 courier-maildrop getmail4 rkhunter binutils sudo gamin -y
Aqui vamos ser questionados sobre a senha do root do MySQL defina ela e confirme, depois em Create directories for web-based administrator informe no, e depois vamos ser questionados sobre o ssl só confirme
Agora vamos fazer um ajuste no arquivo de configuração do MySQL para que ele responda por todas as interfaces do nosso servidor.
sed -i 's/bind-address/#bind-address/g' /etc/mysql/my.cnf
Agora vamos reiniciar o apache
/etc/init.d/mysql restart
Agora vamos remover os certificados gerados na instalação do courier
cd /etc/courier rm -f /etc/courier/imapd.pem rm -f /etc/courier/pop3d.pem
Agora vamos acertar a configuração para gerarmos os certificados novamente
Vamos configurar o imap
vi /etc/courier/imapd.cnf RANDFILE = /usr/lib/courier/imapd.rand [ req ] default_bits = 1024 encrypt_key = yes distinguished_name = req_dn x509_extensions = cert_type prompt = no [ req_dn ] C=BR ST=PR L=Curitiba O=Courier Mail Server OU=Douglas IMAP SSL key CN=isp.douglasqsantos.com.br emailAddress=postmaster@douglasqsantos.com.br [ cert_type ] nsCertType = server
Agora vamos configurar o pop
vi /etc/courier/pop3d.cnf RANDFILE = /usr/lib/courier/pop3d.rand [ req ] default_bits = 1024 encrypt_key = yes distinguished_name = req_dn x509_extensions = cert_type prompt = no [ req_dn ] C=BR ST=PR L=Curitiba O=Courier Mail Server OU=Douglas POP3 SSL key CN=isp.douglasqsantos.com.br emailAddress=postmaster@douglasqsantos.com.br [ cert_type ] nsCertType = server
Agora vamos gerar os certificados novamente
mkimapdcert mkpop3dcert
Agora vamos instalar o Amavis, SpamAssassin e o Clamav
aptitude 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 -y
Agora vamos remover o spamassasin da inicialização pois o amavis vai invocar ele internamente
/etc/init.d/spamassassin stop insserv -r -f spamassassin
Agora vamos preparar o ambiente web, vamos dar suporte ao php, ruby, python e vamos instalar os módulos necessários para isso
aptitude 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 -y
Aqui vamos ser questionados sobre o phpmyadmin então selecione apache2, e depois disso selecione No.
Agora vamos habilitar os módulos do apache
a2enmod suexec rewrite ssl actions include a2enmod dav_fs dav auth_digest
Agora vamos reiniciar o apache
/etc/init.d/apache2 restart
Agora vamos instalar o servidor ftp e o suporte a quota de sistema
aptitude install pure-ftpd-common pure-ftpd-mysql quota quotatool -y
Agora vamos ajustar o pure-ftpd trabalhar em modo chroot
sed -i 's/VIRTUALCHROOT=false/VIRTUALCHROOT=true/g' /etc/default/pure-ftpd-common
Agora vamos habilitar o pure-ftpd a trabalhar com tls
echo 1 > /etc/pure-ftpd/conf/TLS
Agora vamos criar o diretório que vai armazenar as chaves
mkdir -p /etc/ssl/private/
Agora vamos gerar a nossa chave
openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem Generating a 2048 bit RSA private key ....+++ ....................................................................................+++ writing new private key to '/etc/ssl/private/pure-ftpd.pem' ----- 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]:BR string is too long, it needs to be less than 2 bytes long Country Name (2 letter code) [AU]:BR State or Province Name (full name) [Some-State]:Parana Locality Name (eg, city) []:Curitiba Organization Name (eg, company) [Internet Widgits Pty Ltd]:Douglas Organizational Unit Name (eg, section) []:TI Common Name (eg, YOUR name) []:isp.douglasqsantos.com.br Email Address []:douglas@douglasqsantos.com.br
Agora vamos ajustar as permissões as chaves
chmod 600 /etc/ssl/private/pure-ftpd.pem
Agora vamos reiniciar o pure-ftpd
/etc/init.d/pure-ftpd-mysql restart
Agora precisamos ativar o suporte a quota, com isso precisamos adicionar as seguintes opções usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0 na partição /var ou / se o var estiver na mesma partição
vim /etc/fstab [...] UUID=c6d7c021-c58d-4516-b59b-3f057fb886e0 /var ext3 defaults,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0 0 2 [...]
Agora vamos mandar habilitar as quotas
mount -o remount /var quotacheck -avugm quotaon -avug
Agora vamos mandar instalar o bind
apt-get install bind9 dnsutils -y
Agora vamos instalar geradores de relatórios de acesso
apt-get install vlogger webalizer awstats geoip-database -y
Agora vamos comentar as linhas do cron do awstat
sed -i 's/^/#/' /etc/cron.d/awstats
Agora vamos mandar instalar os pacotes dependência para podermos instalar o jailkit.
aptitude install build-essential autoconf automake1.9 libtool flex bison debhelper -y
Agora vamos obter o jailkit
cd /tmp wget http://wiki.douglasqsantos.com.br/Downloads/security/jailkit-2.13.tar.gz
Agora vamos mandar desempacotar ele e vamos acessar o diretório
tar -xzvf jailkit-2.13.tar.gz cd jailkit-2.13
Agora vamos mandar gerar o pacote
./debian/rules binary
Agora vamos mandar instalar o jailkit
cd .. dpkg -i jailkit_2.13-1_*.deb
Agora vamos mandar remover o que não precisamos mais
rm -rf jailkit-2.13*
Agora vamos mandar instalar o fail2ban que é um IDS bem leve
aptitude install fail2ban -y
Agora vamos gerar a configuração para o pureftp, sasl e courier
vi /etc/fail2ban/jail.local [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
Agora vamos criar o filtro para o pureftpd
vi /etc/fail2ban/filter.d/pureftpd.conf [Definition] failregex = .*pure-ftpd: \(.*@<HOST>\) \[WARNING\] Authentication failed for user.* ignoreregex =
Agora vamos gerar o filtro para o pop
vi /etc/fail2ban/filter.d/courierpop3.conf # 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 =
Agora vamos gerar o filtro para o pop com ssl
vi /etc/fail2ban/filter.d/courierpop3s.conf # 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 =
Agora vamos gerar o filtro para o imap
vi /etc/fail2ban/filter.d/courierimap.conf # 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 =
Agora vamos gerar o filtro para o imap com ssl
vi /etc/fail2ban/filter.d/courierimaps.conf # 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 =
Agora vamos reiniciar o fail2ban
/etc/init.d/fail2ban restart
Agora vamos instalar o SquirrelMail
aptitude install squirrelmail -y
Agora vamos criar um link para o /var/www
ln -s /usr/share/squirrelmail/ /var/www/webmail
Agora vamos configurar ele
squirrelmail-configure
- Na primeira tela pressione D
- Na segunda informe courier
- Na próxima enter
- Na próxima informe S
- Na ultimá informe Q
Agora vamos obter o ISPConfig
cd /tmp wget -c http://wiki.douglasqsantos.com.br/Downloads/misc/ISPConfig-3-stable.tar.gz
Agora vamos desempacotar o ISPConfig
tar -xzvf ISPConfig-3-stable.tar.gz
Agora vamos acessar o diretório do ISPConfig
cd ispconfig3_install/install/
Agora vamos configurar o ispconfig
php -q install.php -------------------------------------------------------------------------------- _____ ___________ _____ __ _ ____ |_ _/ ___| ___ \ / __ \ / _(_) /__ \ | | \ `--.| |_/ / | / \/ ___ _ __ | |_ _ __ _ _/ / | | `--. \ __/ | | / _ \| '_ \| _| |/ _` | |_ | _| |_/\__/ / | | \__/\ (_) | | | | | | | (_| | ___\ \ \___/\____/\_| \____/\___/|_| |_|_| |_|\__, | \____/ __/ | |___/ -------------------------------------------------------------------------------- >> Initial configuration Operating System: Debian 6.0 (Squeeze/Sid) or compatible 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
Agora vamos configurar o núcleo do ispconfig
Installation mode (standard,expert) [standard]: #ENTER Full qualified hostname (FQDN) of the server, eg server1.domain.tld [isp.douglasqsantos.com.br]: #ENTER MySQL server hostname [localhost]: #ENTER MySQL root username [root]: #ENTER MySQL root password []: #senhadoroot MySQL database to create [dbispconfig]: #ENTER MySQL charset [utf8]: #ENTER
Agora vamos a configuração do tls
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]:BR State or Province Name (full name) [Some-State]:Parana Locality Name (eg, city) []:Curitiba Organization Name (eg, company) [Internet Widgits Pty Ltd]:Douglas Organizational Unit Name (eg, section) []:TI Common Name (eg, YOUR name) []:isp.douglasqsantos.com.br Email Address []:douglas@douglasqsantos.com.br
Agora vamos definir a porta padrão do ispconfig
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 Bastille Firewall Configuring Fail2ban Installing ISPConfig ISPConfig Port [8080]: #ENTER
Agora vamos configurar o suporte a SSL
Do you want a secure (SSL) connection to the ISPConfig web interface (y,n) [y]: Generating RSA private key, 4096 bit long modulus .......................................++ .............++ e is 65537 (0x10001) 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]:BR State or Province Name (full name) [Some-State]:Parana Locality Name (eg, city) []:Curitiba Organization Name (eg, company) [Internet Widgits Pty Ltd]:Douglas Organizational Unit Name (eg, section) []:TI Common Name (eg, YOUR name) []:isp.douglasqsantos.com.br Email Address []:douglas@douglasqsantos.com.br Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:Douglas writing RSA key
Agora é só aguardar o termino da instalação
Configuring DBServer Installing ISPConfig crontab no crontab for getmail Restarting services ... Stopping MySQL database server: mysqld. Starting MySQL database server: mysqld. Checking for corrupt, not cleanly closed and upgrade needing tables.. Stopping Postfix Mail Transport Agent: postfix. Starting Postfix Mail Transport Agent: postfix. Stopping SASL Authentication Daemon: saslauthd. Starting SASL Authentication Daemon: saslauthd. Stopping amavisd: amavisd-new. Starting amavisd: amavisd-new. Stopping ClamAV daemon: clamd. Starting ClamAV daemon: clamd . Stopping Courier authentication services: authdaemond. Starting Courier authentication services: authdaemond. Stopping Courier IMAP server: imapd. Starting Courier IMAP server: imapd. Stopping Courier IMAP-SSL server: imapd-ssl. Starting Courier IMAP-SSL server: imapd-ssl. Stopping Courier POP3 server: pop3d. Starting Courier POP3 server: pop3d. Stopping Courier POP3-SSL server: pop3d-ssl. Starting Courier POP3-SSL server: pop3d-ssl. Restarting web server: apache2 ... waiting . Restarting ftp server: Running: /usr/sbin/pure-ftpd-mysql-virtualchroot -l mysql:/etc/pure-ftpd/db/mysql.conf -l pam -Y 1 -b -8 UTF-8 -O clf:/var/log/pure-ftpd/transfer.log -E -D -u 1000 -H -A -B Installation completed.
Agora precisamos fazer mais um ajuste o isp tem que utilizar ele mesmo como DNS
vim /etc/resolv.conf nameserver 192.168.1.31
Agora podemos acessar o painel de administração em https://isp.douglasqsantos.com.br:8080 ou https://ip_servidor:8080 o usuário é admin e a senha é admin
No gerenciamento tente seguir a seguinte sequencia:
- Criar um cliente
- Criar um domínio
- Criar o Site
- Criar o acesso ao FTP
Tela de login do ISPconfig
Tela inicial do ISPconfig
Tela de configuração de idioma e troca de senha do ISPconfig
Tela de criação de cliente do ISPconfig
Tela de criação de zona DNS do ISPconfig
Tela de criação do virtualhost do cliente
Tela de criação do cliente FTP para o cliente do ISPconfig
Agora vamos fazer alguns testes.
Vou consultar o domínio que eu criei
nslookup douglasqsantos.com.br Server: 192.168.1.31 Address: 192.168.1.31#53 Name: douglasqsantos.com.br Address: 192.168.1.31
Agora vou fazer um teste do ftp
ftp www.douglasqsantos.com.br Connected to www.douglasqsantos.com.br (192.168.1.31). 220---------- Welcome to Pure-FTPd [privsep] [TLS] ---------- 220-You are user number 1 of 50 allowed. 220-Local time is now 21:54. Server port: 21. 220-This is a private system - No anonymous login 220-IPv6 connections are also welcome on this server. 220 You will be disconnected after 15 minutes of inactivity. Name (www.douglasqsantos.com.br:quintiliano): douglas01 331 User douglas01 OK. Password required Password: 230-User douglas01 has group access to: client1 sshusers 230 OK. Current restricted directory is / Remote system type is UNIX. Using binary mode to transfer files. ftp> ls 227 Entering Passive Mode (192,168,1,31,128,75) 150 Accepted data connection drwxr-x--x 6 5004 client1 4096 Dec 31 21:46 . drwxr-x--x 6 5004 client1 4096 Dec 31 21:46 .. drwxr-x--x 2 5004 client1 4096 Dec 31 21:46 cgi-bin drwxr-xr-x 2 5004 client1 4096 Dec 31 21:46 log drwxr-x--x 2 5004 client1 4096 Dec 31 21:46 ssl drwxrwxrwx 2 5004 client1 4096 Dec 31 21:46 tmp drwx--x--- 4 5004 client1 4096 Dec 31 21:46 web 226-Options: -a -l 226 7 matches total ftp> quit 221-Goodbye. You uploaded 0 and downloaded 0 kbytes. 221 Logout.
Agora vou acessar no navegador o site teste http://www.douglasqsantos.com.br
Vamos ter algo como abaixo.