venerdì 7 febbraio 2014

Proxmox playground - Part 1

Notes
I've decided to play a little bit with Proxmox, this web-interface cluster distro, that allows easly to migrate VM among nodes. Proxmox is basically based on Redhat Cluster. The Proxmox suite miss a tool for handling the cluster resources (at least I didn't find it); still, the container part is based on OpenVZ, outdated by LXC. Despite this, the worst thing now is the lack of the documentation for v3.0.

Scenario
I want to build a small dev environment where a new vm (I will use containers actually - CT) will be spawned by developers everytime they need one. Since the software set for those vm will be large (database, backend, general tools ..) I will create a CT template. The other machines thus, will be cloned from this one

Index
In this Proxmox experiment I will configure  in HA:

 1) a service IP, on which reaching the cluster
 2) a CT template, from where originate the CT clones
 4) a script for the CT creation/spawing automation

The document assumes that a 2nodes Proxmox "cluster", will be already setup and running. Briefly the setup here is
 * Cluster name: vicinet
 * Node01: 'proxmox' - 192.168.1.13
 * Node02: 'proxmox2' - 192.168.1.14
 * Storage: NFS /mnt/pve/shared on a separate node

Configure FENCING first
In order to proceed with any HA resource, we need to configure the fencing. Fencing is basically the procedure by which you exclude a node from the cluster in case of malfunction, sending to this latter a shutdown/reboot command. Such commands could be sent by Apc ups as well as an IPMI device and so on. The software which will trigger the device (ups, ipmi..) to send commands is called Agent

In the Redhat Cluster, the package 'fence-agent' will provides several fence agents that will probably cover your device too (apc, cisco, ibmblade .. but also
ipmi, ilo and many more). On Proxmox the package is called 'fence-agents-pve'

NOTE: Proxmox works with VMs (kvm) and Containers (OpenVZ). Since my experiment here was just to test the creation/automation of Linux Containers I could quietly setup Proxmox in VirtualBox

For my fencing setup, I found this fence_vbox; you can also find agents for vmware, virsh, in the case

Enable fencing on Debian on each node
Uncomment the last line of the file /etc/default/redhat-cluster-pve
# this file is sourced by the following init scripts:
# /etc/init.d/cpglockd
# /etc/init.d/cman
# /etc/init.d/rgmanager

FENCE_JOIN="yes"

reload these services in this order and *outside the /etc/pve directory*
/etc/init.d/rgmanager stop
/etc/init.d/cman reload
/etc/init.d/rgmanager start
/etc/init.d/pve-cluster restart

(I did an alias in .bashrc, like 'alias restart-cluster='...')

Test if the fencing was joined
proxmox:~# fence_tool ls
fence domain
member count  2
victim count  0
victim now    0
master nodeid 2
wait state    none
members       1 2

Edit the cluster.conf file with the proper procedure (cluster.conf.new ..) adding the fencing setup; I will just report mine, just to have an example:
<clusternodes>
    <clusternode name="proxmox" nodeid="1" votes="1">
      <fence>
        <method name="1">
          <device action="reboot" ipaddr="Proxmox" name="VBox"/>
        </method>
      </fence>
    </clusternode>
    <clusternode name="proxmox2" nodeid="2" votes="1">
      <fence>
        <method name="1">
          <device action="reboot" ipaddr="Proxmox2" name="VBox"/>
        </method>
      </fence>
    </clusternode>
  </clusternodes>

  <fencedevices>
    <fencedevice agent="fence_vbox" login="zmo" name="VBox" host="192.168.1.65"/>
  </fencedevices>

 * 'proxmox' 'proxmox2', are the hostnames of the proxmox nodes
 * 'Proxmox' 'Proxmox2', are the GUEST names in VirtualBox
 * 'VBox', names the fence configuration to use
 * '192.168.1.65', is the IP of the VirtualBox HOST

As said, this is just an example of fencing configuration in Proxmox; test and use your own agent and values

Add a cluster IP
This will be the cluster IP, that will migrate between node in case of fails. Configure this migration pattern, writing a first <failoverdomain> section

<rm>
  <failoverdomains>
      <failoverdomain name="vicinet" ordered="1" restricted="0">
        <failoverdomainnode name="proxmox" priority="1"/>
        <failoverdomainnode name="proxmox2" priority="2"/>
      </failoverdomain>
  </failoverdomains>
</rm>

A resource assigned to this failoverdomain, will have 'proxmox' as preferred node and in case proxmox get failed will be migrate on 'proxmox2'. So, a brief explanation
 * ordered: assign a preference order for the resource by priority (1=max, 100=min)
 * restricted: the resource could not migrate (or even started manually) if the nodes defined are not available. We turn 'restricted' off (0)

Add the IP configuration:

<rm>
  <failoverdomains>
      <failoverdomain name="vicinet" ordered="1" restricted="0">
        <failoverdomainnode name="proxmox" priority="1"/>
        <failoverdomainnode name="proxmox2" priority="2"/>
      </failoverdomain>
  </failoverdomains>
  <resources>
      <ip address="192.168.1.100" monitor_link="5"/>
  </resources>
  <service autostart="1" domain="vicinet" name="ip_cluster" recovery="relocate">
      <ip ref="192.168.1.100"/>
  </service>
</rm>

 * monitor_link is just a monitor for the link state, just for that ip
 * relocate means that the service will move on automatically on the preferred node ('proxmox' in this case) when, for example, this will be back online from a down
 * autostart, the service is started by the cluster itself

Reload the cluster and see that you have a new resource on your cluster (use clustat
Cluster Status for vicinet @ Sun Dec 29 10:54:32 2013
Member Status: Quorate

 Member Name             ID      Status
 ------ ----             ----    -----
 proxmox                 1       Online, Local, rgmanager
 proxmox2                2       Online, rgmanager

 Service Name            Owner (Last)          State         
 ------- ----            ----- ------          -----         
 service:ip_cluster      proxmox               started

Also see the new interface on the node proxmox (use 'ip tools' and not 'ifconfig')

3: vmbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN 
    link/ether 01:E0:27:29:3e:fc brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.13/24 brd 192.168.1.255 scope global vmbr0
    inet 192.168.1.100/24 scope global secondary
 






lunedì 28 ottobre 2013

Log4j syslogAppender and Rsyslog

This is how I workarounded an annoying situation, working with log4j.syslogAppender (the syslog module from the Java logging library) and Rsyslog togheter, in order to sends Tomcat logs to a remote log analyzer (Splunk, on the same machine with Rsyslog), that understands 'log4j' format

The article is just meant to show some Rsyslog hacks

Of course, I noticed the problem from the log analyzer, which wasn't working because of the confused log format. So firstly, I wanted to have a look how the logs were cominig to Rsyslog

To show all the fields, I've enabled the RSYSLOG_DebugFormat, next to the entry in /etc/rsyslog.conf
local1.info /var/log/log_analyzer/application.log;RSYSLOG_DebugFormat
This the awfull result:
Debug line with all properties:
FROMHOST: 'localhost', fromhost-ip: '127.0.0.1', HOSTNAME: '2013-10-25', PRI: 142,
syslogtag '19:', programname: '19', APP-NAME: '19', PROCID: '', MSGID: '-',
TIMESTAMP: 'Oct 25 19:38:51', STRUCTURED-DATA: '-',
msg: '38:51,915 INFO
As shown, those fields are totally messed up (HOSTNAME: '2013-10-25', MSGID: '-' ..) The reasons behind this "unmatching" log4j/rsyslog fields, could be either a misconfiguration log4j side (don't ask me where since the configuration is minimal) or the broken syslogAppender module. Reading on the web I was convincing myself much for the latter

So, my decision at the moment is to bypass as much as I can, the Rsyslog handling of those logs in order to store the logs exactly as they come from log4j

These are the steps

1 - Let's define a custom template
Rsyslog has its default template, so for first we need to setup a custom template (Log4j, which basically will avoid any formatting for our logs) and make it point to our "local1.info" entry
$template Log4j, "%rawmsg%\n"
local1.info /var/log/log_analyzer/application.log;Log4j
2 - Turn the control character escaping off
With %rawmsg%, our logs will look like this
<142>2013-10-25 20:20:53,862 INFO  ["http-80"] org.apache.cxf.interceptor: Inbound Message#012Content-Type: xxx#012Headers: xxx
As we can see the string has many #012 in the middle. This represents a form feed control character. The default global option in Rsyslog is meant to escape the control characters, so let's disable it
$EscapeControlCharactersOnReceive off
Verify the Rsyslog configuration
lurch~# rsyslogd -N1
...
rsyslogd: Warning: backward compatibility layer added to following directive to rsyslog.conf: ModLoad imuxsock
rsyslogd: End of config validation run. Bye.
And restart the service
lurch~# service rsyslog restart 
Let's have a look to log again
<142>2013-10-25 20:20:53,862 INFO  ["http-80"] org.apache.cxf.interceptor: Inbound Message
Content-Type: xxx
Headers: xxx
Much better but

3 - Remove some chars from the string
Our string still begins with a <142>. This is the PRIO value in Rsyslog. Since the message is a RAW message, I assume that the PRIO is sent directly from log4j, so it wont be possible to play with Rsyslog fields, in order to remove it
So I decide to cut off the first characters in the string(<142>), in the template definition
$template Log4j, "%rawmsg:6:$%\n"
Finally:
2013-10-25 20:20:53,862 INFO  ["http-80"] org.apache.cxf.interceptor: Inbound Message
Content-Type: xxx
Headers: xxx

domenica 10 marzo 2013

LXC and cgroup.memory on Debian

Two days ago on Lurch, I was trying to show/set a memory limit for a container (LXC), using "lxc-cgroup -n <container> memory.limit_in_bytes"

Unfortunately, I got the message "lxc-cgroup: missing cgroup subsystem", that I've firstly intended as "I couldn't mount this cgroup at this session"

Briefly, asking about memory cgroup to LXC, everything was ok


while asking to linux not


Another confusing point to me, was the check of the dmesg output, that showed memory cgroup between the others

So, after a little of googling, I have understood like, the memory cgroup  is just not enabled on Debian by default. That because having the cgroup.memory enabled, costs around 15Mb of ram, that is obviously a waste if you don't use that cgroup

In order to have the availability of said cgroup, you need to instruct the Grub by /etc/default/grub with the boot parameter cgroup_enable=memory

The amount of memory reserved to the cgroup nos is printed out during the boot time
In the end I could set my cgroup memory limit

sabato 9 marzo 2013

Pxe with Dnsmasq

Just a couple of words..

For a much too long period of my life I have always manually changed the "pxelinux" entry in the "dnsmasq.d/domain.conf" file, to achieve the boot with this and with that image depending to the needed install distro

I just have finally found a way to serve each pxe images in one shot and even with a confortable menu list

That is accomplished adding something like:
Needless to say that you could even make point each pxe entry to a different tftp servers

mercoledì 2 gennaio 2013

VirtualBox port-forwarding

Today on my Munich-Florence train, I've waisted some time just trying some ways for "sshing" my puppet VirtualBox guest. Usually DHCPclient does everything and, once the ip address is got by the guest, I can easily "ssh" into it. This time, I had not a wifi connection and I've encoutered some annoying bounces on my ssh attempts. It looked like the guest was unreachable. I've instinctively tried every "nat", "bridged", "host-only" options.. and in the end .. it touched me to read the documentation :) (by the way, a very good paper) 

..and it was so i've discovered this official best practice to port-forward services on a VirtualBox guest

In this example (exactly extracted from the doc), we are going to portforwarding the SSH service, from our HOST 8888 port, to the GUEST (vm name: "Puppet Test Machine") on 22 port:

"sshService" is just a label.

In this way, our HOST will keep the forward on each interfaces. Anyway, it's possible to bind a specific interface though.

Now that we have our forward ready, we can connect the loopback on the given port
This rule will be permanet unless you explicitly remove it. See the rule properties:
Then delete the rule:

sabato 17 novembre 2012

Python-stdeb

This is what i've done, to make a shiny python library of mine becomes a fully respectable deb package. Move in your python directory, where everything has been started and create your setup.py file, more or less like this sample:
So, in your directory you list:
Create the stdeb configuration file stdeb.cfg
This file will write parameters in the soon generated DEBIAN/control file. A complete list of the parameters translation is here: http://pypi.python.org/pypi/stdeb#stdeb-cfg-configuration-file
Given that, build your package with:
NOTE: It will compile the package with mypylib-"version"; the version is the one written in setup.py (version="")

enjoy your deb_dist directory.

Mikrotik (winbox): VLAN and bridge

The other day i needed to add a new wifi access point in a new place in our building. Our network, like many others, is partitioned in VLANs. We have almost a dedicated VLAN for any different network segment.

Our best practice, where permitted, is to keep access points as untouched as possible, working the VLANs on the management switches. This develop a better/centralized net control to us. However this time the location was linked to the rest of the infrastructure by a non-management switch.



The "Port 40" is just where the trunk from the unlucky zone, ends on the management switch.

So, since the NON-management switch could not collaborate with us, we are forced to tag the VLAN traffic on the AP itself.



In this article we will start from the default Mikrotik configuration up to achieve our new Bridge for the new VLAN. The only stuff we have already configured, is the switch port (in our case the number 40) marked as tagged with VID 6. Im obviously referring to the management switch.
note: I assume you already have a server for this VLAN (dhcp server and so on ..)
otherwise: http://www.cyberciti.biz/tips/howto-configure-linux-virtual-local-area-network-vlan.html

Let's start opening winbox which allow us to connect the mikrotik through the proper mac address, avoiding lost of connection playing around bridge, VLANs ..

~$ wine winbox.exe



Create the new VLAN interface which will be tied to the master-local port on the router



Why master-local port?

The master-local port on the routerboard is the collection of the slave ports, then i act on that to give the same address (vid 6) for both wireless and every wire connections

Once the VLAN interface is created, move to the "Bridge" tab and close the existing one (bridge-local), by clicking "disable" (the red "X")



.. i've forgot .. this VLAN is basically for guests, so the new bridge will be named "bridge-guest". Open "Bridge" tab and add that:



Move in the near tab "Ports". Double click on "master-local" and replace the "interface" field with the VLAN interface "guest" and the "bridge" field with the just bridge-guest



Configure "wlan1" interface replacing the field "bridge" from ''bridge_local'' to ''bridge_guest''; then go to "IP/DHCP Client". If everything goes ok, you will be able to get an ip address from your server on the other side. When on the tab, click on "+" and in the "Interface" field, choose "bridge-guest". Click ok and



thats all.

lunedì 10 settembre 2012

D-link switches and .. "martians packets" ??

Device: Dlink DGS-1224T
Firmware: 4.21.01
IP addr: 10.2.2.8

I have a VLAN interface on my linux router built on eth2 with VID 6

eth2 = 10.2.2
eth2.6 = 10.6.6 (VLAN)

This VLAN is configured on my Dlink switch as well with untagged VLAN ports. My Dlink management interface is set on 10.2.2

Since we use shorewall as iptables interface, we have found this on syslog:

Sep 10 10:03:56 lurch kernel: [2651431.667008] martian source 10.2.2.1 from 10.2.2.8, on dev eth2.6
Sep 10 10:03:56 lurch kernel: [2651431.667011] ll header: ff:ff:ff:ff:ff:ff:00:15:63:45:05:c5:08:04


Martians ??

A possible explanation:
Packets with 10.2.2 as source reach the Dlink management interface on 10.2.2.8 (for management or just a nagios ping); as reply, the Dlink perform an ARP request like "Who has 10.2.2.x" on every ports, even on the VLAN 10.6.6 ones. As result, the Linux kernel see those 10.2.2 source packets on its eth2.6 interface and complains consequently.

A possible fixaround:
Force Dlink management interface being reachable from one network only, in my case 10.2.2, on "Configuration/802.1Q Management VLAN" tab.

giovedì 6 settembre 2012

Nagios: check_http with --extra-opts

We have to check a https page which needs a login.

We want to store our login informations in a nagios only-readable file.

root@lurch:~# touch /etc/nagios/private/custom.ini
root@lurch:~# chown root.nagios /etc/nagios/private/custom.ini
root@lurch:~# chmod 640 /etc/nagios/private/custom.ini


In this example Im going to create an [https] section which includes the credentials for my login web page. This file, which will be passed to --extra-opts= plugin argument, could contains all the options listed by ./check_http -h command in the literally form. For instance:

./check_http -h
...
-a, --authorization=AUTH_PAIR
Username:password on sites with basic authentication
...

Then:

root@lurch:~# su - nagios
nagios@lurch:~$ vim /etc/nagios/private/custom.ini


[https]
authorization = *user*:*password*


Let's write the 'commands' section. I want to call this command like 'check_https_auth'

nagios@lurch:~$ vim /etc/nagios/objects/commands.cfg


# zmo: check_https_auth
define command{
command_name check_https_auth
command_line $USER1$/check_http -H $ARG1$ -I $HOSTADDRESS$ -s $ARG2$ --ssl -c $ARG3$ -u $ARG4$ --extra-opts=https@/etc/nagios/private/custom.ini
}

mercoledì 29 agosto 2012

Nagios: check remote hosts via SSH with command validation


Nagios server: Fedora release 16 (Verne)
Nagios remote node: Debian GNU/Linux testing (wheezy)


Basic SSH Configuration
Let's allow the access from the nagios server to the nagios node creating a ssh key passphrase-less:

zmo@nagiosSer:~$ cd .ssh/
zmo@nagiosSer:~/.ssh$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/zmo/.ssh/id_dsa): nagios
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in nagios.
Your public key has been saved in nagios.pub.
The key fingerprint is:
....

.. so that you will have nagios and nagios.pub from the others

zmo@nagiosSer:~/.ssh$ ls
id_rsa id_rsa.pub nagios nagios.pub

On the remote node create the nagios user and the necessary file

root@nagiosNod:~# adduser nagios
Adding user `nagios' ...
Adding new group `nagios' (1006) ...
Adding new user `nagios' (1006) with group `nagios' ...
...
Enter new UNIX password: xxxxxxxx
Retype new UNIX password: xxxxxxxx
...
root@nagiosNod:~# su - nagios
nagios@nagiosNod:~$ mkdir .ssh
nagios@nagiosNod:~$ touch .ssh/authorized_keys


Paste your pub key, from the nagios server, into the remote nagios authorized_keys file


zmo@nagiosSer:~/.ssh$ cat nagios.pub | ssh nagios@nagiosNod.remote.com 'cat >> /home/nagios/.ssh/authorized_keys'
nagios@nagiosNod.remote.com's password: xxxxxxxx


Have a try

zmo@nagiosSer:~$ ssh -i .ssh/nagios nagios@nagiosNod
Last login: Tue Aug 28 20:44:54 2012 from nagiosSer
nagios@nagiosNod:~$



On the nagios server


root@nagiosSer:~# yum install nagios-plugins-by_ssh.i686


On the nagios remote node
Install the nagios plugins

root@nagiosNod:~# apt-get install nagios-plugins-basic


NOTE: you can find where the plugins have been stored by

root@nagiosNod:~# dpkg -L nagios-plugins-basic
...
/usr/lib/nagios/plugins/check_apt
/usr/lib/nagios/plugins/check_tcp
/usr/lib/nagios/plugins/check_dummy
/usr/lib/nagios/plugins/check_ntp
/usr/lib/nagios/plugins/check_nwstat
/usr/lib/nagios/plugins/check_load
/usr/lib/nagios/plugins/check_procs
...


On the nagios server
Let's write a SSH config file

root@nagiosSer:~# cd /etc/nagios
root@nagiosSer:~/etc/nagios# vim check_by_ssh_config


Host nagiosNod 84.68.x.x
User nagios
Hostname nagiosNod.remote.com
IdentityFile /home/zmo/.ssh/nagios

This file will be passed as ssh configuration to check_by_ssh. You can obviously add others hosts.

Configure the commands.cfg

root@nagiosSer:~/etc/nagios# vim objects/commands.cfg


# Check Remote Disk
define command {
command_name check_remote_disk
command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -F /etc/nagios/check_by_ssh_config -C "/usr/lib/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$"
}

A little explanation:
* $USER$ - the user which nagios run (nagios)
* $HOSTADDRESS$ - the numeric IP address definied in the server configuration file (/etc/nagios/objects/nagiosNod.cfg), mapped on "address" field
* -F /etc/nagios/check_by_ssh_config - The SSH configuration file previously written
* -C /usr/lib/nagios/.. - The command will execute on the remote node

Its better (not mandatory) to put that services in a different group. So, open /etc/nagios/objects/templates.cfg (or services.cfg) and append:

# Remote service
define service{
name remote-service
use generic-service
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
register 0
}


Now in /etc/nagios/objects/nagiosNod.cfg file we could append:

define service {
use remote-service
host_name nagiosNod
service_description Home Partition
check_command check_remote_disk!20%!10%!/home
}


SSH validation
This step is for allow just the check_* commands execution from the nagios server on the nagios nod; not other commands, not a login or whatever else.

Create a validation commands file:

nagios@nagiosNod:~# touch /usr/local/bin/validate-nagios-check
nagios@nagiosNod:~# chown nagios.nagios /usr/local/bin/validate-nagios-check
nagios@nagiosNod:~# su - nagios
nagios@nagiosNod:~$ vim /usr/local/bin/validate-nagios-check
#!/bin/sh
# Ensure
case "$SSH_ORIGINAL_COMMAND" in
*\&*)
echo "Rejected"
;;
*\;*)
echo "Rejected"
;;
/usr/lib/nagios/plugins/check_*)
exec $SSH_ORIGINAL_COMMAND
;;
*)
echo "Rejected"
;;
esac

A little explanation: $SSH_ORIGINAL_COMMAND is our /usr/lib/nagios/plugins/check_* . Using exec here, will prevent to open a shell for the command execution but just to exec the command.

Let's back to our authorized_keys. We have to append in the beginnin of the key definition (ssh-dss or ssh-rsa) the string to execute our validate-nagios-check script from the nagios server.

nagios@nagiosNod:~$ vim .ssh/authorized_keys
from="73.224.x.x",command="/usr/local/bin/validate-nagios-check"
ssh-dss AAAAB3NzaC1kc3MAAACBAKK3jM9O+cmjPufrn9Ie7q+iJJu+1B0bHH6lhfYC8KandEIWP0gMGz4v...
...


You can test the validation script from the nagios server to the node.

root@nagiosSer:~# ssh -i /home/nagios/.ssh/nagios nagios@nagiosNod.remote.com
Rejected
Connection to nagiosNod.remote.com closed.
root@nagiosSer:~# ssh -i /home/nagios/.ssh/nagios nagios@nagiosNod.remote.com /bin/ls
Rejected
root@nagiosSer:~# ssh -i /home/nagios/.ssh/nagios nagios@nagiosNod.remote.com /usr/lib/nagios/plugins/check_http -hcheck_http v1.4.16 (nagios-plugins 1.4.16)
Copyright (c) 1999 Ethan Galstad
Copyright (c) 1999-2011 Nagios Plugin Development Team
...

mercoledì 22 agosto 2012

Dnsmasq and the network "pushing" on CentOS

This simple post shows you how tu push networks to your clients using the Dnsmasq DHCP server.

A possible scenario would be, your DHCP server (192.168.0.1) gives you 192.168.0.x address but you also need to reach 172.16.x.x and 10.0.x x networks, for access to (for instance) some VPN resources in your LAN. Those networks are NOT handled by your DHCP server. The quick solution is to make your DHCP server "pushing" that networks. And that is possibile thanks to "121" dhcp-option.

Let's assume our network id may be "vicinet" (you can also miss the network id, of course):


dhcp-option = vicinet, 121, 10.0.0.0/16, 192.16.0.1, 172.16.0.0/16, 192.168.0.1



The format will always be:


dhcp-option = 'id_net', 121, NETWORK, GATEWAY

martedì 21 agosto 2012

Shorewall and Pptp VPN on Ubuntu



~# apt-get install shorewall linux-pptp


PPP
Let's create a ppp peer file:


~# vim /etc/ppp/peers/zmo


I ve successfully tried these options


# Zmo PPTP VPN configuration
remotename zmo
linkname zmo
ipparam zmo
pty "pptp 149.79.X.X --nolaunchpppd" (remote VPN endpoint)
name username
require-mppe-128
refuse-eap
noauth
lock
noauth
refuse-pap
refuse-eap
refuse-chap
refuse-mschap
nobsdcomp
nodeflate
persist
mtu 1400
mru 1400



Compile the chap-secret file


# Secrets for authentication using CHAP
# client server secret IP addresses
username zmo 2023n5t-w0re *



Network Interface
Fill the /etc/network/interfaces file. You can use the "unit x" parameter. This blessy option allows you to enumerate your ppp device (like ppp0, ppp1, ppp5 ..).


# Zmo Pptp VPN
auto ppp5
iface ppp5 inet ppp
provider zmo
unit 5



Try to get up the link, just giving


~# ifup ppp5



I raccomand to use this file (/etc/network/interfaces) even in the case you wanna add some route/net rules to your VPN device. Use the "post-up" options here.


# Zmo Pptp VPN
auto ppp5
iface ppp5 inet ppp
provider zmo
unit 5
post-up /sbin/route add 149.88.X.X gw 149.19.X.X
post-up /sbin/route add -net 150.84.X.X netmask 255.255.255.0 gw 150.84.X.X



Shorewall
Define a zone for the vpn on shorewall. I will define "zmo"


~# vim /etc/shorewall/interfaces


It should be looks like:


# For information about entries in this file, type "man shorewall-interfaces"
###############################################################################
#ZONE INTERFACE BROADCAST OPTIONS
wan eth0 detect tcpflags,nosmurfs,routefilter,logmartians,dhcp
dmz eth1 detect tcpflags,nosmurfs,routefilter,logmartians,dhcp
lan eth2 detect tcpflags,nosmurfs,routefilter,logmartians,dhcp
# VPN pptp
zmo ppp5 detect tcpflags,nosmurfs,routefilter,logmartians



Allow the vpn to be reached just by the lan


~# vim /etc/shorewall/policy



...
# Zmo Pptp VPN
lan zmo ACCEPT
all zmo REJECT
...


Masquerade the VPN traffic from that interface:


~# vim /etc/shorewall/masq



# For information about entries in this file, type "man shorewall-masq"
##############################################################################
#INTERFACE SOURCE ADDRESS PROTO PORT(S) IPSEC MARK
ppp5 - -


NOTE: an IP wont be needed here; shorewall will be masquerade the traffic with the interface IP address. Then we just can put a "-" in SOURCE/ADDRESS fields. The IP address would be needed if you would masquerade the traffic with a different IP address.

In the end, compile the "tunnels" shorewall file. You can retrieve a tunnels template file from the doc


~# cp /usr/share/doc/shorewall/default-config/tunnels /etc/shorewall



It should be looks like:


###############################################################################
#TYPE ZONE GATEWAY GATEWAY
# ZONE
pptpclient zmo 0.0.0.0/0

lunedì 25 giugno 2012

Convert HG to Git repository






On Ubuntu:


~# ls
repository.hg
~# apt-get install hg-fast-export
~# git init new_repository.git



~# ls
repository.hg new_repository.git
~# cd new_repository.git
~/new_repository.git# hg-fast-export -r ../repository.hg



You will recieve a summary text in the end, like


git-fast-import statistics:
---------------------------------------------------------------------
Alloc'd objects: 5000
Total objects: 478 ( 14 duplicates )
blobs : 133 ( 14 duplicates 54 deltas of 133 attempts)
trees : 216 ( 0 duplicates 194 deltas of 196 attempts)
commits: 129 ( 0 duplicates 0 deltas of 0 attempts)
tags : 0 ( 0 duplicates 0 deltas of 0 attempts)
Total branches: 4 ( 1 loads )
marks: 1024 ( 129 unique )
atoms: 16
Memory total: 2344 KiB
pools: 2110 KiB
objects: 234 KiB
---------------------------------------------------------------------
pack_report: getpagesize() = 4096
pack_report: core.packedGitWindowSize = 1073741824
pack_report: core.packedGitLimit = 8589934592
pack_report: pack_used_ctr = 901
pack_report: pack_mmap_calls = 215
pack_report: pack_open_windows = 1 / 1
pack_report: pack_mapped = 331971 / 331971
---------------------------------------------------------------------


In the end do:


~/new_repository.git# git checkout HEAD



Test your repo with git log.

giovedì 14 giugno 2012

Migrate PhpBB3 on Ubuntu server

PhpBB version: 3.0.9
Backend: Mysql
Mode: Fcgi



Dump the database

ubuntu~# mysqldump -u root -p phpbb3 > /tmp/phpbb3.sql


On the new machine

new~# apt-get update && apt-get install phpbb3


During the installation, choose to configure mysql/phpbb3 via debconf and answer about passwords in this order
* Mysql root password
* Phpbb3 database password
* Phpbb3 admin interface password

Afterwords, setup the web server. You have a configuration example in /etc/phpbb3/apache2.conf; you can directly copy this file in your /etc/apache2/sites-available directory and run

new:/etc/phpbb3# cp apache2.conf /etc/apache2/sites-available/phpbb3
new:/etc/phpbb3# cd /etc/apache2/sites-available/
new:/etc/apache2/sites-available# a2ensite phpbb3 && service apache2 reload


Try to login and surf the admin interface (APC). If you had a custom theme in the previous server, do the follow:

ubuntu~# scp -r /srv/phpbb3/theme/ (or wherever it is) new:/usr/share/phpbb3/styles


Important , make a sym link in /etc/phpbb3/styles directory to make phpbb see the custom theme

new~# cd /etc/phpbb3/styles
new:/etc/phpbb3/styles# ln -s /usr/share/phpbb3/styles/theme theme


Once the link is ok, configure the new theme in the APC (administrative panel)

If everything seems to be fine, move on and restore the database

new~# mysql -u root -p phpbb3 < phpbb3.sql


Configure FCGI

new~# apt-get install php5-cgi
new~# cd /etc/apache2/
new:/etc/apache2/# a2dismod php5
new:/etc/apache2/# service apache2 restart


Setup fcgi environment

new~# cd /srv (or wherever you'll locate it)
new:/srv# mkdir php-fcgi
new:/srv# cd (alt+.)
new:/srv/php-fcgi# ls
phpbb.fcgi
phpbbrc -> /etc/php5/cgi/


phpbb.fcgi

#!/bin/sh
PHP_FCGI_MAX_REQUESTS=10000
PHP_FCGI_CHILDREN=0
export PHPRC=/srv/php-fcgi/php53rc
export PHP_FCGI_MAX_REQUESTS PHP_FCGI_CHILDREN
# Replace with the path to your FastCGI-enabled PHP executable
exec /usr/bin/php-cgi


NOTE: phpbbrc is a link to /etc/php5/cgi/ directory

The virtualhost section should be something like

<VirtualHost *:80>
    ServerName forum.example.org
    DocumentRoot /usr/share/phpbb3/www
    ErrorLog /var/log/apache2/forum_error.log
    CustomLog /var/log/apache2/forum_access.log combined
    Alias / /usr/share/phpbb3/www/

   <Directory>
      Order allow,deny
      Allow from all
      Options +ExecCGI
      AddHandler fcgid-script .php
      FcgidWrapper /srv/php-fcgi/phpbb.fcgi .php
   </Directory>
</VirtualHost>



Try to load a forum page and check with

new~# ps ax | grep cg[i]
2248 ? S 0:00 /usr/bin/php-cgi


that php-cgi is running ..

domenica 15 gennaio 2012

Handle voip customers with Siproxd on CentOS 5.7



Install Libosip2


cd /usr/local/src
wget http://www.antisip.com/download/exosip2/libosip2-3.5.0.tar.gz
tar xvf libosip2-3.5.0.tar.gz
yum install gcc
cd libosip2-3.5.0
./configure
make
make install
ll /usr/local/lib



Create a new file in /etc/ld.conf.d


echo "/usr/local/lib" > /etc/ld.conf.d/local.conf
ldconfig



Install Siproxd


cd /usr/local/src
wget http://sourceforge.net/projects/siproxd/files/siproxd/0.8.1/siproxd-0.8.1.tar.gz/download
tar xvf siproxd-0.8.1.tar.gz
cd siproxd-0.8.1/
./configure --with-libosip-prefix=/usr/local/lib
make
make install



Do this:


yum remove gcc

Create siproxd user:


useradd -c "Siproxd user" -r -s /bin/nologin siproxd

Basic Siproxd configuration:


vim /etc/siproxd_customer-name.conf


if_inbound = eth0
if_outbound = eth0


sip_listen_port = 5070
daemonize = 0
silence_log = 1
user = siproxd


hosts_allow_reg = 11.22.33.44/16


registration_file = /var/lib/siproxd/siproxd_registrations
autosave_registrations = 300
pid_file = /var/run/siproxd/siproxd.pid


outbound_proxy_host = voip.provider.example.com
outbound_proxy_port = 5060


rtp_proxy_enable = 0
rtp_port_low = 27000
rtp_port_high = 27100
rtp_timeout = 300
rtp_dscp = 46
sip_dscp = 0
rtp_input_dejitter = 0
rtp_output_dejitter = 0
tcp_timeout = 600
tcp_connect_timeout = 500
tcp_keepalive = 20


debug_level = 0x00000000
debug_port = 0

Start siproxd:


/usr/local/sbin/siproxd

Some explanations:
if_inbound/if_outbound - It's the same interface (eth0) because we just have one
hosts_allow_reg - Put here your customer IP (if he has a static one) with the right mask (/16, /24..); you can calculate the mask using a subnet calculator (http://www.subnet-calculator.com)
rtp_proxy_enable = 0 - We just want to proxy the signaling protocol (SIP) not the audio stream (RTP)
outbound_proxy_host - Put here the customer voip provider that you want to connect to

Before setup asterisk, try siproxd configuration using a softphone such as twinkle, ekiga.. It's better a softphone which includes a "Outbound Proxy" field. Twinkle does the trick.

Twinkle example configuration_
User Tab:
User name* = user ID for voip.provider.example.com
Domain* = user ID for voip.provider.example.com
Authentication Name = password for voip.provider.example.com

SIP server Tab:
check on Use Outbound Proxy
Outbound Proxy = your.siproxd.server:5070

If something goes wrong revisit you siproxd configuration running siproxd in debug mode:


/usr/local/sbin/siproxd -c /etc/siproxd_customer-name.conf -d -1 2

NOTE: do different "/etc/siproxd_customer-name.conf" files to give to each siproxd instance you need.


Asterisk trunk configuration
(on the customer PBX)


contact="user ID for voip.provider.example.com"
context=from-trunk
fromuser="user ID for voip.provider.example.com"
outboundproxy="your.siproxd.server:5070"
type=peer
nat=never
host="your.siproxd.server"
port=5070
insecure=very
secret="password for voip.provider.example.com"
username="user ID for voip.provider.example.com"

NOTE: i'm currently still testing this setup. It works pretty fine, but i cant hide some weird behavior with asterisk trunk. For instance, it's easy encounter a voip congestion placing 2 calls one after another. Using siproxd directly with twinkle doesn't. Given this, the trunk works. Any tips will be appreciate

giovedì 22 dicembre 2011

Upgrade apt-cacher-ng on Fedora 15

Get the last version of apt-cacher:


cd /usr/src
wget http://ftp.debian.org/debian/pool/main/a/apt-cacher-ng/apt-cacher-ng_x.x.x.orig.tar.xz
tar xvf apt-cacher-ng_x.x.x.orig.tar.xz


Compile it:


cd /usr/src/apt-cacher-ng_last_release
make
(if something goes wrong or missing, do a 'make clean' and retype 'make')
cp /usr/local/sbin/apt-cacher-ng /usr/lcoal/sbin/back_apt-cacher-ng
cp build/apt-cacher-ng /usr/local/sbin/
cp build/in.acng /usr/local/sbin



Integrate all missing file from the sources/conf directory to your /etc/apt-cacher-ng (dont overwrite acng.conf)


cp archlx_mirrors backends_debian.default backends_ubuntu.default cygwin_mirrors delconfirm.html epel_mirrors fedora_mirrors maint.html security.conf report.html sfnet_mirrors sl_mirrors style.css ubuntu_mirrors userinfo.html /etc/apt-cacher-ng


Test everything is working restarting the service:


/etc/init.d/apt-cacher-ng restart


Test the maintenance page to:

http://your_apt-cacher_server:3142/acng-report.html



CONFIGURE YUM FOR RETRIEVE PACKAGES FROM THE CACHER


sudo vim /etc/yum.conf
...
# ZMo: apt-cacher for yum
proxy=http://your_apt-cacher_server:3142
...

lunedì 28 novembre 2011

OpenERP 6 on Fedora 15

postgresql installation


[fedora@lovelock ~]$ sudo yum install postgresql-server postgresql-libs postgresql



Initialize postgresql db and start the daemon:


[fedora@lovelock ~]$ /etc/init.d/postgresql initdb
Initializing database:                                     [  OK  ]
[fedora@lovelock ~]$ /etc/init.d/postgresql start
Starting postgresql (via systemctl):                       [  OK  ]



postgresql user
Become postgres and create the db user:


[fedora@lovelock]$ su - postgres
-bash-4.2$ createuser openerp
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n



openerp user and environment
Create openerp system user and give a him a password:


[fedora@lovelock]$ sudo adduser --system openerp
[fedora@lovelock]$ sudo passwd openerp
Changing password for user openerp.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.



Create the OpenERP release directory:


[fedora@lovelock]$ su openerp -c mkdir /home/openerp/6



setup and test the server
Download the server tarball and unpack it:


[fedora@lovelock]$ su - openerp
[openerp@lovelock]$ cd 6
[openerp@lovelock]$ wget http://www.openerp.com/download/stable/source/openerp-server-6.0.0.tar.gz
[openerp@lovelock]$ tar xvf openerp-server-6.0.0.tar.gz


Install dependencies for the server:


[fedora@lovelock]$ sudo yum install python-lxml.i686 python-mako python-dateutil python-psycopg2 pychart pydot pytz python-vobject python-reportlab PyYAML python-imaging




NOTE: to generally test openerp releases, you don't need to perform a complete installation. Inside the /bin directory, in the untarred openerp archive, you can run "opnenerp-server.py". Running openerp-server.py will also notify you for every missing dependence.



[openerp@lovelock]$ cd openerp-server-6.0.0/bin
[openerp@lovelock]$ ./openerp-server.py"
...
[2011-11-18 17:07:43,573][?] INFO:server:OpenERP version - 6.0.0
[2011-11-18 17:07:43,574][?] INFO:server:addons_path - /home/openerp/6/openerp-server-6.0.0/bin/addons
[2011-11-18 17:07:43,575][?] INFO:server:database hostname - localhost
[2011-11-18 17:07:43,576][?] INFO:server:database port - 5432
[2011-11-18 17:07:43,577][?] INFO:server:database user - openerp
[2011-11-18 17:07:43,578][?] INFO:server:initialising distributed objects services
[2011-11-18 17:07:43,940][?] INFO:web-services:starting HTTP service at 0.0.0.0 port 8069
[2011-11-18 17:07:43,944][?] INFO:web-services:starting HTTPS service at 0.0.0.0 port 8071
[2011-11-18 17:07:43,946][?] INFO:web-services:Registered XML-RPC over HTTP
[2011-11-18 17:07:43,948][?] INFO:web-services:starting NET-RPC service at 0.0.0.0 port 8070
[2011-11-18 17:07:43,950][?] INFO:server:Starting 3 services
[2011-11-18 17:07:43,952][?] INFO:server:OpenERP server is running, waiting for connections...



..ctrl+c to exit the test.

install the server


[fedora@lovelock]$ su - root
[root@lovelock]# yum install python-setuptools
[root@lovelock]# cd /home/openerp/6/openerp-server-6.0.0
[root@lovelock]# python setup.py install
...
copying doc/migrate/3.4.0-4.0.0/post-tiny.py -> /usr/share/doc/openerp-server-6.0.0/migrate/3.4.0-4.0.0
running install_egg_info
Copying openerp_server.egg-info to /usr/lib/python2.7/site-packages/openerp_server-6.0.0-py2.7.egg-info
running install_scripts
copying build/scripts-2.7/openerp-server -> /usr/bin
changing mode of /usr/bin/openerp-server to 755
[root@lovelock]#



Copy the configuration file for the server:


[root@lovelock]# cp doc/openerp-server.conf /etc/openerp-server.cfg
[root@lovelock]# chown openerp.openerp /etc/openerp-server.cfg



setup and test the client
Install client dependencies:


[fedora@lovelock]$ sudo yum install python-lxml.i686 python-mako python-dateutil python-psycopg2 pychart pydot pytz python-vobject python-reportlab PyYAML python-imaging pygtk2 glade2 python-matplotlib python-dateutil pytz pydot hippo-canvas-python mx-devel python-imaging


Download openerp-client tarball and untar it:


[fedora@lovelock]$ su - openerp
[openerp@lovelock]$ cd 6
[openerp@lovelock]$ wget http://www.openerp.com/download/stable/source/openerp-client-6.0.0.tar.gz
[openerp@lovelock]$ tar xvf openerp-client-6.0.0.tar.gz



Test openerp-client:


[openerp@lovelock]$ cd openerp-client-6.0.0/bin
[openerp@lovelock]$ python openerp-client.py



install the client


[fedora@lovelock]$ su - root
[root@lovelock]# cd /home/openerp/6/openerp-client-6.0.0
[root@lovelock]# python setup.py install



setup and test openerp-web
OpenERP-web dependencies:


yum install python-cherrypy python-formencode python-babel



Download OpenERP-web tarball and unpack it:


[fedora@lovelock]$ su - openerp
[openerp@lovelock]$ cd 6
[openerp@lovelock]$ wget http://www.openerp.com/download/stable/source/openerp-web-6.0.0.tar.gz
[openerp@lovelock]$ tar xvf openerp-web-6.0.0.tar.gz



Run OpenERP-web:


[openerp@lovelock]$ cd openerp-web-6.0.0
[openerp@lovelock]$ python openerp-web.py
[21/Nov/2011:05:12:44] ENGINE Bus STARTING
[21/Nov/2011:05:12:44] ENGINE Started monitor thread '_TimeoutMonitor'.
[21/Nov/2011:05:12:44] ENGINE Started monitor thread 'Autoreloader'.
[21/Nov/2011:05:12:44] ENGINE Serving on 0.0.0.0:8080
[21/Nov/2011:05:12:44] ENGINE Bus STARTED



install openerp-web


[openerp@lovelock]$ su - root
[root@lovelock]# cd /home/openerp/6/openerp-web-6.0.0
[root@lovelock]# python setup.py install
...
Using /usr/lib/python2.7/site-packages
Finished processing dependencies for openerp-web==6.0.0



Put the openerp-web configuration file in /etc:


[root@lovelock]# cp doc/openerp-web.cfg /etc
[root@lovelock]# chown openerp.openerp /etc/openerp-web.cfg



Uncomment log section:


[root@lovelock]# vim /etc/openerp-web.cfg
change:
...
#log.access_file = "/var/log/openerp-web/access.log"
#log.error_file = "/var/log/openerp-web/error.log"
...
to:
...
log.access_file = "/var/log/openerp-web/access.log"
log.error_file = "/var/log/openerp-web/error.log"
...



Create openerp log files dir:


[root@lovelock]# mkdir /var/log/openerp-web
[root@lovelock]# chown openerp.openerp /var/log/openerp-web



init scripts
I've found these scripts on-line, optimized for CentOS Linux, so thanks to the author for avoid me to rewrite both from scratch. I've made few modifications there, and now they works on Fedora.

Put these files in /etc/init.d/ directory and give "x" permissions to the both.

Download (right mouse click and "Save link as..."):


openerp-server
openerp-web




[root@lovelock]# cd /etc/init.d/
[root@lovelock]# wget http://www.simoneroselli.eu/files/2011/11/openerp-server.txt
[root@lovelock]# wget http://www.simoneroselli.eu/files/2011/11/openerp-web.txt



[root@lovelock]# mv openerp-server.txt openerp-server
[root@lovelock]# mv openerp-web.txt openerp-web



[root@lovelock]# chmod +x openerp-*



Make pid directory for the daemons:


[root@lovelock]# mkdir /var/run/openerp
[root@lovelock]# chown openerp.openerp /var/run/openerp



Start the daemons


[root@lovelock]# /etc/init.d/openerp-server start
[root@lovelock]# /etc/init.d/openerp-web start