How To Install Ruby on Rails on Linux

Ruby on Rails is an application stack that provides developers with a framework to quickly create a variety of web applications.

sudo apt-get install curl
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm requirements
rvm install ruby
rvm use ruby --default
rvm rubygems current
gem install rails

SP sur un service de Backup dans le Cloud

Situation Professionnelle d’un service de Backup dans le Cloud

L’entreprise Lavin Estates à decider d’améliorer leur fasson de faire des sauvegardes de leur donnée. Actuellement il dispose de deux disques durs de sauvegarde de taille suffisante. Ils font une sauvegarde dans la même partition de tous les ordinateurs du bureau séparé par des dossiers avec le nom de la machine. Un des disques durs reste toujours dans le bureau, un deuxième est aportee tous les mois pour faire une copie exacte du disque dur de sauvegarde du bureau.

Cette façon de procéder est déjà très bonne comparer à d’autre entreprises de la même taille qui non même pas de sauvegarde delocalise et se sert de cle USB. On a tout même decider de rajouter une couche de sécurité qui serait transparente à l’entreprise. Avec l’apparition du Cloud, la façon de penser sur la sauvegarde de données est en train de changer radicalement, car elle offres des avantages qui ne peuvent pas etres négliger. Un des plus grands avantages est la flexibilité que ce service apporte, on peut y sauvegarder de quelque MB de données à plusieurs centaines de TB, tout dépend du tarif que l’entreprise est prête à payer. Un autre avantage c’est qu’on a plus besoin de se préoccuper de l’infrastructure, c’est-à-dire: l’achat de matériel, replacer du matériel defectue et la garantie du materiel.

L’entreprise a fait un achat d’un micro-serveur Windows home Serveur de HP le modèle MicroServer N40L avec le quel jais vérifier son bon fonctionnement avec des outils qui permet de faire du “stress teste” du processeur, vitesse de transfert, et disque dur. On a rajouté un SSD et on lui est fait faire la mise à jour du firmware, qui normalement permet une amélioration en stabilité de la fonction “TRIM”. On a ensuite remplacé le système d’exploitation par défaut par une distribution Linux appeler “Ubuntu”. Cette version du système d’exploitation Linux est très populaire ce qui la rend à notre opinion leader en stabilité, sécurité et performance. La communauté derrière Ubuntu est très grande ce qui rend la réparation des soucis qu’on risque de tomber plus simple à résoudre. Cette communauté met aussi à disposition des petits logiciels gratuitement sur internet dont tout le monde peut y profiter. Par exemple nous avons récupéré un script qui permet de se servir du logiciel Duplicity est de lui permettre de transférer ses données sur un serveur distant par le protocole S3 d’Amazon.

Amazon est une entreprise multinationale qui offre des services Cloud, elle est la plus grosse et offre un tarif competitive dans ce domaine. Un des services pour laquelle elle est la plus reconnue c’est son service de stockage.

Install OpenVPN TAP

This article will guide you in a basic OpenVPN installation on an Ubuntu server running 12.04 using a TAP device.

The TAP solution is useful if you want the remote VPN users to use the same IP scheme that is in use on the local subnet. Very useful if you don’t have a gateway/router in the local subnet that can do static routes since, to the internal hosts, the traffic will seem to originate from a locally connected device on the same subnet.

OpenVPN has a few methods of authentication. Out of the box, OpenVPN relies on certificate based auth. However, with a recompiled client, you can also use Id/password authentication as well providing 2 factor auth into your network (something you have = the cert, something you know= the password).

Before we begin, lets get the installation of the pre-reqs done.

apt-get install bridge-utils openvpn libssl-dev openssl

On the Ubuntu Server, we need to start by configuring the bridge adapter with Bridge Utilities. OpenVPN requires this ‘virtual interface’ when setting up the tap interface it needs to pass traffic into the internal network. This is done by modifying the interfaces file.

nano /etc/network/interfaces

When editing this file, you need to remove or comment out the original eth port settings and replace with what you see below. This creates a new br0 interface and allows eth0 to essentially communicate across it (hence the label ‘bridge’). You will, of course, adjust the file for your specific subnet scheme.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0

#iface eth0 inet static
# address 192.168.1.15
# netmask 255.255.255.0
# network 192.168.1.0
# broadcast 192.168.1.255
# gateway 192.168.1.1
# # dns-* options are implemented by the resolvconf package, if installed
# dns-nameservers 192.168.1.15
# dns-search myhome.local

auto br0
iface br0 inet static
address 192.168.1.15
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255
bridge_ports eth0
#### NOTE: If you are running OpenVPN in a virtual machine, then uncomment these lines:
# bridge_fd 9
# bridge_hello 2
# bridge_maxage 12
# bridge_stp off

iface eth0 inet manual
up ifconfig $IFACE 0.0.0.0 up
up ip link set $IFACE promisc on
down ip link set $IFACE promisc off
down ifconfig $IFACE down

Next, we need to allow IPv4 forwarding so the server can send out packets on the VPN’s behalf.

nano /etc/sysctl.conf
Uncomment the line net.ipv4.ip_forward=1

Restart networking and run ‘sysctl -p’ for the changes to take effect. Or just restart the server.

Create Server Keys
We need to create the server keys and client keys that we need for the OpenVPN server and the eventual client. Easy-RSA will be used to generate the items we need.

Create the easy-rsa folder and copy the sample files into it.

sudo mkdir /etc/openvpn/easy-rsa/
sudo cp -R /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa/
sudo chown -R $USER /etc/openvpn/easy-rsa/

Edit the vars file and edit the following items for your needs, located near the bottom

sudo nano /etc/openvpn/easy-rsa/vars

export KEY_COUNTRY=”US”
export KEY_PROVINCE=”NY”
export KEY_CITY=”New York City”
export KEY_ORG=”Queens”
export KEY_EMAIL=”me@myhost.mydomain”

Next step is to generate the Server Keys

cd /etc/openvpn/easy-rsa/
source vars
./clean-all
./build-dh
./pkitool –initca
./pkitool –server server
cd keys
openvpn –genkey –secret ta.key

Note: if you get an error on the command “./pkitool –initca”
grep: /etc/openvpn/easy-rsa/openssl.cnf: No such file or directory
pkitool: KEY_CONFIG (set by the ./vars script) is pointing to the wrong
version of openssl.cnf: /etc/openvpn/easy-rsa/openssl.cnf
The correct version should have a comment that says: easy-rsa version 2.x

Then you are hitting a known bug #998918 https://bugs.launchpad.net/ubuntu/+source/openvpn/+bug/998918

In a nutshell, openvpn easy-rsa is missing the openssl.cnf file in the package. As a workaround, create a softlink using the following:

cd /etc/openvpn/easy-rsa/
ln -s openssl-1.0.0.cnf openssl.cnf

Then rerun the command:

./pkitool –initca

Continue on from there.

Now copy certain keys to the openvpn directory

cp server.crt server.key ca.crt dh1024.pem ta.key /etc/openvpn/

Create Client Certificates

If you are using the default method of authentication, have a client cert per client, then you need to create the cert on the openvpn server for the client. This is done on the server, not on the client because the server’s CA needs to sign the key. Also, the client cert process will prompt you for a client cert password. You need to give this to the client along with the cert.

cd /etc/openvpn/easy-rsa/
source vars
./pkitool client-name

Those commands will create new files int the easy-rsa/keys directory called client-name.crt and client-name.key (client-name.csr is the text request and can be ignored/deleted). These 2 files need to be copied out the client, along with the server ca.crt and the ta.key (the ta.key is used if TLS is enabled in server conf).

/etc/openvpn/ca.crt
/etc/openvpn/ta.key
/etc/openvpn/easy-rsa/keys/client-name.crt
/etc/openvpn/easy-rsa/keys/client-name.key

These files need to be copied to the client and placed in the proper folder. For a linux client, this would usually be the /home/folder for the user. For windows based machines, this would be in the openvpn client install folder where the profiles are stored.

Create OpenVPN Server scripts

We need 2 scripts in the /etc/openvpn directory to manage bringing the server up and down.

/etc/openvpn/up.sh

#!/bin/sh
BR=$1
DEV=$2
MTU=$3
/sbin/ifconfig $DEV mtu $MTU promisc up
/sbin/brctl addif $BR $DEV

and /etc/openvpn/down.sh

#!/bin/sh
BR=$1
DEV=$2
/sbin/brctl delif $BR $DEV
/sbin/ifconfig $DEV down

Then we need to make the scripts executable:

sudo chmod 755 /etc/openvpn/down.sh
sudo chmod 755 /etc/openvpn/up.sh

Last step is to copy in the sample server config file and edit it to support our config. This sample is a default method using only certificates, but this could be changed to support id/pw instead of user certs (good for large subscription based services), or even 2 factor auth requiring both the cert and the password.

Also note that this config is a bridged network where the client will have an IP right on the target subnet. This sample server config reflects that solution. The Alternative is to create a 2nd subnet for the clients and have the server route between the vpn client and target subnet. For this home solution, that’s overkill, but would be useful in larger setups or where extra security is needed and the remote subnets can be used for access control.

cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
gzip -d /etc/openvpn/server.conf.gz
nano /etc/openvpn/server.conf

Edit the /etc/openvpn/server.conf file and make the following changes:

Change the following because we don’t want a routed solution.
;dev tap
dev tun

to
dev tap0
;dev tun

Change the following because bridged networks don’t need it.
server 10.8.0.0 255.255.255.0
to
;server 10.8.0.0 255.255.255.0

Change the following so OpenVPN can manage the bridged traffic ans assign IPs. (edit these to reflect your scheme).
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
to
server-bridge ‘server-ip’ ‘subnetmask’ ‘DHCP start ip’ ‘DHCP Ending ip’

Change this so the vpn clients have the correct GW router for all your IP traffic (edit these to reflect your scheme)
;push “route 192.168.10.0 255.255.255.0″
to
push “route 192.168.1.1 255.255.255.0″

Change this so all your client traffic passes through the VPN.
;push “redirect-gateway def1 bypass-dhcp”
to
push “redirect-gateway def1 bypass-dhcp”

Change these to 1 of your internal DNS servers if you have 1, otherwise use any public dns you want.
;push “dhcp-option DNS 208.67.222.222″
;push “dhcp-option DNS 208.67.220.220″
to
push “dhcp-option DNS 208.67.222.222″
push “dhcp-option DNS 208.67.220.220″

Change this to implement tls auth, without a proper file, the initial UDP communication is dropped. It also saves on processor time since it doesn’t have to service bad requests.
;tls-auth ta.key 0 # This file is secret
to
tls-auth ta.key 0 # This file is secret

Change the following to increase security so the VPN service has restricted access
;user nobody
;group nogroup
to
user nobody
group nogroup

Add this to the bottom of the file to manage starting and stopping the networking for VPN.
up “/etc/openvpn/up.sh br0″
down “/etc/openvpn/down.sh br0″
script-security 3

With that, you should be able to load the openvpn client, copy in the Ca and user certs and get a connection.

Remember the ta.key is used if ‘tls-auth’ is activated on the server.conf.

Install Linux DNS Server

This is a production ready DNS server installation procedure using DNSMasq:

 

 

This article gives you a step by step on installing bind9 to Ubuntu Server for dns resolution for an internal ‘local’ domain. This was done on Ubuntu 10.04 LTS 64 bit and also on 12.04 LTS 64 bit.   The zone ‘mydomain.local’ can be renamed to anything really.   I like to keep internal domains as ‘local’ on split dns so that there is a clear distinction between mydomain.com and mydomain.local addresses.  Internal subnet space used here is 192.168.1.0/255.255.255.0

Install Bind9 for DNS services

1) Run  apt-get install bind9

2) Create a zones folder “mkdir /etc/bind/zones”

3) Edit /etc/bind/named.conf.local

zone "mydomain.local" {
type master;
file “/etc/bind/zones/mydomain.local.db";
};

zone "1.168.192.in-addr.arpa" {
type master;
notify no;
file “/etc/bind/zones/rev-192.168.1.db";
};

4) Create the Zone files for mydomain.local. Replace ‘server1′ with your dns server name and adjust IP addresses as needed.

vim /etc/bind/zones/mydomain.local.db

 $ORIGIN .
 $TTL 604800     ; 1 week
 mydomain.local             IN SOA  server1.mydomain.local. admin.mydomain.local. (
 2011032909 ; serial
 604800     ; refresh (1 week)
 86400      ; retry (1 day)
 2419200    ; expire (4 weeks)
 604800     ; minimum (1 week)
 )

NS      server1.mydomain.local.
 $ORIGIN mydomain.local.
 server1                 A       192.168.1.10
 server2                 A       192.168.1.11
 gateway                A       192.168.1.1

5) Create the reverse Zone file vim /etc/bind/zones/rev-192.168.1.db

$ORIGIN .
 $TTL 604800     ; 1 week
 1.168.192.in-addr.arpa IN SOA  server1.mydomain.local. admin.mydomain.local. (
 2012080301 ; serial
 604800     ; refresh (1 week)
 86400      ; retry (1 day)
 2419200    ; expire (4 weeks)
 604800     ; minimum (1 week)
 )

NS      server1.
 $ORIGIN 1.168.192.in-addr.arpa.
 1                       PTR     gateway.mydomain.local.
 15                     PTR     server1.mydomain.local.
 245                   PTR     server2.mydomain.local.

6) Lastly don’t forget to add the forwarders by editing /etc/bind/named.conf.options

forwarders {
 208.67.222.222;
 208.67.220.220;
 };