Queste note permettono di creare tutti i server virtuali che si vogliono in un unico PC.
Utile per emulare pagine Web in locale o per avere tanti server Web funzionanti in rete.
Prima di procedere a descrivere lo script, è meglio saper creare un server fisico nella propria rete con un IP fisico locale.
Apriamo un terminale e ci logghiamo come Root e incolliamo quando segue:
Code: Select all
urpmi task-lamp -a -y
urpmi ssh -a -y
urpmi drakwizard -y
urpme proftpd -a -y
urpmi pure-ftpd- -a -y
ifconfig eth0 | awk '/inet/ {print $2}'> /file.txt; i=$(cat /file.txt);rm -f /file.txt;i=${i:5};echo $i | awk '/addr/ {print $1}' > /etc/ip; i=$(cat /etc/ip)
ns=$(echo $HOSTNAME)
echo; echo -n "Nome da assegnare al server fisico: ["${ns}"]-->"; read nsf
if [ ! $nsf ]; then
nsf=$ns
fi
echo "HOSTNAME="$nsf >> /etc/sysconfig/network
export HOSTNAME=${nsf}
echo $nsf > /etc/hostname
echo "<html><body><h1>It works!</h1>" > /var/www/html/index.html
echo "<p>This is the default web page for this server.</p>" >> /var/www/html/index.html
echo "<p>The web server software is running but no content has been added, yet.</p>" >> /var/www/html/index.html
echo "<p>Benvenuto su http://$nfs</p>" >> /var/www/html/index.html
echo "<p>IP per il servizio FTP: $nfs</p>" >> /var/www/html/index.html
echo "<p>Percorso fisico su $nsf: /var/www/html/</p>" >> /var/www/html/index.html
echo "</body></html>" >> /var/www/html/index.html
echo $i" "$nfs >> /etc/hosts
Dopo il riavvio del sistema si esegue il seguente script per generare l'host virtuale:
Code: Select all
#! /bin/bash
# Script da salvare in: /usr/sbin/ del server
echo "##########################################################################"
echo "# MKVHOST - (c)-2010 - Vr. 1.0 - /06/07/2010 #"
echo "# Procedura automatica per generare un Host Virtuale Web nel server; #"
echo "##########################################################################"
echo
if [ ! -f /etc/hostname ]; then
echo "ERRORE: Questo computer e' sprovvisto di un nome o mancano il server HTTPD!"
echo -n "Vuoi assegnare un nome a questo server (s/n)? [s] -->"; read sn
if [ ! $sn ]; then
sn="s"
else
sn="n"
fi
if [ $sn == "s" ]; then
ns=$(echo $HOSTNAME)
echo; echo -n "Nome da assegnare al server fisico: ["${ns}"]-->"; read nsf
if [ ! $nsf ]; then
nsf=$ns
fi
echo "HOSTNAME="$nsf >> /etc/sysconfig/network
export HOSTNAME=${nsf}
echo $nsf > /etc/hostname
echo; echo "Riesegui il comando: MKVHOST"
fi
exit 1
fi
ifconfig eth0 | awk '/inet/ {print $2}'> /file.txt; i=$(cat /file.txt);rm -f /file.txt;i=${i:5};echo $i | awk '/addr/ {print $1}' > /etc/ip; i=$(cat /etc/ip)
echo $i" "$(cat /etc/hostname)
echo -n "Nome del server Virtuale da generare: -->"; read vserver
nsip=$i
ni=${nsip:0:9}
echo -n "Numero IP dell'Host Virtuale ${ni}.### (Solo parte finale IP): -->"; read nvip
nvip=${ni}"."${nvip}
echo $nvip
echo; echo -n "Nome utente: -->"; read utente
echo
webdir="/home/"${utente}"/web/"${vserver}
if [ ! "/home/"${utente} ]; then
echo "UTENTE: ${utente} NON ESISTE."
exit 1
fi
mkdir -p ${webdir}
echo "<html><body><h1>It works!</h1>" > ${webdir}/index.html
echo "<p>This is the default web page for this server.</p>" >> ${webdir}/index.html
echo "<p>The web server software is running but no content has been added, yet.</p>" >> ${webdir}/index.html
echo "<p>Benvenuto su http://$nsip</p>" >> ${webdir}/index.html
echo "<p>Server Virtuale: $vserver</p>" >> ${webdir}/index.html
echo "<p>IP Virtuale: $nvip</p>" >> ${webdir}/index.html
echo "<p>IP per il servizio FTP: $nsip</p>" >> ${webdir}/index.html
echo "<p>Utente proprietario: $utente</p>" >> ${webdir}/index.html
echo "<p>Directory fisica sul server: /home/$utente/web/$vserver/</p>" >> ${webdir}/index.html
echo "</body></html>" >> ${webdir}/index.html
chmod -R 777 /home/${utente}/web
chown -R ${utente}:${utente} /home/${utente}/web
if [ /etc/httpd/conf/nvh ]; then
nh=$(cat /etc/httpd/conf/nvh)
else
nh="0"
fi
nh=$(expr $nh + 1)
echo "Generazione: VirtualHost N° "$nh
echo $nh > /etc/httpd/conf/nvh
if [ ! /bin/vhost ]; then
echo "#! /bin/bash" > /bin/vhost
echo "##############" >> /bin/vhost
echo "# /bin/vhost #" >> /bin/vhost
echo "#################################" >> /bin/vhost
echo "# Procedura generata da MKVHOST #" >> /bin/vhost
echo "#################################" >> /bin/vhost
echo "# script to run on bootup to bind additional IP addresses to the" >> /bin/vhost
echo "# ethernet interface." >> /bin/vhost
echo "" >> /bin/vhost
cd /bin
chmod 777 vhost
cd /
echo "vhost" >> /etc/rc.d/rc.local
fi
echo "echo \"Assign IP: ${nvip} to Virtual Hosts: ${vserver}\"" >> /bin/vhost
echo "ifconfig eth0:"$nh" add $nvip" >> /bin/vhost
if [ ! /etc/httpd/conf/vhosts.d/vhosts.conf ]; then
echo "########################################" > /etc/httpd/conf/vhosts.d/vhosts.conf
echo "# /etc/httpd/conf/vhosts.d/vhosts.conf #" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo "########################################" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo "# Procedura generata da MKVHOST #" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo "#################################" >> /etc/httpd/conf/vhosts.d/vhosts.conf
fi
echo "" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo "# NOME VIRTUAL HOST: "$vserver >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo "# PROPRIETARIO: "$utente >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo "NameVirtualHost ${nvip}" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo "<VirtualHost ${nvip}>" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo " ServerName ${vserver}" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo " ServerAlias www.${vserver}" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo " ErrorLog logs/sick-internals-error_log" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo " ServerPath /home/${utente}/web" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo " DocumentRoot /home/${utente}/web/${vserver}" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo " <Directory \"\">" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo " Options Indexes FollowSymLinks MultiViews" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo " AllowOverride None" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo " Order allow,deny" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo " Allow from all" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo " </Directory>" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo "</VirtualHost>" >> /etc/httpd/conf/vhosts.d/vhosts.conf
echo $nvip" "$vserver >> /etc/hosts
echo; echo "Aggiungere la seguente riga in \"/etc/hosts\" dei PC Client."
echo; echo $nvip" "$vserver" www."$vserver
echo; echo "Riavvio il Server HTTPD:"
service httpd restart
vhost
echo; echo "Editare dal browser: http://"$nvip
Naturalmente datene i permessi in esecuzione:
Code: Select all
chmod 777 /usr/sbin/mkvhost
Riepilogando allego delle istruzioni con i punti da seguire:
Ogni Host virtuale avrà anche un IP virtuale oltre al suo nome.Istruzioni per le configurazioni:
1) installi Mandriva client su PC senza selezionare la parte dei server durante l'installazione
2) assegnare un IP statico del tipo: 192.168.0.XX o 192.168.1.xx (dipende dal tuo router) al PC
3) eseguire un normale aggiornamento dei pacchetti da repository
4) riavviare il sistema
5) apri la consolle e ti logghi come Root
6) Installare e configurare un server fisico, (come sopra)
7) disattivare tutte le porte del firewall da pannello di controllo -> sicurezza
8) riavviare il sistema e già si ha il server fisico con HTTP://<ip server> e FTP anonymouse FTP://<ip server>
9) eseguire da consolle il comando DRAKWIZARD e settare SSH (se lo si vuole)
10) sempre con una consolle come Root esegui il comando: MKVHOST per generare il primo server virtuale
Così si potranno creare tutti i server virtuali che si vogliono con relativi IP virtuali per ogni utente diverso.
Ogni utente registrato al server, attraverso un client-ftp entra nel proprio spazio e si gestisce i propri server virtuali.
Mysql è installato bisogna attivare l'utente amministratore esempio:
Code: Select all
mysqladmin -u <utente> password <password>
Fatemi sapere come vi trovate con questo script !
Ciao
Qualcuno può tradurre in inglese questa guida?