Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

3.4. Servizi multi-port e LVS

LVS routers under any topology require extra configuration when creating multi-port LVS services. Multi-port services can be created artificially by using firewall marks to bundle together different, but related protocols, such as HTTP (port 80) and HTTPS (port 443), or when LVS is used with true multi-port protocols, such as FTP. In either case, the LVS router uses firewall marks to recognize that packets destined for different ports, but bearing the same firewall mark, should be handled identically. Also, when combined with persistence, firewall marks ensure connections from the client machine are routed to the same host, as long as the connections occur within the length of time specified by the persistence parameter. For more on assigning persistence to a virtual server, see Sezione 4.6.1, «La sottosezione SERVER VIRTUALE».
Sfortunatamente il meccanismo usato per bilanciare il carico sui real server — IPVS — è in grado di riconoscere i firewall mark assegnati ad un pacchetto, ma non di assegnare i firewall mark. Il compito di assegnare i firewall mark deve essere espletato dal filtro del pacchetto di rete, iptables, esternamente al Piranha Configuration Tool.

3.4.1. Assegnazione dei firewall mark

Per assegnare i firewall mark ad un pacchetto destinato ad una porta particolare, l'amministratore dovrà utilizzare iptables.
This section illustrates how to bundle HTTP and HTTPS as an example; however, FTP is another commonly clustered multi-port protocol. If an LVS is used for FTP services, refer to Sezione 3.5, «Configurazione di FTP» for configuration details.
La regola di base da ricordare quando si utilizzano i firewall mark e quella che per ogni protocollo che utilizza un firewall mark con il Piranha Configuration Tool, è necessaria la presenza di una regola iptables equivalente per assegnare i firewall mark ai pacchetti di rete.
Prima di creare le regole per il filtro dei pacchetti di rete, assicuratevi che non siano presenti altre regole. Per fare questo aprite un prompt della shell, registratevi come utente root e digitate:
/sbin/service iptables status
Se iptables non è in esecuzione, il prompt apparirà istantaneamente.
Se iptables è attivo, esso visualizzerà un set di regole. Se sono presenti alcune regole, digitate il seguente comando:
/sbin/service iptables stop
Se le regole già presenti sono regole importanti, controllate il contenuto di /etc/sysconfig/iptables e copiate qualsiasi regola importante in un luogo sicuro prima di procedere.
Di seguito vengono riportate le regole che assegnano lo stesso firewall mark, 80, al traffico in ingresso destinato all'indirizzo IP floating, n.n.n.n, su porte 80 e 443.
/sbin/modprobe ip_tables
/sbin/iptables -t mangle -A PREROUTING -p tcp -d n.n.n.n/32 --dport 80 -j MARK --set-mark 80
/sbin/iptables -t mangle-A PREROUTING -p tcp -d n.n.n.n/32 --dport 443 -j MARK --set-mark 80
For instructions on assigning the VIP to the public network interface, see Sezione 4.6.1, «La sottosezione SERVER VIRTUALE». Also note that you must log in as root and load the module for iptables before issuing rules for the first time.
Nei comandi iptables sopra riportati, n.n.n.n deve essere sostituito con l'IP floating per i vostri server virtuali HTTP e HTTPS. Questi comandi avranno l'effetto di assegnare a qualsiasi traffico indirizzato al VIP sulle porte appropriate, un firewall mark di 80, il quale a sua volta viene riconosciuto da IPVS ed inoltrato in modo appropriato.

Avvertimento

The commands above will take effect immediately, but do not persist through a reboot of the system. To ensure network packet filter settings are restored upon reboot, refer to Sezione 3.6, «Come salvare le impostazioni per il filtro del pacchetto di rete»