Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Virtual hosting made easy
View unanswered posts
View posts from last 24 hours

Goto page 1, 2, 3, 4  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Sat Sep 28, 2002 4:07 am    Post subject: Virtual hosting made easy Reply with quote

Recently faced with a requirement for a small virtual hosting system, I developed a system whereby administration is made easy. It's reasonably generic (generic enough), reasonably robust, and sufficient for most purposes. It's designed with special emphasis on Typo3, a killer content management system that has some interesting requirements.

The services provided by this include:
  • http:// for one or more arbitrary domain names
  • SSH/SCP/FTP access for your clients
  • MySQL username and database creation
  • Easy administration


The required programs:
  • Apache
  • MySQL (what's a website without a database backend?)
  • OpenSSH
  • Pure-FTPd (optional, and others work too)
  • Standard Bourne shell, Unix text processing utilities, etc.

All in all, pretty standard stuff. Moving along...

With my setup, Apache uses mod_rewrite to do some special dynamic name-based hosting. Standard dynamic virtual hosts don't let you have a default host, my mod_rewrite-based one does) Included the following in apache.conf:
Code:
RewriteEngine On

# a ServerName derived from a Host: header may be any case at all
RewriteMap  lowercase  int:tolower

RewriteCond  %{REQUEST_URI}  !^/icons/
# Duplicate the above for whatever other system-wide aliases you have
RewriteCond  /pub/www/hosts/${lowercase:%{SERVER_NAME}} -d
RewriteRule  ^/(.*)$  /pub/www/hosts/${lowercase:%{SERVER_NAME}}/$1 [L]

RewriteCond  %{REQUEST_URI}  !^/icons/
# Duplicate the above for whatever other system-wide aliases you have
RewriteRule  ^/(.*)$  /pub/www/default/$1

# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon

This maps the request to /pub/www/hosts/www.domain.com/ if it exists, or /pub/www/default/ if it does not exist. Additionally, it makes the log format easy to handle. The following script (placed wherever you feel like) runs on a schedule (via cron) at 23:59 daily -- it splits the log file into its respective virtual hosts. The logs end up at http://www.domain.com/logs/YYYY-MM-DD.log for easy usage. (You probably want to protect it with a .htaccess...)
Code:
#!/bin/bash

# Initialization
cd /pub/www/hosts
hosts=`find -type d -maxdepth 1 | egrep -v ^.$ | sed -e 's/^.\///g'`
now=`date +%Y-%m-%d`

# Copy and chop logfile
cp /var/log/apache/access_log access_log
echo -n > /var/log/apache/access_log

# Do the splittin
for i in $hosts
do
        mkdir -p $i/logs
        echo "# Access log for ${now}" >> $i/logs/${now}.log
        egrep '^'${i}' ' access_log | awk -F"${i} " '{print $2}' >> $i/logs/${now}.log
done

# Remote temporary log
rm access_log


At this point, Apache is all set up. Now, just four little scripts -- pick some place in your path to put 'em. The first script (user-new) creates a user as specified on the command line.
Code:
#!/bin/bash
if [[ (-z "$1") || (-z "$2") || (-n "$4") || ("$1" = "--help") ]]
then
        echo "Uber-nifty user creation utility"
        echo "Written by delta407 (delta407@lerfjhax.com)"
        echo
        echo "    Usage: "`basename $0`" username \"Full Name\" [password]"
        exit 0
fi

# Gather configuration
uname=`echo $1 | tr -d ' :.'`
rname=$2

# Password config
pass=`echo "${uname} ${rname}" | md5sum | head -c 7`
[[ "$3" ]] && pass=$3

# Setup complete, prompt
echo "Creating user with the following settings:"
echo "  - User: ${uname}"
echo "  - Real name: ${rname}"
echo "  - Password: ${pass}"

echo
echo " Ctrl-C now to abort, enter to continue"

read i

# User didn't abort, let's work magic
/usr/sbin/useradd -d /home/${uname} -m -g users -G cron -s /bin/bash ${uname}
chfn "${rname}" ${uname}

# Hack to make passwd work
{ echo ${pass}; sleep 1; echo ${pass}; } | passwd ${uname} 2>/dev/null

echo "** User creation successful"


Run this script for every user you make. (BTW, it gives them access to cron, which may or may not be desirable. You'll probably want to tweak it anyway.) Next up is pub-newsite, complete with auto-configuration for Typo3.
Code:
#!/bin/bash
if [[ (-z "$1") || (-n "$3") || ("$1" = "--help") ]]
then
        echo "Uber-nifty website creation utility"
        echo "Written by delta407 (delta407@lerfjhax.com)"
        echo
        echo "    Usage: "`basename $0`" www.domain.com [skeleton]"
        exit 0
fi

# Gather configuration
domain=$1
uname=`echo $1 | sed -e 's/^www\.//' -e 's/\.com$//' -e 's/\.org$//' -e 's/\.net$//' -e 's/\./-/g' | head -c 16`
db=$uname
pass=`echo ${uname} | md5sum | head -c 6`

# Check skeleton parameter validity
if [ "$2" ]
then
        skel=invalid
        [[ -f /pub/www-skel/$2.tbz2 ]] && skel=$2
        if [ "$skel" == "invalid" ]
        then
                echo "Invalid skeleton file. Valid ones are:"
                cd /pub/www-skel/
                ls | sed -e 's/^/ - /' -e 's/.tbz2$//g'
                exit 1
        fi
fi

# Setup complete, prompt
echo "Creating site with the following settings:"
echo "  - Domain: ${domain}"
echo "  - Database: ${db}"
echo "  - Username: ${uname}"
echo "  - Password: ${pass}"
[ "${skel}" ] && echo "  - Skeleton: ${skel}"
echo
echo " Ctrl-C now to abort, enter to continue"

read i

# User didn't abort, let's work magic

# Create website directory if not exists
if [ ! -d /pub/www/hosts/${domain} ]
then
        echo "Creating website directory..."
        mkdir /pub/www/hosts/${domain}

        # Unpack skeleton if possible
        if [ "${skel}" ]
        then
                cd /pub/www/hosts/${domain}
                tar xjf /pub/www-skel/${skel}.tbz2
        fi
else
        [ "${skel}" ] && echo "** Directory already exists, not unpacking skeleton"
fi

# Do database stuff
dbsuccess=0
echo "REPLACE INTO mysql.user SET Host = 'localhost', User = '${uname}', Password = PASSWORD('${pass}'), Select_priv = 'N', Insert_priv = 'N', Update_priv = 'N', Delete_priv = 'N', Create_priv = 'N', Drop_priv = 'N', Reload_priv = 'N', Shutdown_priv = 'N', Process_priv = 'N', File_priv = 'N', Grant_priv = 'N', References_priv = 'N', Index_priv = 'N', Alter_priv = 'N';" > /tmp/usersql
echo "CREATE DATABASE IF NOT EXISTS \`${db}\`;" >> /tmp/usersql
echo "FLUSH PRIVILEGES;" >> /tmp/usersql
echo "GRANT Select, Insert, Update, Delete, Create, Drop, References, Index, Alter ON \`${db}\` . * TO '${uname}'@'localhost';" >> /tmp/usersql
cat /tmp/usersql | mysql --password=' *** ---MY ROOT DATABASE PASSWORD--- *** ' && dbsuccess=1
rm /tmp/usersql

[ $dbsuccess -eq 0 ] && echo "** Database operation failed" && exit 1
[ $dbsuccess -eq 1 ] && echo "** Database operation succeeded"

# Typo3? If so, update config automagically
if [ "$skel" == "typo3" ]
then
        cfg=/pub/www/hosts/${domain}/typo3conf/localconf.php

        echo '<?php' > $cfg
        echo '$TYPO3_CONF_VARS["BE"]["installToolPassword"] = "bacb98acf97e0b6112b1d1b650b84971";' >> $cfg
        echo "\$typo_db_username = '${uname}';" >> $cfg
        echo "\$typo_db_password = '${pass}';" >> $cfg
        echo "\$typo_db_host = 'localhost';" >> $cfg
        echo "\$typo_db = '${db}';" >> $cfg
        echo "\$TYPO3_CONF_VARS[\"SYS\"][\"sitename\"] = '${domain}';" >> $cfg
        echo '$TYPO3_CONF_VARS["GFX"]["im_combine_filename"] = "combine";' >> $cfg
        echo '$TYPO3_CONF_VARS["GFX"]["im_path"] = "/usr/local/bin/";' >> $cfg
        echo '$TYPO3_CONF_VARS["GFX"]["im_path_lzw"] = "/usr/local/bin/";' >> $cfg
        echo '?>' >> $cfg
        echo "** Updated Typo3 configuration"
fi

echo "** Site creation successful"

This deserves some explanation. You run the script and pass it a FQDN that you want to host, and it makes a directory, a MySQL database, and other assorted handy things. Additionally, you can make "skeleton" tarballs -- one I made was placed in /pub/www-skel/typo3.tbz2. If I want a new Typo3 site, I say "pub-newsite www.domain.com typo3" and it auto-extracts the Typo3 skeleton. Additionally, the last little block of code sets up the Typo3 configuration file to automatically connect using the database parameters, so the proud new owner of the site can push two buttons and start doing stuff in about four seconds without even touching a shell prompt.

Of course, no web host is complete without a way to redirect domain.com to www.domain.com, thus a handy little script for that purpose: pub-newredirect.
Code:
#!/bin/bash
if [[ (-z "$1") || (-z "$2") || (-n "$4") || ("$1" = "--help") ]]
then
        echo "Uber-nifty redirect creation utility"
        echo "Written by delta407 (delta407@lerfjhax.com)"
        echo
        echo "    Usage: "`basename $0`" www.domain.com destination [\"append\"]"
        exit 0
fi

# Gather configuration
# Strip trailing slashes
domain=`echo $1 | sed -e 's/\/$//'`
dest=`echo $2 | sed -e 's/\/$//'`

if [ -d /pub/www/hosts/${domain} ]
then
        echo "${domain} already exists."
        exit 0
fi

append=no
[[ ($3 = "append") || ($3 = "yes") ]] && append=yes

# Setup complete, prompt
echo "Creating redirect with the following settings:"
echo "  - Domain: http://${domain}/"
echo "  - Destination: http://${dest}/"

if [[ $append = "yes" ]]
then
        echo "  - Append: yes"
        echo "    (${domain}/filename.ext -> http://${dest}/filename.ext)"
fi

echo
echo " Ctrl-C now to abort, enter to continue"

read i

# User didn't abort, let's work magic

# Create website directory
mkdir /pub/www/hosts/${domain}

# Absolute redirect?
htaccess=/pub/www/hosts/${domain}/.htaccess
echo "RewriteEngine On" > $htaccess

if [[ $append = "yes" ]]
then
        echo "RewriteRule (.*) http://${dest}/\$1" >> $htaccess
else
        echo "RewriteRule (.*) http://${dest}" >> $htaccess
fi

echo "** Redirect creation successful"

Run "pub-newredirect domain.com www.domain.com append" and then requests for http://domain.com/products/ will become http://www.domain.com/products/, wheras if "append" is omitted it would simply redirect to the base site.

Great, we can create users and websites, but there's no way for the user to get at his website. So, the ever handy pub-link script:
Code:
#!/bin/bash
if [[ (-z "$1") || (-z "$2") || (-n "$3") || ("$1" = "--help") ]]
then
        echo "Uber-nifty website/user association utility"
        echo "Written by delta407 (delta407@lerfjhax.com)"
        echo
        echo "    Usage: "`basename $0`" www.domain.com username"
        exit 0
fi

# Validate
[[ ! -d /pub/www/hosts/$1 ]] && echo "** Domain '$1' does not exist." && exit 1
[[ ! -d /home/$2 ]] && echo "** User directory for $2 does not exist." && exit 1

# ...magic...
cd /home/$2
ln -s /pub/www/hosts/$1/ $1

# Permissions
chown -R $2:apache /pub/www/hosts/$1
chmod -R 664 /pub/www/hosts/$1
cd /pub/www/hosts/$1
find -type d | xargs chmod 775

echo "** $1 associated with $2"

This script puts a symlink in the user's home directory to his respective site(s), providing easy access. Note that the association script makes the site writable by Apache (which is good for Typo3), but that means that any mean person with an account on your system could do mean things to the other person's stuff. So, either trust everyone on your system or remove the applicable lines. (I'm doing small virtual hosting with nice people and a good backup policy, so I'm okay. Your situation is probably different.)

So, say "bgates" signs up for www.microsoftrulez.com with your service and wants the domain parked. Here's what you'd run (assuming you made the "parked" skeleton tarball):
Code:
# user-new bgates "Bill Gates" yayforgoats
# pub-newsite www.microsoftrulez.com parked
# pub-link www.microsoftrulez.com bgates


All done. bgates can ftp, ssh, scp, or http his stuff around as much as he likes after those three commands. No restarting Apache, no interrupting the rest of your users. :D

Have fun, but be sure to understand what the scripts are doing before you do anything with them.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 18165

PostPosted: Sat Sep 28, 2002 4:29 am    Post subject: Reply with quote

Wow. You need an assistant, don't you. ;)
_________________
Those who know what's best for us must rise and save us from ourselves.
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Sun Sep 29, 2002 4:26 am    Post subject: Reply with quote

So, I was thinking: what's virtual hosting without DNS service too?

Required software:
  • djbdns
  • bash, standard *nix utilities, etc.

Behold, the dns-new script:
Code:
#!/bin/bash
if [[ (-z "$1") || (-n "$2") || ("$1" = "--help") ]]
then
        echo "Uber-nifty virtual hosting DNS creation utility"
        echo "Written by delta407 (delta407@lerfjhax.com)"
        echo
        echo "    Usage: "`basename $0`" domain.com [wildcard]"
        exit 0
fi

# Configurables
# What nameserver(s) will serve this zone file?
nameservers="1.2.3.4 5.6.7.8 9.10.11.12"
# What computer will provide the services?
web_ip="209.98.98.98"
mail_ip="208.42.42.42"

# Command line stuffs
[[ -n $2 ]] && wildcard=1

# Setup complete, prompt
echo "Creating the following DNS entries:"

for ns in $nameservers
do
        [[ ! ${has_soa} ]] && echo "  - $1 IN SOA ${ns} (RP hostmaster@$1)"
        has_soa=1

        # hack that gives letters for to six nameservers (stupid octal)
        # nothing breaks beyond then, it just isn't all that smart
        num=`expr 0${num} + 1`
        echo -e "  - $1 IN NS \14${num}.ns.$1"
done

num=0
for ns in $nameservers
do
        num=`expr 0${num} + 1`
        echo -e "  - \14${num}.ns.$1 IN A ${ns}"
done

echo "  - $1 IN A ${web_ip}"
echo "  - $1 IN MX ${mail_ip}"

if [[ $wildcard ]]
then
        echo "  - *.$1 IN A ${web_ip}"
        echo "  - *.$1 IN MX ${mail_ip}"
else
        echo "  - www.$1 IN A ${web_ip}"
        echo "  - ftp.$1 IN A ${web_ip}"
        echo "  - mail.$1 IN A ${mail_ip}"
fi

echo
echo " Ctrl-C now to abort, enter to continue"

read i

# User didn't abort, let's work magic
# Do nameserving entries first
for ns in $nameservers
do
        if [[ ! $did_soa ]]
        then
                echo ".$1:${ns}" >> /var/tinydns/root/data
        else
                echo "&$1:${ns}" >> /var/tinydns/root/data
        fi
        did_soa=1
done

echo "+$1:${web_ip}" >> /var/tinydns/root/data
echo "@$1:${mail_ip}" >> /var/tinydns/root/data

if [[ $wildcard ]]
then
        echo "+*.$1:${web_ip}" >> /var/tinydns/root/data
        echo "@*.$1:${mail_ip}" >> /var/tinydns/root/data
else
        echo "+www.$1:${web_ip}" >> /var/tinydns/root/data
        echo "+ftp.$1:${web_ip}" >> /var/tinydns/root/data
        echo "+mail.$1:${mail_ip}" >> /var/tinydns/root/data
fi

cd /var/tinydns/root && /usr/bin/tinydns-data

if [[ $? -eq 0 ]]
then
        echo "** DNS creation successful"
else
        echo "** DNS data written but reloading failed"
fi


And, of course, the dns-del script (I'll make deletion scripts for the rest later, okay? ;)):
Code:
#!/bin/bash
if [[ (-z "$1") || (-n "$3") || ("$1" = "--help") ]]
then
        echo "Uber-nifty virtual hosting DNS deletion utility"
        echo "Written by delta407 (delta407@lerfjhax.com)"
        echo
        echo "    Usage: "`basename $0`" domain.com"
        exit 0
fi

# Prompt
echo `basename $0`" will delete ALL ENTRIES CONTAINING '$1'"
echo "(So, '"`basename $0`" domain.com' will also delete sub.domain.com,"
echo "'"`basename $0`" sub.net' will delete sub.network.com and so forth.)"
echo
echo " Ctrl-C now to abort, enter to preview changes"

read i

# User didn't abort, let's work magic
cd /var/tinydns/root
# Back up current data
cp data data-before-deleting-$1
grep -v $1 data-before-deleting-$1 > data-after-deleting-$1

# Preview changes
{
        echo "Changes to be made:"
        echo
        diff data-before-deleting-$1 data-after-deleting-$1 | grep '<'
} | less -S

echo " Ctrl-C now to abort, enter to apply changes"
read i

mv data-after-deleting-$1 data
/usr/bin/tinydns-data

if [[ $? -eq 0 ]]
then
        echo "** DNS deletion successful"
else
        echo "** DNS data written but reloading failed"
fi

_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Sun Sep 29, 2002 4:38 am    Post subject: Reply with quote

And, of course, it might be helpful to make domain.com map transparently www.domain.com -- you know, without a redirect. This can be done with a symlink, but why not make a handy little script to do that for you? :D

Thus, pub-newalias is born:

Code:
#!/bin/bash
if [[ (-z "$1") || (-z "$2") || (-n "$3") || ("$1" = "--help") ]]
then
        echo "Uber-nifty alias creation utility"
        echo "Written by delta407 (delta407@lerfjhax.com)"
        echo
        echo "    Usage: "`basename $0`" www.domain.com other.domain.com"
        exit 0
fi

# Gather configuration
# Strip trailing slashes
domain=`echo $1 | sed -e 's/\/$//'`
dest=`echo $2 | sed -e 's/\/$//'`

if [ -d /pub/www/hosts/${domain} ]
then
        echo "${domain} already exists."
        exit 1
fi
if [ ! -d /pub/www/hosts/${dest} ]
then
        echo "${dest} does not exist."
        exit 1
fi

# Setup complete, prompt
echo "Creating alias with the following settings:"
echo "  - Domain: http://${domain}/"
echo "  - Destination: http://${dest}/"

echo
echo " Ctrl-C now to abort, enter to continue"

read i

# User didn't abort, let's work magic

# Yay for symlinks
cd /pub/www/hosts
ln -s ${dest} ${domain}

echo "** Alias creation successful"

_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
mezz
Tux's lil' helper
Tux's lil' helper


Joined: 01 Jun 2002
Posts: 111

PostPosted: Sun Sep 29, 2002 4:44 am    Post subject: Reply with quote

Sweet, thanks!
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Sun Sep 29, 2002 5:47 am    Post subject: Reply with quote

As hinted at by the DNS stuff above, I was planning on adding mail support. Here it is. (The things I do for you... :roll:)

Required software:
  • Postfix
  • Courier-IMAP (if so desired)
  • mutt (so your users can get at their mail via ssh)
  • bash :D


Anyway, configuration goes like this. Do the following to set up Postfix:
Code:
# emerge postfix (if you haven't)
# echo 'virtual_maps = hash:/etc/postfix/virtual' >> /etc/postfix/main.cf
# touch /etc/postfix/virtual
# postmap /etc/postfix/virtual
# /etc/init.d/postfix start (if it isn't)

Do the following to set up Courier-IMAP:
Code:
# emerge courier-imap (if you haven't)
# /etc/init.d/courier-imapd start (if it isn't)

Of course, you'll want to rc-update add each of the services you like. You can also use courier-pop3d and/or the SSL varieties of each.

If you want a catch-all for a domain, run mail-newdomain:
Code:
#!/bin/bash
if [[ (-z "$1") || (-z "$2") || (-n "$3") || ("$1" = "--help") ]]
then
        echo "Uber-nifty mail catch-all creation utility"
        echo "Written by delta407 (delta407@lerfjhax.com)"
        echo
        echo "    Usage: "`basename $0`" domain.com username"
        exit 0
fi

# Gather configuration
uname=`echo $2 | tr -d ' :.'`
domain=$1

# Setup complete, prompt
echo "Creating domain catch-all with the following settings:"
echo "  - Domain: ${domain}"
echo "  - Local user: ${uname}"

echo
echo " Ctrl-C now to abort, enter to continue"

read i

# User didn't abort, let's work magic
virtual=/etc/postfix/virtual
echo "postmaster@${domain} root" >> $virtual
echo "hostmaster@${domain} root" >> $virtual
echo "@${domain} ${uname}" >> $virtual
postmap $virtual
postfix reload

echo "** Catch-all creation successful"


If you want to forward some specific address to a local user or another specific address, run mail-newforward:
Code:
#!/bin/bash
if [[ (-z "$1") || (-z "$2") || (-n "$3") || ("$1" = "--help") ]]
then
        echo "Uber-nifty mail forward creation utility"
        echo "Written by delta407 (delta407@lerfjhax.com)"
        echo
        echo "    Usage: "`basename $0`" addr@domain.com username"
        exit 0
fi

# Gather configuration
addr_from=$1
addr_to=`echo $2@$HOSTNAME | awk -F@ '{print $1 "@" $2}' | sed -e "s/@$HOSTNAME//"`

# Setup complete, prompt
echo "Creating mail forward with the following settings:"
echo "  - Originally to: ${addr_from}"
echo "  - Routed to: ${addr_to}"

echo
echo " Ctrl-C now to abort, enter to continue"

read i

# User didn't abort, let's work magic
virtual=/etc/postfix/virtual
echo "${addr_from} ${addr_to}" >> $virtual
postmap $virtual
postfix reload

echo "** Forward creation successful"


Also, recall that users can control their own mail delievery with a .forward file in their home directory. (So, if they don't want your IMAP/POP3 stuff, they can forward their mail to an account of their choosing.)

To bring everything together now... if a user wants a new site with everything currently provided (HTTP, MySQL, SSH, FTP, IMAP, POP3), do the following:
Code:
# user-new hsmith "Your Mom (Helga Smith)"
# pub-newsite www.yourmomsface.com
# pub-link www.yourmomsface.com hsmith
# mail-new yourmomsface.com hsmith


Now, to make it all web-based... ;)
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Sun Sep 29, 2002 10:18 pm    Post subject: Reply with quote

delta407 wrote:
(The things I do for you... :roll:)

Yep, I've upped the ante again. Behold:

vhost-install

I'm still testing it, but the general idea is this:
Code:
< follow Gentoo install guide, reboot, login >
# wget http://.../vhost-install
# chmod +x vhost-install
# ./vhost-install BUILD WEB MAIL SQL DNS FTP MISC

...and, like magic, all the stuff in the previous posts is done for you. The install process is broken down into a few phases.

vhost-install --help wrote:
Uber-nifty Virtual Hosting System
Written by delta407 (delta407@lerfjhax.com)

Usage: vhost-install PHASENAME [PHASENAME ...]

This installer will do various strange and wonderful things to your server. Note that the recommended configuration is where none of the required packages have been installed and that none of the configuration files exist, to ensure a clean and functional install. Specifically, the installer will do the following:
BUILD:
- emerge apache
- emerge postfix
- emerge mysql
- emerge djbdns
- emerge courier-imap
- emerge pure-ftpd
WEB:
- make /etc/apache/apache.conf do dynamic virtual hosting and splittable logfiles
- create /root/bin/rotate-logs
- add /root/bin/rotate-logs to /etc/crontab
- create /pub and other assorted directories
- copy administration scripts to /root/bin
- make Apache start on boot
- start Apache
MAIL:
- edit /etc/postfix/main.cf to use /etc/postfix/virtual
- copy administration scripts to /root/bin
- make Postfix start on boot
- start Postfix
- make Courier-IMAPd start on boot
- make Courier-POP3d start on boot
- start Courier-IMAPd
- start Courier-POP3d
SQL:
- make MySQL start on boot
- start MySQL
DNS:
- configure tinydns
- create /services
- let tinydns be managed by svscan
- copy administration scripts to /root/bin
- make svscan (and tinydns) start on boot
- start svscan (and tinydns)
FTP:
- edit /etc/conf.d/pure-ftpd sensibly
- make Pure-FTPd start on boot
- start Pure-FTPd
MISC:
- modify /etc/profile to have root's path include /root/bin
- email delta407 saying you used his script (I like to know... disable by appending NO_PHONE_HOME)


It then pokes around in your configuration (specifically, guessing an IP to bind FTP/DNS to, seeing if you're NATed, etc.) and then performs whatever operations you tell it to. Anyway, once vhost-install completes, everything should work out-of-the-box. (Except for dns-new, which might need a little bit of configuration...)

I'm currently testing this on a stage 3 tarball of 1.4_rc1 inside VMware -- if anyone wants to test it on their box, let me know. I'll post instructions here once I'm happy with it.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
PimpNasty
n00b
n00b


Joined: 05 Jun 2002
Posts: 36

PostPosted: Tue Oct 01, 2002 2:53 am    Post subject: Reply with quote

I would be willing to try out the vhost stuff out. I have an extra machine laying around waiting for something like this.

Anther question, how much work would it be to use PostgreSQL instead of MySQL?
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Tue Oct 01, 2002 2:57 am    Post subject: Reply with quote

PimpNasty wrote:
Anther question, how much work would it be to use PostgreSQL instead of MySQL?

Well, I don't have any experience PostgreSQL, so auto database/user creation would be difficult.

I'll e-mail you the script within 24 hours.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Tue Oct 01, 2002 2:59 pm    Post subject: Reply with quote

Okay, consider this a public beta. My e-mail contained the following

I wrote:
The virtual hosting install script worked under Gentoo 1.4 with a couple minor exceptions, that I believe have been corrected now.

At any rate, to use it, do the following:

# wget http://gentoo.swchs.org/projects/vhost/vhost-install
# chmod +x vhost-install
# ./vhost-install
[ displays usage options and what each one does ]

I would suggest running each phase independently and checking that everything worked right. My concerns for each phase include, but is not limited to the following:

- WEB once decided to overwrite apache.conf when the command was `wget ... -O - >> apache.conf`, and I still cannot figure out why. It now wgets the additions to a temporary file and runs `cat >> apache.conf` instead, which ought to make life happy. Addition
ally, it does not yet give Apache permission to read from /pub/www, which it ought to before the final release.

- MAIL may get older/newer versions of Postfix confused, but should be harmless.

- SQL doesn't yet configure MySQL to work right off the bat -- ideas for improvement include checking if the mysql database exists and if not auto-creating the MySQL database and setting a somewhat random root password.

- DNS will be sensitive to minor variances in the tinydns-setup script. It ought to work for now, at least. (Also, a recent install of djbdns showed it was missing a digest file, so emerge djbdns may fail.)

- FTP may incorrectly guess your NAT preference and doesn't give you a TODO list of things you ought to check.

- Some people won't like MISC ;)

- Failure conditions overall are poorly tested. Most of the things that I could imagine failing have appropriate tests wrapped around them, but I'm not going to call it bullet-proof yet.


Feedback?
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
sebest
Apprentice
Apprentice


Joined: 03 Jul 2002
Posts: 163
Location: Paris - France

PostPosted: Wed Oct 02, 2002 4:49 pm    Post subject: Reply with quote

Adding mod_php mod_ssl and a webmail like squirrelmail or imp and you would have a full Webmail solution
Back to top
View user's profile Send private message
huhmz
n00b
n00b


Joined: 16 Aug 2002
Posts: 16

PostPosted: Wed Oct 02, 2002 10:44 pm    Post subject: Reply with quote

Oh my god just saw this thread, I'll just quit learning stuff now and check this page from time to time and let you do all the administration for me. :lol:

Seriously, It's nice stuff here, saves me a ton of time and shell scripting (which I suck at, I do all "shell scripts" in perl :oops: )

Just wanted to let you know that this stuff is very useful for me.
Keep em comin' :wink:
Back to top
View user's profile Send private message
tewlz
n00b
n00b


Joined: 28 Sep 2002
Posts: 53

PostPosted: Thu Oct 31, 2002 5:27 am    Post subject: Thanks a billion, delta407... Reply with quote

Thanks a *LOT* for this thread. Great work, great tips - *very* much appreciated.
Back to top
View user's profile Send private message
karwoski
n00b
n00b


Joined: 30 Jun 2002
Posts: 16
Location: Columbia, MO

PostPosted: Sat Jan 04, 2003 6:45 pm    Post subject: Reply with quote

I've been looking for just this sort of thing. Can't wait to try it out. Thanks. Any further developments?
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Sat Jan 04, 2003 7:02 pm    Post subject: Reply with quote

Yes; there were some problems with the way DNS works (it needs a :a, :b on the end of the NS fields) that some script modifications address. (These modifications are not yet public, but they will be once I get around to it.) Major advances are unlikely until my next big project gets going... ;)

This next project is a virtual private network that consists of a series of point-to-point links; i.e. not client connecting to some local network but a series of separate machines creating a virtual network between themselves. The killer feature is that it has a mesh topology, so that computer A can talk directly to computer C without going through computer B. Additionally, it is flexible enough to allow, say, end-to-end bzip2 compression of every packet (if you really wanted to), the ability for any of the clients to obtain a world-routable IP address from anywhere (assuming you have the address space), and other nifty things like masquerading as legitimate HTTP traffic to allow full access to the network from behind a transparent proxy or a Nazi firewall. (This is done, it just needs a nice interface. It will likely be web-based, using LISSARD.)

This system was designed as a result of the increased demands mobility is placing on data distribution. I own and control a lot of computers in a lot of different places (on a lot of different Internet connections too). The idea is that one machine at home can be providing NAT for the other internal boxes as well as VPN access via ssh and over wireless. A big, beefy machine that is doing NAT on a beefier DSL line can provide VPN access via ssh, do some serious file serving, and has enough high-availability components that I can make it the central administrative point. I have a Pentium 2 with negligible amounts of disk that is only doing DNS, but it's on a nice fat pipe, so I can make it route traffic between nodes in the event that a direct connection fails. (As long as they can connect to this machine, a route can be made between them.) The list goes on; I have the machines needed, they just don't have a convenient way of talking to each other. This is that convenient way. :D

I am looking to implement one of the nifty caching network filesystems (probably Coda) on top of this. This would allow me to grab my laptop, wander out of wireless range, and still have all of the music I was just listening to. And it would allow me to work on networked documents (i.e. edit them) unplugged, plug in from a Starbucks (with the Nazi firewall), and sync up with one of the master servers.

How does this relate to virtual hosting? Each of them could have the same tinydns data files and share the same /pub directory, meaning you could theoretically enable DNS round-robin and have several web servers sharing content. Other nifty stuff is possible too. ;)
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
puddpunk
l33t
l33t


Joined: 20 Jul 2002
Posts: 681
Location: New Zealand

PostPosted: Sun Jan 05, 2003 10:08 am    Post subject: Reply with quote

well delta407, you've really outdone yourself this time.

This was a brilliant peice of work man, and i commend you for it. And thank you for posting it to us feeble beings (we're not worthy!).

/me hands delta his crown. The real Bodhisattva crown!
Back to top
View user's profile Send private message
Carlo
Developer
Developer


Joined: 12 Aug 2002
Posts: 3356

PostPosted: Tue Jan 07, 2003 2:47 pm    Post subject: Reply with quote

huhmz wrote:
Oh my god just saw this thread, I'll just quit learning stuff now and check this page from time to time and let you do all the administration for me. :lol:


I thought the same.


@delta407: wow & thx :!:


Carlo
Back to top
View user's profile Send private message
mrhodes
Guru
Guru


Joined: 01 May 2002
Posts: 310
Location: Halifax, NS

PostPosted: Wed Jan 08, 2003 12:10 am    Post subject: Having Troubles... Reply with quote

This may seem like a simple problem, I hop it is :)

I can't create new sites with this script... I get an SQL error....

ERROR 1045: Access denied for user: 'root@localhost' (Using password: YES)
** Database operation failed

can anyone help me out?

Thanks,

Mike
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Wed Jan 08, 2003 4:16 am    Post subject: Reply with quote

Make sure to change 'empty' to your real MySQL root user's password.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
mrhodes
Guru
Guru


Joined: 01 May 2002
Posts: 310
Location: Halifax, NS

PostPosted: Wed Jan 08, 2003 12:05 pm    Post subject: Reply with quote

Ok, great...

thanks :)


Mike

PS. One thing I noticed about your script was that after I ran everything, my prompt went for having colours to being a basic prompt.... Also, my path was erased as well. I booted off the gentoo CD and just copied the /etc/profile file back, and everything worked out fine...
other then that, great script!
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Wed Jan 08, 2003 1:41 pm    Post subject: Reply with quote

Yes... that's part of the MISC phase. Specifically, it's supposed to add /root/bin/ to root's path, but apparently it didn't work.
Code:
mv /etc/profile /etc/profile.bak
cat /etc/profile.bak | sed -e 's/${ROOTPATH}"/${ROOTPATH}:~\/bin/"' > /etc/profile

(It did make a backup, though.)
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
mrhodes
Guru
Guru


Joined: 01 May 2002
Posts: 310
Location: Halifax, NS

PostPosted: Mon Jan 13, 2003 12:15 am    Post subject: Typo3 Question Reply with quote

Hi.. I used your scripts, and have a pretty good server going now. My goal is to start a web hosting company, and I am very interested in Typo3... however, I'm not sure how to set it up :( I know it's not up to you (original poster) to explain this as it is not part of gentoo, but I would be very interested in where you got the skel file for typo3...

thanks,

Mike
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Mon Jan 13, 2003 12:26 am    Post subject: Reply with quote

I just sort of made the tarball one day. Standard Typo3 stuff -- appropriate symlinks for index.php, t3lib/, typo3/, etc. and an autogenerated config file (including database settings) -- just packed into typo3.tar.bz2. Nothing overly complicated, but I would suggest poking around in the Typo3 testsite before you try to host real websites with it.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
mrhodes
Guru
Guru


Joined: 01 May 2002
Posts: 310
Location: Halifax, NS

PostPosted: Mon Jan 13, 2003 12:35 am    Post subject: Reply with quote

Ok, thanks for the quick reply...

I'm looking over the typo site now, and going through the install guide.
This program / system looks very good!

Do you have any sites that were create / modified with it that I could look at?

Thanks,

Mike
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Mon Jan 13, 2003 12:37 am    Post subject: Reply with quote

Continuing discussion via PM.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum