git
Comments

Git Svn - Working With Branches and Tags

So as many know I am firmly an advocate of git, and a pesemist when it comes to subversion because well it seems to fail for unresolveable reasons either through use, or through fault of it’s own (lock files in meta directories for one …).

Now this is not to say that git is infallable. At any rate here is the best way to use git as an svn client and still maintain access to branches and tags.

git svn init -s <protocol>://<FQDN of server>/<repo path> ./folder_to_checkout_to

OR

git svn init -t tags -b branches -T trunk <protocol>://<FQDN of server>/<repo path> ./folder_to_checkout_to
  1. This initializes an empty git respository in the folder specified (This can also be handy for migrating from subversion)
  2. The examples above use -s for stdlayout, the 2nd example can be used to specify exact locations of trunk,tags,branches.

Now we need the data:

git svn fetch

One thing to note that whilst tags are present within git, subversion tags do not (at this stage) translate into git tags, as such to checkout svn tags (if you are not yet ready to make the jump to using git and want to maintain a subversion server this will needed).

git checkout -b tags/tag_name tags/tag_name

What does this do? it will checkout the tag from subversion: tag_name and setup a local git branch to track it.

If you are ready however to make the jump to git you can https://gitready.com/advanced/2009/02/16/convert-git-svn-tag-branches-to-real-tags.html.

Comments

Yummy Chroots Building Chroots With Yum on Fedora 16

We’re going to build a minimal chroot directory for Fedora 16 using yum and rpm, we are using the ChrootDirectory functionality of Openssh which only came in >= 4.9p1

Credit goes Here for a great article getting me started on this.

As root:

mkdir --mode=700 -p /chroot/chrootuser
rpm --root /chroot/chrootuser --initdb
yumdownload --destdir=/var/tmp fedora-release
rpm --root /chroot/chrootuser -ivh --nodeps /var/tmp/fedora-release*rpm
yum --installroot=/chroot/chrootuser -y install bash
yum --installroot=/chroot/chrootuser -y install coreutils
groupadd chrooted

Edit /etc/ssh/sshd_config

Match Group chrooted
        ChrootDirectory /chroot/%u
        AllowTcpForwarding no
        X11Forwarding no
        AllowAgentForwarding no
        PermitRootLogin no
        ForceCommand /bin/bash

And restart the service: systemctl restart sshd.service

Add the user:

useradd -G chrooted -d /chroot/chrootuser chrootuser

ssh in as the user and they will be in the jailed directory

Comments

RHEL 6 Openstack via EPEL Nova and Glance on KVM

In this post I will cover getting openstack nova and glance services installed from EPEL and configured to the point where an image can be started, this assumes

  1. You have a mysql instance installed and running
  2. You have a rabbitmq-server installed and running
  3. You have kvm installed and running (libvirt)
  4. You have selinux set to permissive, as I will not be covering selinux rules here at this time and I do not think disabled is a valid option ;-)

I will also be carrying out mySQL configuration of glance and nova, for 2011.3 (Diablo), though most if not all of this should be portable to the Essex release

Install EPEL

rpm -Uvh https://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm

Install Nova and Glance

yum -y install openstack-nova openstack-glance

yum should take care of all the dependencies here, and install both with a minimal configuration.

Burning and Rebuilding bridges

First thing’s first KVM is going to install with it’s own default bridged networking, this provides NAT.

Which is also noted as being very slow (There is/was an note on the wiki@ linux-kvm.org but I have been unable to locate it at the time of writing)

If you are only setting this up for experimentation you can run with the default networking, simply use vibr0 in your nova.conf instead of br0, and ensure you have ipv4 forwarding enabled.

Burning Bridges

1
2
3
4
5
6
7
8
9
virsh net-list
Name                 State      Autostart
-----------------------------------------
default              active     yes 
virsh net-destroy default
Network default destroyed
virsh net-undefine default
Network default has been undefined
service libvirtd restart

Building Bridges

The theory here is that this configuration of bridge will give us near native network performance, which if you are setting up for use beyond a throwaway sandbox, you really do not want to start introducing bottlenecks.

Shutdown and disable NetworkManager

1
2
3
service NetworkManager stop
chkconfig NetworkManager off
chkconfig network on

If you know of a NetworkManager friendly way of doing the following please let me know!

In this scenario br0 becomes your current eth0

/etc/sysconfig/network-scripts/ifcfg-br0

1
2
3
4
5
6
7
8
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
IPADDR=192.168.99.1
NETMASK=255.255.255.0
GATEWAY=192.168.99.254
ONBOOT=yes
DELAY=0

/etc/sysconfig/network-scripts/ifcfg-eth0

1
2
3
4
5
6
7
DEVICE=eth0
BOOTPROTO=none
TYPE=Ethernet
HWADDR=00:11:22:33:44:55
ONBOOT=yes
USERCTL=no
BRIDGE=br0

There is plenty more fun to be had here such as bonded interfaces (I myself have a few systems with bonded interfaces as such becoming br0 -> bond0 -> NIC’s), but that’s for another time.

Note: you may also use brctl for temporary configurations if you are just experimenting.

Caution: my network dropped out immediatly on my testbox, most likely because networkmanager was running, always ensure you can attach to the head of your box when doing network configuration ;-)

Once you have these configurations in place (Ensuring your have replaced the placeholder IP’s and MAC address with valid ones) you can now go for a

1
service network restart

All being well you’ll lose and re-establish connection, of you’ll be attaching a monitor / to kvm over ip.

Configuring Nova

First we’re going to need a blank database, please ensure you change the placeholder password that follows for something more secure, and amend the host if you are using mySQL on the same host as nova.

create database nova;
grant all privileges on nova.* to 'nova'@'localhost' identified by 'nova';

Your /etc/nova.conf should resemble this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
--logdir=/var/log/nova
--state_path=/var/lib/nova
--lock_path=/var/lib/nova/tmp
--dhcpbridge=/usr/bin/nova-dhcpbridge
--dhcpbridge_flagfile=/etc/nova/nova.conf
--injected_network_template=/usr/share/nova/interfaces.template
--libvirt_xml_template=/usr/share/nova/libvirt.xml.template
--vpn_client_template=/usr/share/nova/client.ovpn.template
--credentials_template=/usr/share/nova/novarc.template
--network_manager=nova.network.manager.FlatDHCPManager
--iscsi_helper=tgtadm
--sql_connection=mysql://nova:nova@localhost/nova
--rabbit_host=localhost
--glance_api_servers=localhost:9292
--iscsi_ip_prefix=10.0.0.1
--bridge=br0

Setup the database and start the relevant nova services

nova-manage db sync
for i in api network scheduler compute; do service openstack-nova-$i start; done
for i in api network scheduler compute; do chkconfig openstack-nova-$i on; done

Note: you could also use openstack-nova-db-setup instead of “nova-manage db sync”, but it requires mysql-server, which at the time of writing if you have Percona installed will falsely adivse you a need to install mysql-server, Percona need to add: “Provides: mysql-server” to their spec ideally.

Remember this is only a basic setup so a lot of the options are left default such as the network_manager, I will cover their options at a later date.

Onto setting up a basic user (Note: this will be replaced in future posts with keystone)

1
2
3
nova-manage user admin saiweb
nova-manage project create saiweb saiweb
nova-manage network create saiweb 192.168.99.1/24 1 256 --bridge=br0

Take a moment to run a quick check on your services and network

1
2
3
4
5
6
7
8
9
nova-manage service list
Binary           Host                                 Zone             Status     State Updated_At
nova-network     oneiroi                              nova             enabled    :-)   2012-03-07 22:21:10
nova-compute     oneiroi                              nova             enabled    :-)   2012-03-07 22:21:12
nova-scheduler   oneiroi                              nova             enabled    :-)   2012-03-07 22:21:10

nova-manage network list
id      IPv4                IPv6            start address   DNS1            DNS2            VlanID          project         uuid           
1       10.0.0.0/24         None            10.0.0.2        8.8.4.4         None            None            None            7d480f13-47f7-4117-9889-d44f378c3fee

Now we need the nova credentials for this user + project.

1
2
3
4
5
6
7
8
9
10
nova-manage project zipfile saiweb saiweb
unzip nova.zip
mv ./{novarc,pk.pem,cert.pem,cacert.pem} ~/.nova/
chmod 700 ~/.nova
chmod 600 ~/.nova/*
rm ./nova.zip
echo ". ~/.nova/novarc" >> ~/.bashrc
source ~/.bashrc
euca-add-keypair nova_key > ~/.nova/nova_key.priv
chmod 600  ~/.nova/nova_key.priv

Configuring Glance

The only change I made was to make glance use mysql.

create database glance;
grant all privilges on glance.* to 'glance'@'localhost' identified by 'glance';

/etc/glance/glance-resgistry.conf

1
2
3
...
sql_connection = mysql://glance:glance@localhost/glance
...

Once you have made the change, unlike nova all you need do is start glance and it will setup the database.

for i in api registry; do chkconfig openstack-glance-$i on; service openstack-glance-$i start; done

Now were going to need an image, I’m using the BT5-R2 .iso as an example, you could use any of the pre-generated images out there, or even build them using oz

1
glance add name="BT5-R2-Gnome-x64" is_public=True container_format=ovf disk_format=raw < ./BT5R2-GNOME-64.iso

Once the import has completed it should appear in your glance index

1
2
3
4
glance index
ID               Name                           Disk Format          Container Format     Size          
---------------- ------------------------------ -------------------- -------------------- --------------
1                BT5-R2-Gnome-x64               raw                  ovf                      2762084352

And assuming you setup your nova.conf correctly you should now be able to see this image from nova

1
2
3
4
5
6
nova image-list
+----+------------------+--------+
| ID |       Name       | Status |
+----+------------------+--------+
| 1  | BT5-R2-Gnome-x64 | ACTIVE |
+----+------------------+--------+

You will also have some default instance sizes aka flavours (commands use american spelling flavor).

1
2
3
4
5
6
nova-manage flavor list
m1.medium: Memory: 4096MB, VCPUS: 2, Storage: 40GB, FlavorID: 3, Swap: 0MB, RXTX Quota: 0GB, RXTX Cap: 0MB
m1.large: Memory: 8192MB, VCPUS: 4, Storage: 80GB, FlavorID: 4, Swap: 0MB, RXTX Quota: 0GB, RXTX Cap: 0MB
m1.tiny: Memory: 512MB, VCPUS: 1, Storage: 0GB, FlavorID: 1, Swap: 0MB, RXTX Quota: 0GB, RXTX Cap: 0MB
m1.xlarge: Memory: 16384MB, VCPUS: 8, Storage: 160GB, FlavorID: 5, Swap: 0MB, RXTX Quota: 0GB, RXTX Cap: 0MB
m1.small: Memory: 2048MB, VCPUS: 1, Storage: 20GB, FlavorID: 2, Swap: 0MB, RXTX Quota: 0GB, RXTX Cap: 0MB

Booting your first Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
nova boot --flavor 2 --image 1 "BT5"
+--------------+--------------------------------------+
|   Property   |                Value                 |
+--------------+--------------------------------------+
| accessIPv4   |                                      |
| accessIPv6   |                                      |
| adminPass    | pnFKeVPpbb7bKKy6                     |
| config_drive |                                      |
| created      | 2012-03-07T23:11:59Z                 |
| flavor       | m1.small                             |
| hostId       |                                      |
| id           | 1                                    |
| image        | BT5-R2-Gnome-x64                     |
| key_name     | None                                 |
| metadata     | {}                                   |
| name         | BT5                                  |
| progress     | 0                                    |
| status       | BUILD                                |
| tenant_id    | saiweb                               |
| updated      | 2012-03-07T23:11:59Z                 |
| user_id      | saiweb                               |
| uuid         | fb08be47-2647-4cb2-86d8-867ea0ef4981 |
+--------------+--------------------------------------+
virsh list
 Id Name                 State
----------------------------------
  1 instance-00000001    running

And as iso-boot is not currently complete, this example falls down here, as the instance fails to boot from the .iso file, still you now have

  1. Successfully configured nova
  2. Sucessfully configured glance
  3. Have nova using glance

All you need do is load a valid image into glance and boot using nova, so now I will be cheating a little I will create a blank 10GB qcow2 image, import it into glance boot it and use virt-manager to attach the .iso and reboot.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
qemu-img create -f qcow2 blank.qcow2 10G
Formatting 'blank.qcow2', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536
glance add name="blank-10G" is_public=True container_format=bare disk_format=qcow2 < ./blank.qcow2
Added new image with ID: 2
nova boot --flavor 2 --image 2 "BT5"
+--------------+--------------------------------------+
|   Property   |                Value                 |
+--------------+--------------------------------------+
| accessIPv4   |                                      |
| accessIPv6   |                                      |
| adminPass    | H3khDYMwheNNWBV3                     |
| config_drive |                                      |
| created      | 2012-03-07T23:01:50Z                 |
| flavor       | m1.small                             |
| hostId       |                                      |
| id           | 2                                    |
| image        | blank-10G                            |
| key_name     | None                                 |
| metadata     | {}                                   |
| name         | BT5                                  |
| progress     | 0                                    |
| status       | BUILD                                |
| tenant_id    | home                                 |
| updated      | 2012-03-07T23:01:50Z                 |
| user_id      | oneiroi                              |
| uuid         | 05ce2b5d-d03c-442e-99e3-2c079469ec5b |
+--------------+--------------------------------------+

Now I cheat I used virt-manager to force off the insance, create and attach an IDE cdrom and set it as the primary boot device. BT5 boots from the ISO and I can even begin to work through the install to hard drive menus, which as irony would have it prompts me that it needs an 11.5GB partition to install upon :D

I will cover producing proper images in my next openstack post, as the size of the storage volume should not be defined by the image in glance, it should be defined by the falvour being started.

Comments

N2n P2p Vpn Wtf

First off what is n2n ?

n2n is a layer-two peer-to-peer virtual private network (VPN) which allows users to exploit features typical of P2P applications at network instead of application level. This means that users can gain native IP visibility (e.g. two PCs belonging to the same n2n network can ping each other) and be reachable with the same network IP address regardless of the network where they currently belong. In a nutshell, as OpenVPN moved SSL from application (e.g. used to implement the HTTPS protocol) to network protocol, n2n moves P2P from application to network level.

So why do I care ?

Some services you may wish to run on a public cloud such as Gluster do not have (at the time of writing) internal TLS (read: encryption), this n2n allows you to establish peer to peer vpn connections, wihtout the need of a single routing device (with some assume caveats I will cover shortly).

So in short you can have your own private network within the cloud environment without affecting that environment, this allows for:

  1. TLS for services otherwise sent “in the clear”
  2. Potential for Cluster services and floating IP’s without touching the host network infrastructure.

Installation

We are going to use EPEL, why? because I’m a packager and I will be using redhat for this setup, so admitedly I am a little biased toward RedHat, that said the majority of the following configurations should be portable to other distros, leave a commment if you get stuck I will try to help!

yum -y install n2n

And no I’m not using sudo i.m.o sudo is akin to “training wheels”, and somethign I will only generally use if I have too (such as maintaining an auditable system), you are of course welcome to use sudo yourself, I use “throw away” vm’s for all my experimentation so in these cases the ethos is if it’s broken it gets rebuilt.

SuperNode Setup

First thing’s first we’re going to need at least 1 Supernode, as I uderstand it a Supernode is used to register new peers and to retrieve currently connected peers. Once this list is retrieved the individual nodes will communicate directly (p2p), and not via the supernode.

Caveats to note:

  1. If all supernodes are down, only existing peers can communicate, new peers can not.

supernode whilst installed does not at the time of writing provide an init.d/sysvinit script, you may use the following:

place the above in /etc/init.d/supernode and chmod +x i.e.

curl -o /etc/init.d/supernode https://raw.github.com/gist/1986260/b66b38da265ea14aac8d0ef7196a9ba98939716c/supernode.sh && chmod +x /etc/init.d/supernode

(Though I really do recommend you read through this code first before trusting it blindly!)

Note: Annoyingly I had to use the -f (foreground) flag to allow the daemon wrapper to function correctly with this process, there is more than likely a better solution, please feel free to revise the gist it is public.

Now as I have opted to use a non existant n2n account to daemonize the process this will need creating as will the pid directory.

useradd -d /dev/null -s /sbin/nologin n2n
mkdir /var/run/supernode && chown n2n:n2n /var/run/supernode

You will now be able to start your supernode with: /etc/init.d/supernode start.

In my configuration above I have chosen to bind port 1200, you can change this to any port, but remember that your vpn peers will need to be able to access this port. As such you will need the relevant iptables rules

iptables -N N2N
iptables -I INPUT -j N2N
iptables -A N2N -s <vpn peer> -p udp --dport 1200 -j ACCEPT

I highly recomend you limit your firewall to only allow connection from known peers, and that this is done over the internal interface (for which you do not generally pay bandwidth charges).

I also recomend you repeat this process on a 2nd node to provide 2 Supernodes (The maximum allowable) for greater resilliance.

Edge Setup

I have opted for a .conf file approach here, you can of course opt to instead embed everything in the sysvinit script.

DEVICE="n0"
ADDRESS="127.16.0.1"
MAC="00:11:22:33:44:55"
COMMUNITY="N2N"
SHAREDKEY="asdf12345"
SUPER1="1.2.3.4:1200"
SUPER2="1.2.3.5:1200"
PORT="1201"

Place this in /etc/edge.conf, you can negate ADDRESS if you wish to use DHCP, whilst you can also Negate SUPERNODE2 and MAC I do not recomend doing so for the following reasons.

  1. Negating Supernode2 means there is only 1 supernode and as such a single point of failiure in the setup
  2. Negating MAC is valid, however on loss of connection and restoration a new MAC is generated meaning all existing nodes can not communicate with the restored node untill their local ARP caches are cleared, specifiying a static MAC address ensures immediate restoration of communication.
  3. I have made PORT a requirement, it is technically optional but fixing the port makes your iptables / firewall rules far easier.
  4. Make sure you actually edit the file and replace the args with VALID ones, especially the SHAREDKEY as the above is in no way secure!
  5. Make sure your ip and mac addresses are unique!

We need to prep the pid dir again:

mkdir /var/run/edge && chown n2n:n2n /var/run/edge

place the above in /etc/init.d/edge and chmod +x i.e.

curl -o /etc/init.d/edge https://raw.github.com/gist/1986260/3061d0fb9d6f2ddf1608f01917129d65b8131d33/edge.sh && chmod +x /etc/init.d/edge

(Again I HIGHLY recommend you actually read the code before blindly trusting it!)

Note: the –user option is negated in this init file. This is because we need to actually create a network interface, something that can only be done as root. As such we are reliant on the edge binary to drop privileges itself by providing the -u and -g arguments, these are of course assuming you have allready setup the n2n user, as per above and not just skipped to this section.

Add the Services and set them to run

chkconfig --add supernode
chkconfig --add edge
chkconfig supernode on
chkconfig edge on

Modify other services that are reliant on the VPN

Modify the “Requires” line in the sysvinit script for each service you want to only start once your VPN has been established.

...
# Required-Start: $local_fs $network $supernode $edge
...

Note: Whilst I have opted for requiring supernode here, you do not need this, you can require just your edge service, as the supernode does not have to run on the same device.

You should now be able to reboot and see all required services start up in the correct order.

And done, that’s where I am ending this blog post,

  1. we have setup n2n with supernodes and edge
  2. generated valid sysvinit scripts

expect future posts to cover more advanced n2n configuration as I discover the options available.

Comments

Wordpress to Octopress

So I have as some know been wrestling with Jekyll, and have sucessfully been porting my Wordpress posts to markdown.

Why you may ask? Performance!

To facilitate running wordpress on the smalest possible CloudServer I am using Varnish which using Apache as the backend, now with static files I can get all the blogging functionality without the need for Wordpress nor varnish, yet still uncached content can lead to increased load on the server.

Also wordpress does not lend itself to scalability especially with the at the time of writing schema and sql queries (percona-query-advisor flags up a few wordpress core sql queries as non scalable).

But this does not mean you need remove the option of using Wordpress, for you client for instance keeping wordpress in place can aid in content generation simply through ease of use.

  1. wordpress used as normal
  2. wordpress content is ported to markdown
  3. markdown used to generate html

Now this does have caveats:

  1. you’re going to need to maintain designs in wordpress templates and markdown (_layouts).
  2. you’re going to need to handel any shortcode plugins in your export process.
  3. you’re going to need to handel any other content modifying plugins in your export process.
  4. any UGC / Dynamic requests will still need PHP.

But it essentially replaces the whole caching layer with static content which then can be pushed to CDN.

And with CDN’s now supporting index files (S3, and Coming Soon @ CloudFiles) in essence entire sites can be placed on CDN whilst maintaining ease of content generation.

Now don’t get me wrong, this requires a whole lot of “glue” to get working, but the potential for serving an entire web app from CDN without Origin pull / cache headers etc, saves a lot of systems time in scaling and adressing performance issues, or rather makes them “less critical” as the “business” part of the webapp is all on CDN.

I’m still getting to grips with Jekyll and by extention Octopress to see what it can achieve, so expect more posts.