Saturday, April 02, 2011

Starting a rails project

This is just a quick reminder about how to start a standard rails project. The assumption is that rvm already installed on an Ubuntu machine (I'm using Natty).
  • mkdir projects
  • cd projects
  • rails new project_name -T
  • echo "rvm --create use 1.9.2@project_name" > .rvmrc
  • cd project_name
  • (agree to the use of the .rvmrc file)
My default Gemfile at the moment takes into account that I'll be creating a general API and will be using rspec (I tend to use rspec for integration testing too). It includes spork and autotest for a cool autotest environment.
  • (create the following Gemfile)
  • gem install bundler
  • bundle install
source 'http://rubygems.org'

gem 'rails', '3.0.1'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
gem 'gravatar_image_tag', '0.1.0'
gem 'will_paginate', '3.0.pre2'

group :development do
gem 'rspec-rails', '2.0.1'
gem 'annotate-models', '1.0.4'
gem 'faker', '0.3.1'
end

group :test do
gem 'rspec', '2.0.1'
gem 'webrat', '0.7.1'
gem 'spork', '0.9.0.rc4'
gem 'libnotify', '0.3.0'
gem 'factory_girl_rails', '1.0'
end
Add the inital state of the framework to git. Take the opportunity to create a project at github and upload your public key (so that you can push up the project).
  • git init
  • git add .
  • git commit -am "Initial commit of Rails framework"
  • git remote add origin git@github.com:username/project_name.git
  • git push origin master
Then create a project at heroku (goto heroku.com and sign up) - you may need to install the heroku gem (gem install heroku)
  • heroku create
  • git push heroku master
  • heroku rename project-name #you can't use _ so, I tend to use - instead here
Finally, it's time to get rspec installed
  • rails generate rspec:install
Get some generate setup done for static pages:
  • remove public/index.html
  • add public/stylesheet/blueprint
  • add public/stylesheet/custom.css #see rails3tutorial
  • rails generate controller Pages home contact about
Add some autotesting
  • sudo apt-get install libnotify-bin
  • echo "require 'autotest/growl'" >> .autotest
  • spork --bootstrap
  • edit spec/spec_helper.rb to contain the contents of Listing 3.13 from the Rails3Tutorial Book
  • echo "--drb" >> .rspec
  • create /usr/local/bin/runautotest
spork&
sleep 10s
autotest
  • sudo chmod +x /usr/local/bin/runautotest

Sunday, March 13, 2011

Git: upgrading to parent

I have a fork of a GIT project. The parent had got ahead of my local repro by quite a bit, so I wanted to pull in all those changes.
  • cd [child-local-dir]
  • git remote add parent [parent-url]
  • git pull parent [stable]
Clearly, if you want a different branch, you can specify that.

Once it's local, if you have a remote location for your repro (such as github) just
  • git push

Saturday, March 12, 2011

Natty install

We've moved into Alpha3 and beyond and I've been running a distribution upgrade from Maverick for a while now. So, I took the opportunity to test a clean install this morning and it's been a huge success.

A:
  • Downloaded the alpha3 .iso and burnt it to disc.
  • Shoved it in the drive and watched it do it's stuff
  • Selected "get updates" and "install restricted drivers"
  • Before long it was installed and ready to go (am liking the new Unity interface)
B:
Mount the various partitions. I'd previously set up my machine so that the main drive is partitioned into:
  • sda1: 50Gb - Windows
  • sda2: 50Gb - Linux
  • sda3: the rest - data
So, after doing a clean install onto sda2, I mounted sda3 to /home and another drive to /backup.
  • Create the folders that you want to mount the drives to
  • List your drives to make sure you know where they are: "sudo fdisk -l"
  • Test that they mount okay: "mount /dev/sda3 /home"
  • Add a link to /etc/fstab "/dev/sda3/ /home defaults 0 0"
  • Remove the previous mount: "sudo umount /home"
  • Use fstab to mount all: "sudo mount -a"
C:
Install some helpful programs
  • sudo apt-get install joe guake geany gdebi
Install some programs from downloaded debs: for some reason, installing them with the software centre triggers an error in alpha, so I just used gdebi to install them and everything worked fine. With ~/.chrome unaffected by the reinstall, all the previous settings were preserved.
  • chrome
  • dropbox
  • skype
Install Crashplan (ensuring that the jre from the restricted extras in installed). Adopt the old version of the machine so that a new seed of data isn't required. Copy over CrashPlanRemote (see previous blog post).

D:
Setup apache, PHP, mysql etc.
  • sudo apt-get install php5 apache2 mysql-server phpmyadmin
Copy over /etc/hosts and the config files from sites-available and then use "sudo a2ensite blah" to enable them; follow that with a "sudo /etc/init.d/apache2 reload" and everything should be working. Import data into mysql.

E:
Passwordless login is key to great workflow. Because ~ was preserved (on a partition unaffected by the reinstall), my ~/.ssh directory was unchanged. So, after /etc/hosts was reinstated, passwordless login was back up and running.

All in all - a complete reinstall in less than 2 hours!

Tuesday, February 22, 2011

Mysql backups

I have found the most wonderful tool for backing up mysql databases. It's not new... it's just that I've only found it recently!

automysqlbackup does exactly what is says on the tin - it backs up your mysql database. There are some great todos, but I thought I'd post what I did on out Plesk servers so that I've got it noted down for the future!
  • sudo -s
  • mkdir /var/mysql
  • mv automysqlbackup /usr/local/bin/
  • ln -s /usr/local/bin/automysqlbackup /etc/cron.daily/automysqlbackup
  • joe /etc/crontab (edit the time that the daily cron takes place and save)
When setting up automysqlbackup, these are the settings I used:
### START CFG ###
# Username to access the MySQL server e.g. dbuser
USERNAME=admin

# Password to access the MySQL server e.g. password
PASSWORD=YourAdminPasswordForPlesk

# Host name (or IP address) of MySQL server e.g localhost
DBHOST=localhost

# List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
DBNAMES="all"

# Backup directory location e.g /backups
BACKUPDIR="/var/mysql/"

# Mail setup
# What would you like to be mailed to you?
# - log : send only log file
# - files : send log file and sql files as attachments (see docs)
# - stdout : will simply output the log to the screen if run manually.
# - quiet : Only send logs if an error occurs to the MAILADDR.
MAILCONTENT="log"

# Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs])
MAXATTSIZE="4000"

# Email Address to send mail to? (user@domain.com)
MAILADDR="support@domain.com"

# ============================================================
# === ADVANCED OPTIONS ( Read the doc's below for details )===
#=============================================================

# List of DBBNAMES for Monthly Backups.
MDBNAMES="${DBNAMES}"

# List of DBNAMES to EXLUCDE if DBNAMES are set to all (must be in " quotes)
DBEXCLUDE=""

# Include CREATE DATABASE in backup?
CREATE_DATABASE=no

# Separate backup directory and file for each DB? (yes or no)
SEPDIR=yes

# Which day do you want weekly backups? (1 to 7 where 1 is Monday)
DOWEEKLY=6

# Choose Compression type. (gzip or bzip2)
COMP=gzip

# Compress communications between backup server and MySQL server?
COMMCOMP=no

# Additionally keep a copy of the most recent backup in a seperate directory.
LATEST=yes

# The maximum size of the buffer for client/server communication. e.g. 16MB (maximum is 1GB)
MAX_ALLOWED_PACKET=

# For connections to localhost. Sometimes the Unix socket file must be specified.
SOCKET=

# Command to run before backups (uncomment to use)
#PREBACKUP="/etc/mysql-backup-pre"

# Command run after backups (uncomment to use)
#POSTBACKUP="/etc/mysql-backup-post"
### END CFG ###

Plesk, Backup and Crashplan

Finally, I think I've found a good solution for Plesk and backup. For ages, I've been trying to find ways of efficiently backing up server data (www, mail mysql) and have tried to the Plesk solution, TotalBackup from 4psa and other rsync methods. To date, they all create a massive amount of data.

TotalBackup has served us okay. It does manage a backup of the whole server and then performs daily deltas, but each week, we still have a massive backup split up into 1000Mb files moving from server to server to facilitate an offline backup solution. And, potentially, with a server going down, we're still 24 hours out of date. Added to that, the restore process (which needs to knit all the parts of the backup together, apply the deltas and then unzip it, before offering the chance to actually get at your files) and we're in a position that doesn't really allow us the best backup/restore cycle.

I've been using Crashplan at home for a while now and love the product (especially after seeing what Mozy did with their pricing strategy and Crashplan promise not to do the same).

So, why not use the same technology with the servers... that's the plan, and that's what I've been spending the last couple of days thinking about. The plan is to backup:
  • /var/www/vhosts (where all the www data is)
  • /var/qmail/mailnames (where all the mail is)
  • /var/mysql/latest (where my latest mysql db backups are)
For more information about the mysql backup process, see the separate post.

Putty tunnels

In a previous post, I was talking about getting a headless instance of Crashplan setup on an Ubuntu server and then administrating it from a local machine (in that case, Ubuntu). However, I needed to do a similar thing with a windows machine.

Get putty: the best (maybe only) SSH client worth having on Windows.

On the support page at Crashplan, there is some discussion about how to use putty to create the remote connection via a tunnel, but either I'm daft, or it's not quite explicit enough. So, here's a little reminder about creating tunnels using putty.

Make sure that the Crashplan desktop client is not open (the tray icon can continue to run in the background).

Change the config
  • edit C:\Program Files\CrashPlan\conf\uk.properties
  • uncomment the servicePort line and make sure it reads servicePort=4200
  • save the file
NB. Have just found Notepad++ which is a great little replacement for notepad.

Create the tunnel
  • open putty
  • in the first screen, enter the server details (as you would if just SSHing normally)
  • now in the left hand column, under "Connection" and then "SSH" is a tab helpfully titled "Tunnels"
  • in the source port box, type 4200
  • in the destination box, type localhost:4243
  • click Add (don't forget to do this bit!)
  • finally, click Open
  • log in with your normal user credentials
Check that the port is open
  • Start -> Run
  • cmd
  • telnet localhost 4200 (should not get a message that talks about failed connection)
Open Crashlpan - and you should get a remote connection over an SSH tunnel.

Once you're finished, change back the config file and close the putty session which will close the tunnel.

Missing desktop notification link

When you visit mail.google.com, you should get a helpful hint at the top of the page that relates to the new desktop notifications (which are very cool).

"Click here to enable desktop notifications in Google".

However, while there are links to "Learn more" and "Hide", there is no actual link to setup notification. There *should be* a link to the settings page where you can actually set up notifications.

in reference to: Desktop notifications in Chrome - Gmail Help (view on Google Sidewiki)

Friday, February 18, 2011

Crashplan headless

I've previously mentioned my desire to get headless backups working with Crashplan. However, it wasn't quite right. So, I spent some more time this morning trying to get it working simply and well.

Before I start, here are the references to the work completed:

Install the Java virtual machine - don't use openJRE
sudo apt-get install sun-java6-jre
Accept the licence
Goto the crashplan download site and find out the URL of the latest version

Get the crashplan archive, extract it and change directory
wget http://download.crashplan.com/installs/linux/install/CrashPlan/CrashPlan_3.0.2_Linux.tgz
tar -zxvf CrashPlan_3.0.2_Linux.tgz
cd CrashPlan-install
Install Crashplan as root (if you want access to all directories)
sudo -s
./install.sh
Complete the install process
  • Read the EULA
  • Hit q to exit the EULA and then agree to it
  • Accept the default locations for the binaries, backups and scripts
Finish off the remote install process
  • Remove the downloaded files
  • Firewall: open up port 4243 on the remote machine

Setup the local machine

To administrate the remote machine, we will be port forwarding via ssh 4200 to 4243 and then using the desktop GUI.

Copy and paste the following script into crashplan/bin/CrashPlanRemote (which is usually in /usr/local/ on Ubuntu).
#!/bin/bash

# Do we have the appropriate input?
if [ -z "$1" ]; then
echo usage: $0 remote-server
exit
fi

# fill in your stuff here:
USER=jeremy
SERVER=$1

# dont change anything down here
ssh -fnNTL 4200:localhost:4243 ${USER}@${SERVER}
PID=$!

# get CrashPlan folder
SCRIPT=$(ls -l $0 | awk '{ print $NF }')
SCRIPTDIR=$(dirname $SCRIPT)
TARGETDIR="$SCRIPTDIR/.."
cd ${TARGETDIR}

#change CrashPlan config to use the tunnel
sed 's/#servicePort=4200/servicePort=4200/g' ${TARGETDIR}/conf/ui.properties > /tmp/CrashPlan-ui.properties
cp /tmp/CrashPlan-ui.properties ${TARGETDIR}/conf/ui.properties
rm /tmp/CrashPlan-ui.properties

#CrashPlan start script - begin
. ${TARGETDIR}/install.vars
. ${TARGETDIR}/bin/run.conf
${JAVACOMMON} ${GUI_JAVA_OPTS} -classpath "./lib/com.backup42.desktop.jar:./lang:./skin" com.backup42.desktop.CPDesktop > ${TARGETDIR}/log/ui_output.log 2 > ${TARGETDIR}/log/ui_error.log
#CrashPlan start script - end

#change CrashPlan config back to default
sed 's/servicePort=4200/#servicePort=4200/g' ${TARGETDIR}/conf/ui.properties > /tmp/CrashPlan-ui.properties
cp /tmp/CrashPlan-ui.properties ${TARGETDIR}/conf/ui.properties
rm /tmp/CrashPlan-ui.properties

#kill (every 4200) tunnel
CMD="ps -eo pid,args | grep 'ssh -fnNTL 4200:localhost:4243' | grep -v 'grep' | cut -c1-6"
PID=`eval $CMD`
kill -9 $PID
Now create a link from somewhere in your path, so that you can run it with the command CrashPlanRemote
chmod +x /usr/local/crashplan/bin/CrashPlanRemote
sudo ln -s /usr/local/crashplan/bin/CrashPlanRemote /usr/local/bin/CrashPlanRemote
And that should be it!
  • CrashPlanRemove server.name.here
NB. it's best to have setup passwordless login to the remote server
  • /etc/hosts: add a line with the IP address and full.domain.name
  • ssh-copy-id -i ~/.ssh/id_rsa.pub full.domain.name

Friday, September 17, 2010

Ripping DVDs and Ubuntu

I've been mucking around now for a while trying to work out the best way to rip and encode DVDs.

I tried using Handbrake for a while to rip and encode, but what I really want is something that just does it in the background. On the mac, RipIt is a great tool for ripping the DVD to the HDD allowing you to go back at your leisure and encode it.

What i really want is a solution that will autorip on DVD tray-close (like RipIt on the mac) and then a cron that will encode. This is a post about how I get on.

First, we'll need to add restricted formats:
  • sudo apt-get install libdvdread4
  • sudo /usr/share/doc/libdvdread4/install-css.sh
Now, install dvdbackup
  • sudo apt-get install dvdbackup
Create a directory to put the ripped DVDs into and enter it and execute the command to rip the DVD:
  • mkdir Ripped
  • cd Ripped
  • dvdbackup -M
You can also use the -F option rather than -M to just get the main feature, but I had bother with using handbrakeCLI to encode after doing that. Also use the -v flag to give a bit more output.

And, to eject, just use the command
  • eject
So, now we need to work out how to do that automatically when a DVD is inserted into the machine. In the perfect world, we'd do that using the terminal only so that it could run flawlessly on a headless server.

Handbrake

We need to install handbrake from a PPA.
  • sudo add-apt-repository ppa:handbrake-ubuntu/ppa
  • sudo apt-get update && sudo apt-get install handbrake-cli
Then, it's a simple hop skip and a jump to a simple CLI command to encode the ripped disc using a preset for "Film"
  • HandBrakeCLI -i 21/ --main-feature -o 21.mp4 --preset="Film"
Amazingly, this encoded the film at, on average, 280fps (granted, I'm running a quad core AMD monster), but still! I'd tried this on the Mac, using the GUI version and was getting an encode with an average fps of about 9!

Sunday, September 05, 2010

Drweb and plesk

I have been getting some really irritating emails for a couple of weeks from Plesk... actually, it's been a bit longer than that, but I just filtered them out via a gmail auto-delete - probably not the best way to deal with the situation!

What's strange it that I didn't even have dr-web installed. A couple of searches on google revealed a helpful page on serverfault.com which suggested that diabling the update call in the drweb-update cron would be helpful.

So:
  • sudo touch var/log/drwebupdate.log
  • sudo joe /etc/cron.d/drweb-update
  • add ">> /var/log/drwebupdate.log" to the line that has update.pl
  • save the file...

Tuesday, July 13, 2010

tbackup and Plesk

I just installed tbackup from 4psa for Plesk. It installed fine and the licence was installed without a problem. However, every time I tried to set it up, it said that the directory that the backups were to be saved to didn't exist.

Problem was that the debs are for 32-bit systems and the system is 64-bit. A helpful tech from 4psa kindly informed me that the ia32-libs package needed installing.
sudo apt-get install ia32-libs

And everything works fine.

Monday, June 14, 2010

Rhodes + Android + Eclipse + Ubuntu 10.4

In an attempt to start using Rhodes to build an Android app, I'm building my local dev environment, hence the title "Rhodes + Android + Eclipse + Ubuntu 10.4".

Handy pages:
Installing ruby and some essentials

So.. let's start at the beginning, we'll need Ruby, rails and rubygems (which is now in the repros - change the X.X below for the latest version - use tab-complete to the the options).
sudo apt-get install ruby-full build-essential rubygemsX.X
Installing rhodes

Once we have done that, let's get rhodes (version 2.0 is currently in beta)
sudo gem install templater
sudo gem install rake
sudo gem install rails
sudo gem install rhodes --pre
Irritatingly, the apt-get install of rubygems doesn't add the path of the gems that we later installed to the PATH... doh! Have a look where rubgems has been installed to - should be something like "/usr/lib/gems/1.9.1/" although the last directory name will clearly depend on what version you installed above. Open up ~/.bashrc and add (thanks to adamtao):
PATH = "${PATH}":/var/lib/gems/1.9.1/bin
export PATH
You also need to install eclipse and the Android SDK and NDK. I'm not going to list the routine for getting it done since it's explained well elsewhere. Setup for android development including getting all the files from the android development site. Setup an Android AVD (Android virtual device) and test the emulator with a simple hello world script.

Setting up rhodes

Now we need to link our rhodes installation to the SDK and eclipse.
rhodes-setup
You'll be prompted with questions - my answers are below:
  • JDK path: /usr/lib/jvm/java-6-openjdk/
  • Android SDK path: /opt/androidSDK/
  • Android NDK path: /opt/androidNDK/
  • the remainder of the questions related to Windows and Blackberry: (left blank)
Helpful way to find paths is to either look in your path (echo $PATH) or use "locate" (locate java > java_list) and then look in the java_list file that has just been created.

Create a soft link to the rhodes directory:
sudo ln -s /var/lib/gems/1.9.1/gems/rhodes-2.0.0.beta9/ /var/lib/rhodes
First application

So, for now, I'm going to work via the command line and with gedit to edit files; using tutorial2 as a starting point:
  • rhogen app testapp
  • cd testapp
  • joe build.yml
    I wanted to remove the iphone refs and add in some android ones
sdk:"/var/lib/gems/1.9.1/gems/rhodes-2.0.0.beta9"
sdkversion: 2.0.0
name: testapp
version: 1.0
vendor: rhomobile
build: debug
bbver: 4.6
applog: rholog.txt
android:
version: 2.1
extensions: ["extension-name-here", "second-extension-name"]
  • rake run:android
You'll be asked if you want to setup hardware - type yes and answer the questions.

When you have finished, and want to uninstall the app:
  • rake uninstall:android


More to come as a work through the process

Smartphone app development

At radiopaedia.org, we have had iPhone apps for a while - and they are great. However, with a growing userbase that is using Android and other platforms, we'd really like to expand our apps and develop our teaching files for Android too.

Given the usual mantra of "okay, I'll give it a go", I'd launched myself head first into Android app development. My coding background is traditional webdesign - HTML, PHP, CSS and a little bit of javascript (which has been increasing lately with the use of Jquery).

So, the Java environment that is Android development is completely new to me. After a late night and a little bit of progress, I was pointed in the direction of Rhodes - a Ruby-based development stack that allows traditional HTML, CSS and javascript for designing your app and a Ruby backend for the MVC part of the app.

It sounds amazing - and what's better is that you can take your Rhodes app and build it as an iPhone app, Android app, windows mobile app... And it builds the Objective C++, Java etc. And, to give the apps a naitive feel, all you need to do is tweak the CSS - amazing.

For development, I could use RhoHub, an online SDK which looks pretty cool. But, if you want to create private apps with more than 3 contributors, you need to pay. So, I'm going to attempt to build a Rhodes development environment locally using the Android SDK and eclipse on Ubuntu 10.4 - with me luck!

Blogger templater

I'd heard about the new blogger templater, but hadn't had a chance to play with it. But, given that I'm just about to post another item to the blog about smartphone app development, I thought I'd have a play. And... I was duly impressed... and after a couple of clicks have a much improved look to the blog.

Monday, May 17, 2010

Local development with GIT and Plesk

I'm loving GIT. But, what I really wanted to do was to create a development environment locally that pushed changes to a server which was therefore always up to date.

So, I've got an Ubuntu (lucid) machine locally and an Ubuntu server running Plesk 9.x remotely.

Make sure that git is installed on both systems
sudo apt-get install git-core
Make sure that you setup Plesk to give the user shell access (bin/bash) in Web Hosting Settings.

Follow this helpful todo.

Easy! When you are working remotely to setup the git repro, you will need to be root - so remember to change the httpdocs and httpdocs.git directory permissions back to "username:psaserv" and do it recursively:
chown -R username:psaserv httpdocs
chown -R username:psaserv httpdocs.git
Passwordless login and git clone

It's worth while setting up passwordless login:
ssh-copy-id -i .ssh/id_rsa.pub username@domainname.tld
Then, the command to get the git repro locally becomes:
git clone ssh://username@domainname.tld/var/www/vhosts/domainname.tld/httpdocs.git
Setup apache

You'll need to make sure the apache2, php5 are installed:
sudo apt-get install apache2 php5
You need to setup apache by editing the conf file: /etc/apache2/sites-available/default. If you are going to run multiple local sites, you'll have to declare them here. For each site, add the following:
<VirtualHost *:80>
ServerName localservername
DocumentRoot /home/sites/location/httpdocs/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/sites/location/httpdocs/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
You also need to edit /etc/hosts to provide a route to your local server. Add a line:
127.0.0.1 localserver

Setup database forwarding

We could just setup mysql or other database locally. However, then you need to try and keep local and remote databases synced. If you are just reading, it's much simpler to setup an ssh tunnel to your remote server.

While the ssh for the git clone was as a plesk user of the particular website, this ssh should be performed as a user of the server i.e. it should log you in a you, not as a website. You need to make sure that mysql is NOT running locally:
sudo stop mysql
And then, type
ssh -L3306:localhost:3306 remoteserver.tld
For ease, if you save this command to a file and put it in /usr/local/bin and then "chmod +x" it, you can simply type the name of the file (e.g. connect) and the tunnel will be set up.

Connecting to the tunnelled mysql db via PHP

The other piece of glue is to realise that you can't connect to the database as localhost, you have to use 127.0.0.1, e.g.:
mysql_connect('127.0.0.1', $username, $password);
All in all, a pretty successful development environment.


Saturday, December 26, 2009

VPS.net server install

Notes from a recent installation of Ubuntu server on a UK2 cloud server.

signup
login as root@

passwd
sudo apt-get install joe
joe /etc/apt/sources.list
apt-get update
apt-get upgrade
adduser username
usermod -G admin username

joe /etc/ssh/sshd_config (permitrootlogin no)
/etc/init.d/ssh restart

logout

ssh-copy-id -i .ssh/id_rsa.pub username@host.domain.tld

ssh username@host

wget http://download1.parallels.com/Plesk/PPP9/Ubuntu8.04/parallels_installer_v3.4.1_build090204.18_os_Ubuntu_8.04_x86_64

mv parallels_installer.... /tmp/
chmod +x file
sudo ./file

follow the instructions

log into the Plesk frontend
admin:setup

setup master user details

-> updates
- -> prefs -> Check for updates upon administrator's login to control panel [Y]

-> Settings
- -> Spam Filter Settings -> Switch on server-wide greylisting spam protection [Y]

-> Control Panel Interface
- -> Interface Management

apt-get install munin-node
joe /etc/munin/munin-node.conf

#
# Example config-file for munin-node
#

log_level 4
log_file /var/log/munin/munin-node.log
port 4949
pid_file /var/run/munin/munin-node.pid
background 1
setseid 1

# Which port to bind to;
host *
user root
group root
setsid yes

# Regexps for files to ignore

ignore_file ~$
ignore_file \.bak$
ignore_file %$
ignore_file \.dpkg-(tmp|new|old|dist)$
ignore_file \.rpm(save|new)$

# Set this if the client doesn't report the correct hostname when
# telnetting to localhost, port 4949
#
#host_name localhost.localdomain
host_name [luffness.konsulting.ltd.uk]

# A list of addresses that are allowed to connect. This must be a
# regular expression, due to brain damage in Net::Server, which
# doesn't understand CIDR-style network notation. You may repeat
# the allow line as many times as you'd like

allow ^127\.0\.0\.1$
allow ^80\.2\.73\.137$

****************************
[monitoring server]
joe /etc/munin/munin.conf

[craigielaw.konsulting.ltd.uk]
address 83.170.83.182
use_node_name yes

***************************

** install mysqltuner
wget mysqltuner.pl
chmod +x mysqltuner.pl
sudo mv mysqltuner.pl /usr/local/bin/mysqltuner

** alter crontab
** allows a weekly email to test for upgrade and mysql tuning options
sudo crontab -e
add:
MAILTO=server@klever.co.uk
17 3 * * 3 apt-get update; apt-get upgrade -sy
17 4 * * 5 /usr/local/bin/mysqltuner

Monday, September 28, 2009

Ubuntu fonts

Get a raft of fonts for Ubuntu with a simple apt-get
sudo apt-get install ttf-sil-gentium ttf-dustin ttf-georgewilliams ttf-sjfonts sun-java6-fonts ttf-larabie-deco ttf-larabie-straight ttf-larabie-uncommon
Any, if Microsoft fonts are required:
sudo apt-get install msttcorefonts
Works a treat.. and you could do worse than gnome-specimen for a font previewer.

Monday, September 14, 2009

Load alert

I've been having an issue with a server whose load sporadically runs high. While trying to work out what the problem was, I needed a way to know when the load peaked.

I modified a simple script to allow me to do just that and then ran it from cron. Only problem is that if it detects a high load, an email is sent each time the cron is run (maybe every 5 minutes!)
!/bin/bash
avg=`uptime | awk '{print $8" " $9 " "$10 $11 $12 }' | tr -s , " "`
cur=`uptime | awk '{print $10}' | tr -d , | cut -d. -f1`
str="============================="
info="Curent $avg"
if [ $cur -ge 1 ]; then
info1="Server load is high presently"
touch /tmp/tmp.00
echo -e "$str\n$info\n$info1\n$str\n" >> /tmp/tmp.00
ps aux | head -1 >> /tmp/tmp.00
ps aux | sort -rn +2 | head -10 >> /tmp/tmp.00;
mail -s "Alert: Load Average for `hostname` on `date` " jeremy@yourdomainnamehere.com < /tmp/tmp.00;
rm -f /tmp/tmp.00
else
#echo -e "$str\n$info\n$str"
fi
Cron might look something like this:
*/5 * * * * /usr/local/bin/loadaverage

Sunday, August 30, 2009

Cloud server Plesk Ubuntu install

Notes from a recent installation of Ubuntu server on a UK2 cloud server.

signup
login as root@

passwd
sudo apt-get install joe
joe /etc/apt/sources.list
apt-get update
apt-get upgrade
adduser username
usermod -G admin username

joe /etc/ssh/sshd_config (permitrootlogin no)
/etc/init.d/ssh restart

logout

ssh-copy-id -i .ssh/id_rsa.pub username@host.domain.tld

ssh username@host

wget http://download1.parallels.com/Plesk/PPP9/Ubuntu8.04/parallels_installer_v3.4.1_build090204.18_os_Ubuntu_8.04_x86_64

chmod +x file
sudo ./file

follow instructions

make sure that postfix is installed as the MTA

sudo apt-get install postgrey
netstat -lpn | grep 60000
joe /etc/postfix/main.cf (add check_policy_service inet:127.0.0.1:60000,) before reject_unauth_destination
/etc/init.d/postfix restart
tail -f /var/log/mail.info

apt-get install munin-node
joe /etc/munin/munin-node.conf

#
# Example config-file for munin-node
#

log_level 4
log_file /var/log/munin/munin-node.log
port 4949
pid_file /var/run/munin/munin-node.pid
background 1
setseid 1

# Which port to bind to;
host *
user root
group root
setsid yes

# Regexps for files to ignore

ignore_file ~$
ignore_file \.bak$
ignore_file %$
ignore_file \.dpkg-(tmp|new|old|dist)$
ignore_file \.rpm(save|new)$

# Set this if the client doesn't report the correct hostname when
# telnetting to localhost, port 4949
#
#host_name localhost.localdomain
host_name [luffness.konsulting.ltd.uk]

# A list of addresses that are allowed to connect. This must be a
# regular expression, due to brain damage in Net::Server, which
# doesn't understand CIDR-style network notation. You may repeat
# the allow line as many times as you'd like

allow ^127\.0\.0\.1$
allow ^80\.2\.73\.137$

[monitoring server]
joe /etc/munin/munin.conf

[craigielaw.konsulting.ltd.uk]
address 83.170.83.182
use_node_name yes

http://www.debuntu.org/postfix-and-postgrey-a-proactive-approach-to-spam-filtering
https://help.ubuntu.com/community/PostfixAmavisNew

** spamassassin
sudo apt-get install spamassassin spamc

** install backports
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -t hardy-backports spamassassin

** install mysqltuner
wget http://mysqltuner.com/mysqltuner.pl.gz
gzip -d mysqltuner.pl.gz
chmod +x mysqltuner.pl
sudo mv mysqltuner.pl /usr/local/bin/mysqltuner

** alter crontab
sudo crontab -e
add:
MAILTO=server@klever.co.uk
17 3 * * 3 apt-get update; apt-get upgrade -sy
17 4 * * 5 /usr/local/bin/mysqltuner


other helpful software
sudo apt-get install ifstat rcconf

tbackup
ssh-keygen -rsa
ssh-copy-id -i......