ASIX/M08/UF1/P41/2
Contingut
- 1 Programari
- 1.1 PHP 7
- 1.2 Development tools
- 1.3 Apache, MariaDB, PHPMyAdmin
- 1.4 Dovecot
- 1.5 Postfix
- 1.6 Getmail
- 1.7 Posada a punt MariaDB
- 1.8 Configuració Apache - PHPMyAdmin
- 1.9 Instal·larem Amavisd-new, SpamAssassin, ClamAV, i Postgrey
- 1.10 Instal·lació de mòduls Apache: mod_php, mod_fcgi/PHP, PHP-FPM
- 1.11 Instal·lació mod_python
- 1.12 PureFTPd
- 1.13 Instal·lació BIND
- 1.14 Instal·lació Webalizer i AWStats
- 1.15 Instal·lació Jailkit
- 1.16 Instal·lació Fail2Ban
Programari
PHP 7
Haurem d'afegir primer el repositori EPEL amb
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
i el repositori REMI:
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
També serà necessari instal·lar una utilitat de yum que permet canviar repositoris per defecte, de manera que quan instal·lem PHP, ens agafi el del repositori EPEL amb la versió 7:
yum install yum-utils
Una vegada instal·lades aquestes utilities, seleccionarem el repositori que volem activar segons la sub-versió que volguem instal·lar de PHP: 7.0, 7.1 o 7.2: En aquest cas, instal·lo la versió 7.2
yum-config-manager --enable remi-php72
Una vegada activat el repo amb la versió de PHP seleccionada, instal·larem la versió 7.2 amb la comanda
yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
Per a comprovar la versió de PHP que està instal·lada i en funcionament actualment podem executar un
php -v
I ens donarà una sortida:
PHP 7.2.12 (cli) (built: Nov 6 2018 16:40:25) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Això és senyal que s'ha instal·lat i està a punt el PHP 7.2.5. Ara és qüestió de recarregar la configuració del servidor web Apache perquè utilitzi la versió PHP nova.
systemctl reload httpd
Development tools
Segons la documentació, hem d'instal·lar un conjunt de paquets amb la següent comanda:
yum -y groupinstall 'Development Tools'
Apache, MariaDB, PHPMyAdmin
yum -y install ntp httpd mod_ssl mariadb-server php php-mysql php-mbstring phpmyadmin
Dovecot
yum -y install dovecot dovecot-mysql dovecot-pigeonhole
Crearem un arxiu de configuració buit per al Dovecot:
touch /etc/dovecot/dovecot-sql.conf ln -s /etc/dovecot/dovecot-sql.conf /etc/dovecot-sql.conf ln -s /etc/dovecot/dovecot.conf /etc/dovecot.conf
Habilitarem l'engegada automàtica i arrencarem el servei per primera vegada:
systemctl enable dovecot systemctl start dovecot
Postfix
Instal·larem el programari postfix (pot ser que vagi preinstal·lat amb la minimal install de CentOS):
yum -y install postfix
També engegarem i habilitarem el servidor MariaDB per a la base de dades i reiniciarem el servei de postfix
systemctl enable mariadb systemctl start mariadb systemctl enable postfix systemctl restart postfix
Getmail
L'instal·larem com la resta de paquets
yum -y install getmail
Posada a punt MariaDB
Executarem el mysql_secure_installation per tal de configurar una contrasenya de root per al MariaDB, eliminar taules d'exemple, etc.
mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n]
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Configuració Apache - PHPMyAdmin
Obrirem l'arxiu /etc/httpd/conf.d/phpMyAdmin.conf amb un editor de text i buscarem la aquesta secció i la deixarem de la següent manera:
(...)
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
#Require ip 127.0.0.1
#Require ip ::1
Require all granted
</RequireAny>
</IfModule>
(...)
Després canviarem el mètode d'autenticació de PHPMyAdmin editant l'arxiu /etc/phpMyAdmin/config.inc.php de manera que tingui el següent contingut a la secció corresponent. Canviarem el valor per defecte cookie per http.
(...) $cfg['Servers'][$i]['auth_type'] = 'http'; (...)
Habilitarem l'arrencada automàtica del servidor web Apache (httpd) i el reiniciarem per carregar els canvis:
systemctl enable httpd systemctl restart httpd
Instal·larem Amavisd-new, SpamAssassin, ClamAV, i Postgrey
Se'ns instal·laran moltes dependències (uns 180MB entre tot, al moment d'escriure això).
yum -y install amavisd-new spamassassin clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd unzip bzip2 perl-DBD-mysql postgrey re2c
Configuració ClamAV
Editarem l'arxiu /etc/freshclam.conf i comprovarem que la línia amb Example estigui comentada:
(...) # Comment or remove the line below. #Example (...)
Per tal d'actualitzar automàticament les firmes de malware de ClamAV editarem l'arxiu /etc/sysconfig/freshclam i verificarem que la línia següent estigui comentada:
(...) # FRESHCLAM_DELAY=
Posada en marxa
Arrencarem els 3 serveis de la manera següent, després d'actualitzar les firmes de malware:
sa-update freshclam systemctl enable amavisd.service systemctl start amavisd.service systemctl start clamd@amavisd.service systemctl enable postgrey.service systemctl start postgrey.service
- Problema
Si al fer start de amavisd ens surt un error i no arrenca el servei, podem revisar què ha passat amb la comanda journalctl -xe i podem veure, en aquest cas:
nov 22 15:40:03 baseCentOS7 amavisd[21940]:The value of variable $myhostname is "baseCentOS7", but should have been nov 22 15:40:03 baseCentOS7 amavisd[21940]: a fully qualified domain name; perhaps uname(3) did not provide such. nov 22 15:40:03 baseCentOS7 amavisd[21940]: You must explicitly assign a FQDN of this host to variable $myhostname nov 22 15:40:03 baseCentOS7 amavisd[21940]: in amavisd.conf, or fix what uname(3) provides as a host's network name!
- Solució
Per tal de definir un FQDN (Fully-Qualified Domain Name) per a la màquina, editarem l'arxiu /etc/sysconfig/network i a la línia següent hi posarem el nom de host nou:
HOSTNAME=ispconfig.local
Per a ser consistents, haurem d'editar l'arxiu /etc/hosts per tal que la màquina sàpiga que aquell nom de domini és ella mateixa. Tenint en compte que aquesta màquina té IP 192.168.56.100, afegirem una línia nova a l'arxiu amb el següent contingut:
192.168.56.100 ispconfig.local ispconfig
Una vegada fet això, per aplicar-ho al mateix moment, farem servir la comanda hostname per a definir el nom de màquina i aplicar-ho:
hostname ispconfig.local
Sempre és bo fer un reinici per tal d'assegurar-nos que els canvis s'han aplicat: init 6
En aquest punt, podem executar systemctl start amavisd.service i no hauria de donar problemes i seguir amb les comandes de l'apartat anterior.
Instal·lació de mòduls Apache: mod_php, mod_fcgi/PHP, PHP-FPM
yum -y install php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-pecl-apc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy curl curl-devel perl-libwww-perl ImageMagick libxml2 libxml2-devel mod_fcgid php-cli httpd-devel php-fpm wget
Configuració PHP
Editarem l'arxiu /etc/php.ini i deshabilitarem la mostra d'errors, configurar la zona horària i descomentar cgi.fix_pathinfo=1 de manera que, les línies corresponents, quedin de la manera següent:
(...) error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT (...) date.timezone = 'Europe/Andorra' (...) cgi.fix_pathinfo=1 (...)
Habilitarem PHP-FPM i Apache de nou per tal d'aplicar aquest canvi en el motor de PHP:
systemctl start php-fpm.service systemctl enable php-fpm.service systemctl enable httpd.service systemctl start httpd.service
Suport per a Let's Encrypt (SSL)
Descarregarem el programari:
mkdir /opt/certbot cd /opt/certbot wget https://dl.eff.org/certbot-auto chmod a+x ./certbot-auto
Executarem certbot-auto. Ens sortirà el missatge no names were found in your configuration files. El que farem serà cancel·lar amb c ja que els certificats els farà el propi ISPConfig i aquest script només ens instal·larà possibles dependències que no tinguem i configurarà aspectes de Python com ara els virtual-envs:
[root@ispconfig certbot]# ./certbot-auto (...) Completat! Creating virtual environment... Installing Python packages... Installation succeeded. Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator apache, Installer apache Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): guillem_solaboeck@iescarlesvallbona.cat - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: a - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: n No names were found in your configuration files. Please enter in your domain name(s) (comma and/or space separated) (Enter 'c' to cancel): c Please specify --domains, or --installer that will help in domain names autodiscovery, or --cert-name for an existing certificate name. IMPORTANT NOTES: - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal.
Instal·lació mod_python
Pot ser que ja estigui instal·lat; sinó:
yum -y install python-devel
Llavors descarregarem el source code del mòdul i el compilarem:
cd /usr/local/src/ wget http://dist.modpython.org/dist/mod_python-3.5.0.tgz tar xfz mod_python-3.5.0.tgz cd mod_python-3.5.0 ./configure make
Abans de fer la instal·lació, executarem la següent ordre per evitar un problema que encalla la instal·lació:
sed -e 's/(git describe --always)/(git describe --always 2>\/dev\/null)/g' -e 's/`git describe --always`/`git describe --always 2>\/dev\/null`/g' -i $( find . -type f -name Makefile\* -o -name version.sh )
Després ja podrem:
make install
Habilitarem el mòdul a la configuració d'Apache i farem un restart del servei per recarregar el mòdul:
echo 'LoadModule python_module modules/mod_python.so' > /etc/httpd/conf.modules.d/10-python.conf systemctl restart httpd
PureFTPd
Instal·lem:
yum -y install pure-ftpd
Habilitem arrencada automàtica i engeguem:
systemctl enable pure-ftpd.service systemctl start pure-ftpd.service
Suport FTPS (FTP+SSL)
Instal·larem OpenSSL en cas de no estar instal·lat:
yum install openssl
Editarem l'arxiu /etc/pure-ftpd/pure-ftpd.conf per permetre que PureFTP pugui aprofitar els avantatges de SSL per a oferir una protecció al protocol FTP. Descomentarem la línia següent de manera que quedi així:
TLS 1 #El valor 1 significa que es permetran connexions tant xifrades com sense xifrar. Altres valors serien més restrictius: obligar a usar TLS o bé prohibir-lo totalment; per exemple
Per a usar SSL/TLS haurem de crear certificats:
mkdir -p /etc/ssl/private/ [root@ispconfig ~]# 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) [XX]:ES State or Province Name (full name) []: Locality Name (eg, city) [Default City]:Tona Organization Name (eg, company) [Default Company Ltd]:GSB Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) []:ispconfig.local Email Address []:guillem_solaboeck@iescarlesvallbona.cat [root@ispconfig ~]# chmod 600 /etc/ssl/private/pure-ftpd.pem [root@ispconfig ~]# openssl dhparam -out /etc/ssl/private/pure-ftpd-dhparams.pem 2048 Generating DH parameters, 2048 bit long safe prime, generator 2 This is going to take a long time .......................................................+........................................................................................+.............+........................................................................................+..........................................................................+........................+............................................................................................................ (...) ...............................................+..........+............................................................................................................................+.....................................................................+..........+............+.........................................................++*++*
Finalment, reiniciem el servidor FTP perquè recarregui el certificat TLS generat i pugui fer-lo servir en les comunicacions que ho demanin:
[root@ispconfig ~]# systemctl restart pure-ftpd.service
Instal·lació BIND
yum -y install bind bind-utils haveged
Farem una còpia de l'arxiu named.conf per defecte i en farem un de nou:
cp /etc/named.conf /etc/named.conf_bak cat /dev/null > /etc/named.conf
I en farem un de nou amb el següent contingut:
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { any; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
allow-recursion {"none";};
recursion no;
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.conf.local";
Per acabar, crearem l'arxiu /etc/named.conf.local que serà el que ISPConfig vagi omplint si afegim noves zones des d'allà:
touch /etc/named.conf.local
Finalment, habilitarem l'arrencada automàtica i engegarem els serveis:
systemctl enable named.service systemctl start named.service systemctl enable haveged.service systemctl start haveged.service
Instal·lació Webalizer i AWStats
yum -y install webalizer awstats perl-DateTime-Format-HTTP perl-DateTime-Format-Builder
Editarem l'arxiu /etc/httpd/conf.d/awstats.conf i deixarem la línia Require local d'aquesta manera:
Require all granted
Reiniciarem el servei per a aplicar els canvis:
systemctl restart httpd.service
Instal·lació Jailkit
És utilitzat per fer chroot als usuaris SSH i als cronjobs.
- Nota: és important instal·lar-lo abans de ISPConfig; no pot ser instal·lat després.
cd /tmp wget http://olivier.sessink.nl/jailkit/jailkit-2.19.tar.gz tar xvfz jailkit-2.19.tar.gz cd jailkit-2.19 ./configure make make install cd .. rm -rf jailkit-2.19*
Instal·lació Fail2Ban
És opcional però recomanable; ja que ISPConfig intenta mostrar-ne els logs.
yum -y install iptables-services fail2ban fail2ban-systemd
Fail2ban fa servir iptables per a aplicar les restriccions; per tant, deshabilitarem el firewall del sistema per evitar conflictes:
systemctl stop firewalld.service systemctl mask firewalld.service systemctl disable firewalld.service systemctl stop firewalld.service
Configuració
Editarem l'arxiu /etc/fail2ban/jail.local i hi posarem el contingut:
[sshd] enabled = true action = iptables[name=sshd, port=ssh, protocol=tcp] [pure-ftpd] enabled = true action = iptables[name=FTP, port=ftp, protocol=tcp] maxretry = 3 [dovecot] enabled = true action = iptables-multiport[name=dovecot, port="pop3,pop3s,imap,imaps", protocol=tcp] maxretry = 5 [postfix-sasl] enabled = true action = iptables-multiport[name=postfix-sasl, port="smtp,smtps,submission", protocol=tcp] maxretry = 3
L'engegarem i habilitarem la càrrega automàtica:
systemctl enable fail2ban.service systemctl start fail2ban.service