Now Playing Tracks

Handling Multiple Displays with x2x

x2x is a great program for users who have two computers and monitors, or a monitor and a laptop, and want to share mouse and keyboard between the two monitors. You have to be using X on both machines. In my case, I have Ubuntu Precise Pangolin (12.04 LTS) on both. To install X2X, on Workstation 1 do:

sudo apt-get install x2x

And on workstation 2 I do:

sudo apt-get install x2x openssh-server

Now, on workstation 1, just do the following in the command line.

ssh -XC user@workstation2  x2x -east -to :0

Make sure to replace “workstation2” with the name of your computer, or the IP. You can make a shortcut for this by adding that command to your shortcut.

Reference this article for further explanation:
https://help.ubuntu.com/community/X2xHowto

Using Ubuntu as an A2DP Receiver

To use your Ubuntu machine as an a2dp bluetooth device, you must first configure it to register as an “a2dp sink” endpoint.

The bluez package in Ubuntu (10.04 and above) includes a utility called sdptool that can be used to check whether a bluetooth device is configured as an a2dp sink or not. Here is the output from sdptool run against my bluetooth headset (the address is taking from the “bluetooth settings” dialog in the gnome-control-center):

$ sdptool search —bdaddr 00:18:16:3A:3B:D4 a2snk

Searching for a2snk on 00:18:16:3A:3B:D4 …

Service RecHandle: 0x10002

Service Class ID List:

  “Audio Sink” (0x110b)

Protocol Descriptor List:

  “L2CAP” (0x0100)

    PSM: 25

  “AVDTP” (0x0019)

    uint16: 0x102

Profile Descriptor List:

  “Advanced Audio” (0x110d)

    Version: 0x0102

$

and here is the output when run against my local Ubuntu machine:

$ sdptool search —bdaddr local a2snk

Searching for a2snk on FF:FF:FF:00:00:00 …

$

This shows that the Ubuntu machine is not advertising itself as an a2dp sink. It is advertising itself as an a2dp source however:

$ sdptool search —bdaddr local a2src

Searching for a2src on FF:FF:FF:00:00:00 …

Service Name: Audio Source

Service RecHandle: 0x10003

Service Class ID List:

  “Audio Source” (0x110a)

Protocol Descriptor List:

  “L2CAP” (0x0100)

    PSM: 25

  “AVDTP” (0x0019)

    uint16: 0x102

Profile Descriptor List:

  “Advanced Audio” (0x110d)

    Version: 0x0102


$

This enables the Ubuntu machine to pair correctly with the headset as an audio source, but it does not enable using the Ubuntu machine as an output (sink) for bluetooth audio.

If you edit /etc/bluetooth/audio.conf, you can enable a2dp sink support by adding this line underneath the [General] section:

  Enable=Source

This is both counterintuitively named since what we’re adding here is bluetooth sink support, not source support, and in contradiction with the comment in this file that claims all implemented services are enabled by default. :(

After making this change, you will need to restart bluetoothd by running ‘sudo service bluetooth restart’.

If you have previously paired your Android or iOS device with the Ubuntu computer while trying to get this work, you will need to delete the pairing on both sides and re-pair them in order to get Android/iOS to recognize Ubuntu as an available audio device.

Once you’ve done this, the Android/iOS device should show up as an input device under pulseaudio. Then you need to tell pulseaudio to route this audio input to your output (such as your speakers, or a bluetooth headset). You can do this from the Sound Settings GUI or from the command line.

Sound Settings GUI

Ubuntu Sound Control Panel

Command Line:

Using the pactl command:

pactl load-module module-loopback source=$BTSOURCE sink=$SINK

(Replace “$BTSOURCE” with the source name for your bluetooth device as seen by pulseaudio, e.g. bluez_source.14_DA_E9_2A_D7_57; and replace $SINK with the name of the pulseaudio output you want to send the audio stream to, e.g.: alsa_output.pci-0000_00_1b.0.analog-stereo)

  • You can find $SINK with pactl list sinks, $SINK is shown after Name:
  • Similarly you can see the $BTSOURCE with pactl list sources

Here’s what an example one would look like (Remember to replace the : with _ in the bluetooth address!):

pactl load-module module-loopback source=bluez_source.14_DA_E9_2A_D7_57 sink=alsa_output.pci-0000_00_14.2.analog-stereo

Be careful however to remove this loopback connection before you drop this audio connection! pulseaudio appears to re-connect the loopback connection to the next available audio input when the connection drops, so if for instance your laptop microphone is unmuted, you may get some very bad feedback. To drop this loopback connection when you’re done, run:

pactl unload-module $(pactl list short modules | grep “loopback.*$BTSOURCE” | cut -f1)

Again, replace “$BTSOURCE” with the name for the pulseaudio source that refers to your bluetooth device.

Upgrade to Ubuntu 11.10 problem: Waiting for network configuration then black screen solution

Have you just upgraded to Ubuntu 11.10 Oneiric Ocelot and now getting the “Waiting for network configuration” message followed by “Waiting up to 60 seconds more for network”? This then might be accompanied by a black blank screen.

The bug is here ( http://tinyurl.com/79klcdu ) and the fix is based on this: http://tinyurl.com/6k7onr4

Hit Ctrl+Alt+F1 at the blank screen to get you to a non-X terminal (tty1)
Login in with your username and password
Change to root with: sudo -i and enter your password
Run: 

mkdir -p /run /run/lock
rm -rf /var/run /var/lock
ln -s /run /var
ln -s /run/lock /var
reboot

You should have 11.10 back again.

BackupPC Host + Client Setup Script

This script is designed to automatically set up a Linux/Unix host to be backed up using BackupPC

The system to be backed up must have a root password set, and the ability to use SSH Keys for authentication by the backuppc machine.

NOTE: This script assumes you have already generated SSH keys for BackupPC

To use this script, place it in

/usr/bin/AddHost

and make it executable.

chmod +x /usr/bin/AddHost

Once you have done the above, DO NOT add the host to BackupPC via the Web Frontend, this script will do it automatically for you.

This script requires the system to be backed up to be resolvable via DNS and have both IPv4 and IPv6 connectivity (IPv6 can be disabled by commenting out the IPv6 block)

Run AddHost, e.g. to set up the host “JUbuntu” to be backed up, run as root:

AddHost JUbuntu

And thats all there is to it.

/usr/bin/AddHost:

#!/bin/bash
if [ “`whoami`” != “root” -o “$SUDO_USER” != “” ]; then
echo “Not root. Run as root. Not SUDO!!!!”
exit 1
fi

if [ “$1” == “” ]; then
echo “No hostname specified”
exit 2
fi

HOST=$1
KEYDIR=”/var/lib/backuppc/.ssh”;

# Check IPv4 Connectivity
ping -c1 $HOST >/dev/null 2>&1
RESP=$?
if [ $RESP != 0 ]; then
echo “Unable to ping host via IPv4”
exit 3
fi

# Check IPv6 Connectivity
ping6 -c1 $HOST >/dev/null 2>&1
RESP=$?
if [ $RESP != 0 ]; then
        echo “Unable to ping host via IPv6”
        exit 3
fi

# Do Stuff!!!!!

# Sync Keyfiles to destination host
echo “About to sync keyfiles to $HOST. Press return when ready”
echo “Backups will not run without running this step!”
read
su backuppc -c sh -c “scp -r -q ~/.ssh root@$HOST:~”

# Check Keys
KEYRES=”`su backuppc -c sh -c “ssh root@Jubuntu ls -l /root/.ssh/authorized_keys2”`”
if [[ “$KEYRES” =~ authorized_keys2 ]]; then
FAILED=0
else
FAILED=1
fi
 
if [ $FAILED -eq 1 ]; then
echo “Keys failed to transfer properly, Cleaning Up”
echo “Exiting… Sorry”
exit 5
fi

# Keys transferred.
echo “Keys Transferred Successfully”
# Check the host doesnt already exist
EXISTS=”`grep -i $HOST /etc/backuppc/hosts`”
if [ “$EXISTS” != “” ]; then
        echo “Host is already set up for BackupPC”
        exit 4
fi

# Add the host to BackupPC
echo “$HOST     0       idkpmiller” | tee -a /etc/backuppc/hosts >/dev/null 2>&1

echo “Added $HOST to BackupPC hosts list successfully”
exit 0

Load Balanced Highly Available Web Server Set Up

Boredom is something im plagued with nowadays, So last night i decided to take a crack at getting a load balanced Highly Available web server set up running. And thats what I did.

Instructions:

1 Preliminary Note

In this tutorial I will use the following hosts:

  • Load Balancer 1: lb1.example.com, IP address: 192.168.0.100
  • Load Balancer 2: lb2.example.com, IP address: 192.168.0.101
  • Web Server 1: http1.example.com, IP address: 192.168.0.102
  • Web Server 2: http2.example.com, IP address: 192.168.0.103
  • We also need a virtual IP address that floats between lb1 and lb2192.168.0.99

Here’s a little diagram that shows our setup:

    shared IP=192.168.0.99
 192.168.0.100  192.168.0.101 192.168.0.102 192.168.0.103
 ———-+——————+———————+—————-+—————
        |            |              |           |
     +—+—+      +—+—+      +——+——+ +——+——+
     | lb1 |      | lb2 |      |  http1  | |  http2  |
     +——-+      +——-+      +————-+ +————-+
     pound        pound        2 web servers (Apache) 
     keepalived   keepalived

The shared (virtual) IP address is no problem as long as you’re in your own LAN where you can assign IP addresses as you like. However, if you want to use this setup with public IP addresses, you need to find a hoster where you can rent two servers (the load balancer nodes) in the same subnet; you can then use a free IP address in this subnet for the virtual IP address.

 

http1 and http2 are standard Ubuntu Apache setups with the document root /var/www (the configuration of this default vhost is stored in /etc/apache2/sites-available/default). If your document root differs, you might have to adjust this guide a bit.

To demonstrate the session-awareness of Pound, I’m assuming that the web application that is installed on http1 and http2 uses the session id PHPSESSIONID.

2 Preparing The Backend Web Servers

Pound works as a transparent proxy, i.e., it will pass on the original user’s IP address in a field called X-Forwarded-For to the backend web servers. Of course, the backend web servers should log the original user’s IP address in their access logs instead of the IP addresses of our load balancers. Therefore we must modify theLogFormat line in /etc/apache2/apache2.conf and replace %h with %{X-Forwarded-For}i:

http1/http2:

nano /etc/apache2/apache2.conf

[...]
#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
[...]

Afterwards we restart Apache:

/etc/init.d/apache2 restart

We are finished already with the backend servers; the rest of the configuration happens on the two load balancer nodes.

3 Installing Pound

We can install Pound on our two load balancers like this:

lb1/lb2:

apt-get install pound

4 Configuring The Load Balancers

The Pound configuration is stored in /etc/pound/pound.cfg and is pretty straight-forward.

We back up the original /etc/pound/pound.cfg and create a new one like this:

lb1/lb2:

cp /etc/pound/pound.cfg /etc/pound/pound.cfg_orig
cat /dev/null > /etc/pound/pound.cfg
nano /etc/pound/pound.cfg

## Minimal sample pound.cfg
##
## see pound(8) for details


######################################################################
## global options:

User            "www-data"
Group           "www-data"
#RootJail       "/chroot/pound"

## Logging: (goes to syslog by default)
##      0       no logging
##      1       normal
##      2       extended
##      3       Apache-style (common log format)
LogLevel        1

## check backend every X secs:
Alive           2

## use hardware-accelleration card supported by openssl(1):
#SSLEngine      "<hw>"


######################################################################
## listen, redirect and ... to:

## redirect all requests on port 80 ("ListenHTTP") to the virtual IP address:
ListenHTTP
        Address 192.168.0.99
        Port    80
End

Service
        BackEnd
                Address http1.example.com
                Port    80
        End
        BackEnd
                Address http2.example.com
                Port 80
        End
        Session
                Type Cookie
                ID   "PHPSESSIONID"
                TTL  300
        END
End

Afterwards, we set startup to 1 in /etc/default/pound:

nano /etc/default/pound

# Defaults for pound initscript
# sourced by /etc/init.d/pound
# installed at /etc/default/pound by the maintainer scripts

# prevent startup with default configuration
# set the below varible to 1 in order to allow pound to start
startup=1

5 Setting Up keepalived

We’ve just configured Pound to listen on the virtual IP address 192.168.0.99, but someone has to tell lb1 and lb2 that they should listen on that IP address. This is done by keepalived which we install like this:

lb1/lb2:

apt-get install keepalived

To allow Pound to bind to the shared IP address, we add the following line to /etc/sysctl.conf:

nano /etc/sysctl.conf

[...]
net.ipv4.ip_nonlocal_bind=1

… and run:

sysctl -p

Next we must configure keepalived (this is done through the configuration file /etc/keepalived/keepalived.conf). I want lb1 to be the active (or master) load balancer, so we use this configuration on lb1:

lb1:

nano /etc/keepalived/keepalived.conf

vrrp_script chk_pound {           # Requires keepalived-1.1.13
        script "killall -0 pound"     # cheaper than pidof
        interval 2                      # check every 2 seconds
        weight 2                        # add 2 points of prio if OK
}

vrrp_instance VI_1 {
        interface eth0
        state MASTER
        virtual_router_id 51
        priority 101                    # 101 on master, 100 on backup
        virtual_ipaddress {
            192.168.0.99
        }
        track_script {
            chk_pound
        }
}

(It is important that you use priority 101 in the above file - this makes lb1 the master!)

Then we start keepalived on lb1:

lb1:

/etc/init.d/keepalived start

Then run:

lb1:

ip addr sh eth0

… and you should find that lb1 is now listening on the shared IP address, too:

lb1:/etc/keepalived# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:a5:5b:93 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global eth0
    inet 192.168.0.99/32 scope global eth0
    inet6 fe80::20c:29ff:fea5:5b93/64 scope link
       valid_lft forever preferred_lft forever
lb1:/etc/keepalived#

Now we do almost the same on lb2. There’s one small, but important difference - we use priority 100 instead of priority 101 in /etc/keepalived/keepalived.confwhich makes lb2 the passive (slave or hot-standby) load balancer:

lb2:

nano /etc/keepalived/keepalived.conf

vrrp_script chk_pound {           # Requires keepalived-1.1.13
        script "killall -0 pound"     # cheaper than pidof
        interval 2                      # check every 2 seconds
        weight 2                        # add 2 points of prio if OK
}

vrrp_instance VI_1 {
        interface eth0
        state MASTER
        virtual_router_id 51
        priority 100                    # 101 on master, 100 on backup
        virtual_ipaddress {
            192.168.0.99
        }
        track_script {
            chk_pound
        }
}

Then we start keepalived:

lb2:

/etc/init.d/keepalived start

As lb2 is the passive load balancer, it should not be listening on the virtual IP address as long as lb1 is up. We can check that with:

lb2:

ip addr sh eth0

The output should look like this:

lb2:~# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:e0:78:92 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.101/24 brd 192.168.0.255 scope global eth0
    inet6 fe80::20c:29ff:fee0:7892/64 scope link
       valid_lft forever preferred_lft forever
lb2:~#

6 Starting Pound

Now we can start Pound:

lb1/lb2:

/etc/init.d/pound start

7 Testing

Our high-availability load balancer is now up and running.

You can now make HTTP requests to the virtual IP address 192.168.0.99 (or to any domain/hostname that is pointing to the virtual IP address), and you should get content from the backend web servers.

You can test its high-availability/failover capabilities by switching off one backend web server - the load balancer should then redirect all requests to the remaining backend web server. Afterwards, switch off the active load balancer (lb1) - lb2 should take over immediately. You can check that by running:

lb2:

ip addr sh eth0

You should now see the virtual IP address in the output on lb2:

lb2:~# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:e0:78:92 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.101/24 brd 192.168.0.255 scope global eth0
    inet 192.168.0.99/32 scope global eth0
    inet6 fe80::20c:29ff:fee0:7892/64 scope link
       valid_lft forever preferred_lft forever
lb2:~#

When lb1 comes up again, it will take over the master role again.

To Tumblr, Love Pixel Union