Remote server

From Vertubleu

Jump to: navigation, search

Misc install link (fr): http://doc.ubuntu-fr.org/tutoriel/installation_configuration

Similar page: http://www.patrickjwaters.com/blog/2011-07-13/my-favorite-web-server-setup-ubuntu-server-lamp-webmin-and-virtualmin/3524

Contents

Basic tools

apt-get install w3m vim htop wget

lamp

apt-get install bind9 apache2 libapache2-mod-php5  phpmyadmin libapache2-mod-python mysql-server-5.1 apache2-utils

email

apt-get install courier-imap-ssl courier-imap spamassassin procmail  mailutils sendmail sendmail-doc

(not sure all are required) Then activate sendmail as default mail agent instead of postfix

Test sending emails:

echo “This will go into the body of the mail.” | mail -s “Hello world” you@youremailid.com
 or 
echo “Sending an attachment.” | mutt -a backup.zip -s “attachment” calvin@cnh.com
 or  
#!/bin/bash
df -h | mail -s “disk space report” calvin@cnh.com

webmin

Add following to sources.list:

deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib
wget http://www.webmin.com/jcameron-key.asc
apt-key add jcameron-key.asc 
apt-get update && apt-get install webmin

virtualmin

wget http://download.webmin.com/download/virtualmin/webmin-virtual-server_3.90.gpl-2_all.deb http://download.webmin.com/download/virtualmin/webmin-virtual-server-theme_8.2_all.deb

(from http://www.webmin.com/vdownload.html)

dpkg -i webmin-virtual-server_3.90.gpl-2_all.deb webmin-virtual-server-theme_8.2_all.deb

or alternatively, use this repository? (tb tested):

deb http://software.virtualmin.com/gpl/ubuntu/dists/virtualmin-universal main/binary-amd64/
apt-get install webmin-virtual-server webmin-virtual-server-theme

Install apache2-suexec-custom with /home as the ref folder (instead of /var/www):

apt-get install apache2-suexec-custom
cd /etc/apache2/suexec
vim www-data
# => replace the line "/var/www" with "/home"


Use of a failover IP for a domain (tbc)

  • virtualmin: edit virtual server / change IP address => private address: set failover IP (Can be directly done at domain creation)
  • webmin: bind dns server / edit master zone for domain / name server => set failover reverse name
  • ovh server: dns secondaire: configure domain with failover IP
  • ovh domain: configure DNS to failover IP

(OVH failover setup: http://guide.ovh.com/IpFailover#link9)

on server, run followinf command to check DNS setup:

dig <domain name>

Drupal site backup

  • get drush: drupal.org/project/drush => untar in user home folder
  • get dgb: https://github.com/scor/dgb => link dgb.drush.inc to drush/command/
  • follow dgb install guidelines:
    • create a git repo at the home user root (git init).
    • configure your name / email in .gitconfig
    • create a .gitignore file with all the non-backuped-up files
    • create a databases folder
  • test by doing: cd public_html; <path to>/drush dgb-backup
  • If ok, add that as a cron rule (use the drush --quiet option to not generate cron emails on each cron, or use cronic script)

VPN command line setup

# Start VPN and configure all routes through it
# Must be run as root
#
# update following files:
# - ~/default-ip: used by the stop script (default routing IP to be used)
# - ~/my-ip: current public allocated IP

defaultip=`ip route | grep default | awk '{print $3}'`   

echo "$defaultip" > ~/default-ip

echo -n " starting vpn... "
pon ipjetable

sleep 5
echo "done"

echo -n " configuring routes... "
ip route del default
sleep 1
ip route add default dev ppp0
sleep 1
echo "done" 

myip=`ifconfig ppp0 | grep "inet addr" | sed 's/.* addr:\([0123456789.]*\).*/\1/'`
echo " My public IP is now: $myip"
echo "$myip" > ~/my-ip

gwip=`ifconfig ppp0 | grep "inet addr" | sed 's/.*P-t-P:\([0123456789.]*\).*/\1/'`
echo " PPP Gateway IP: $gwip"

# start vpn-monitor to restore the default network configuration on cas the ppp link would break
echo -n " starting vpn-monitor ..."
~/scripts/vpn-monitor $gwip 20 ~/scripts/stop-vpn &
echo "done"
  • sample stop script:
# stops VPN and restore default routing
# Must be run as root
#
# uses the default routing IP stored into ~/default-ip
# also updates ~/my-ip

defaultip=`cat ~/default-ip`

poff ipjetable

sleep 2
route add default gw $defaultip

myip=`ifconfig eth0 | grep "inet addr" | sed 's/.* addr:\([0123456789.]*\).*/\1/'`

echo " My public IP is now: $myip"
echo "$myip" > ~/my-ip

# Now check if vpn-monitor is still running, and kill it if needed
ps aux | grep vpn-monitor | grep -vq "grep" && echo " killing running instances of vpn-monitor" && killall vpn-monitor || echo " no instances of vpn-monitor found"
  • sample vpn-monitor script (in case the link gets broken => restore the default config)
#!/bin/bash
# Usage: $0 <host> <period> <script to run>
# ex: $0 google.com 10 ~/scripts/stop-vpn

[ $# -ne 3 ] && echo "Usage:" && echo "  $0 <host> <period> <script to run>" && exit

host="$1"
timecheck=$2
script="$3 &"

echo " Checking ping to $host each ${timecheck}s - run $script when connection is down"

while (true); do
        ping -c 1 $host | grep -q "time=";
        [ $? -ne 0 ] && echo "Now running $script" && `$script` && break;

        sleep $timecheck
done

others

http://www.daddyscripts.com/forum/viewtopic.php?f=4&t=154

Personal tools