Gentoo

How To: Getting Started with Amazon EC2

By | BSD, CentoOS, Debian, DragonFlyBSD, FreeBSD, Gentoo, Linux | 2 Comments

Así.. sin valium y sin nada:

Amazon EC2 is among the more potent items in Amazon's web services arsenal. You've probably heard of many of the other services such as S3 for storage and FPS for payments. EC2 is all about the "elastic compute cloud." In layman's terms, it's a server. In slightly less layman's terms, EC2 lets you easily run and manage many instances (like servers) and given the proper software and configurations, have a scalable platform for your web application, outsource resource-intensive tasks to EC2 or for whatever you would use a server farm.

There are three different sizes of EC2 instances you can summon and they're all probably more powerful than the server currently running your blog. Unless you're offloading video processing or something intense to EC2, the default small instance with its 1.7GB of RAM and 160GB disk should be more than fine. It's just nice to know that if for any reason I need a farm of machines each with 15GB of RAM, I can get that easily.

EC2 has been around for a while but has gained interest in the last few weeks as Amazon released an elastic IP feature. One of the larger EC2 issues deals with data persistence on instances. There are many limitations with EC2 that make it difficult to use unless you carefully build around the EC2 architecture and don't just assume that you can move your app to EC2 flawlessly. If an instance crashes and you run it again, you'll loose data and when the instance comes back up it will have a new IP, adding another hurdle with DNS issues. Fortunately, the elastic IP feature lets you assign a static IP address to your instances.

As the title of this article implies, this article is meant to be a beginner's look into tinkering with EC2. Just because you will be able to host a page on EC2 at the end of this article does not mean you should start using it as your only server. Many considerations need to be made when using EC2 to get around the data persistence issue. If your startup is looking to use EC2 as a scalable platform, fortunately there are many services that have already built stable systems on top of EC2, ready for your consumption: WeoCeo, Scalr and RightScale. Enough talk, shall we jump right in?

Note: Most of the information below (and more) is available in the EC2 API doc if you enjoy reading those things.

Read More

iptables TIP

By | CentoOS, Debian, Gentoo, Linux, Red Hat, SuSE, Ubuntu | One Comment

Necesitamos que un equipo tenga acceso a toda la red corporativa y a si mismo, pero no al 'resto del mundo'.

#!/bin/bash
iptables -F
iptables -X
iptables -Z

# abrimos trafico a la red interna

iptables -A INPUT -s 127.0.0.0/8 -j ACCEPT
iptables -A OUTPUT -s 127.0.0.0/8 -j ACCEPT
iptables -A INPUT -s 10.120.0.0/16 -j ACCEPT
iptables -A INPUT -s 10.120.0.0/16 -j ACCEPT

iptables -A OUTPUT -d ! 10.120.0.0/16 -j DROP

grep

By | BSD, Debian, DragonFlyBSD, FreeBSD, Gentoo, Linux, OpenBSD, SuSE, Ubuntu | No Comments

pspipegrep-copia.pngWhat does ‘grep’ mean?

 

The Wikipedia entry for grep states:

grep is a command line utility originally written for use with the Unix operating system.

The name comes from a command in the Unix text editor ed that takes the form:

g/re/p

This means “search globally for matches to the regular expression re, and print lines where they are found”.

Simple como deben ser las utilidades

Instalación de LVM2 en Gentoo

By | Gentoo, Linux | No Comments
Contenido:

1. Introducción

Esta guía está basada en un ejemplo que usa dos discos duros IDE. Significa que probablemente tendrá que cambiar el disco, los nombres y los tamaños de las particiones según su configuración y sus propias necesidades.

Aviso:
No es la intención que este documento sea un tutorial de LVM2. Servirá como información suplementaria al procedimiento de instalación de Gentoo, tal como se describe en la Parte 1 del Manual. Asegúrese de leer el Manual de Instalación antes de comenzar el proceso de instalación.

Nota:
Para un HOWTO completo acerca de LVM, navegue a
http://tldp.org/HOWTO/LVM-HOWTO.

Requisitos iniciales

Si va a hacer una instalación desde cero, hará falta usar un CD del cual pueda arrancar que soporte LVM2, tal como el CD de Instalación Gentoo. Puede encontrar el CD de Instalación para la plataforma x86 en nuestros servidores espejo bajo /releases/x86/current/installcd. Tal vez estén soportadas otras plataformas también.

Si instala LVM2 en un sistema existente con espacio de sobra en disco duro, habrá que activar el módulo LVM2 (dm-mod). Este módulo está disponible en las fuentes gentoo-sources. La compilación del núcleo y el hacer funcionar a LVM2 serán cubiertos más adelante en esta misma guía.

Read More

logrotate!!

By | Gentoo, Linux | No Comments

logrotate.pngSi un día ves que el log de tu máquina se ha comido 10^6 hamburguesas, talvez sería bueno instalar logrotate.

Esto suele pasar en sistemas Gentoo, cuando has ido a toda mecha instalando un sistema, por aquello de las prisas y los presupuestos.

Pero claro que en el, nunca bien ponderado, handbook lo pone:

Si está pensando utilizar sysklogd o syslog-ng quizá quiera instalar posteriormente logrotate ya que esos logeadores no proporcionan ningún mecanismo de rotación para los archivos de log.

Así que:

# emerge -av logrotate

Un dato anecdótico es que tiene Copyright de Red Hat, Inc.

tratatrá ~ # logrotate -v
logrotate 3.7.1 - Copyright (C) 1995-2001 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License

Algunos ficheros de configuración y la ruta del mismo para información:

# cat /etc/logrotate.d/syslog-ng

/var/log/messages {
    rotate 7
    weekly
    size 50M
    sharedscripts
    postrotate
        /etc/init.d/syslog-ng reload > /dev/null 2>&1 || true
    endscript
}

/var/log/syslog {
    rotate 7
    weekly
    size 50M
    sharedscripts
    postrotate
        /etc/init.d/syslog-ng reload > /dev/null 2>&1 || true
    endscript
}

/var/log/debug {
    rotate 7
    weekly
    size 50M
    sharedscripts
    postrotate
        /etc/init.d/syslog-ng reload > /dev/null 2>&1 || true
    endscript
}

Para forzar el rotado de logs ejecuta esta instrucción:

# logrotate -f /etc/logrotate.conf

Más informacion en: http://gentoo-wiki.com/HOWTO_Setup_Logrotate

Observando si un paquete esta en la rama inestable o no

By | Gentoo, Linux | No Comments

Aveces necesitamos saber si un paquete está o no en la rama inestable de gentoo, aunque éste esté enmascarado en /etc/portage/packages.keywords.

Para ello disponemos de este pequeño script que nos hará la vida más fácil.

#!/bin/bash
# vim: set sw=4 sts=4 et tw=80 :

# Author:        Ciaran McCreesh 
# Purpose:       Display ebuild keywords in a graphical form
# Invocation:    eshowkw [ packagename ] (defaults to current directory if no
#                packagename is provided)

shopt -s extglob

PID_TO_KILL=$$

die() {
    echo "$@" 1>&2
    kill $PID_TO_KILL
}

trap 'exit 250' 15

get_portage_dir() {
    local dir
    if  -z ${portage_dir_cache}  ; then
        for dir in "${HOME}/cvs/gentoo-x86" "/usr/portage" ; do
             -d ${dir}/profiles  && portage_dir_cache=${dir} && break
        done
    fi
     -z ${portage_dir_cache}  && portage_dir_cache=$(portageq portdir )
    export portage_dir_cache
    echo ${portage_dir_cache}
}

version_sort() {
    local items= left=0
    items=( $@ )

    while [[ ${left} -lt ${#items[@]} ]] ; do
        local lowest_idx=${left}
        local idx=$(( ${lowest_idx} + 1 ))
        while [[ ${idx} -lt ${#items[@]} ]] ; do
            version_compare "${items[${lowest_idx}]}" "${items[${idx}]}"
             $? -eq 3  && lowest_idx=${idx}
            idx=$(( ${idx} + 1 ))
        done
        local tmp=${items[${lowest_idx}]}
        items[${lowest_idx}]=${items[${left}]}
        items[${left}]=${tmp}
        left=$(( ${left} + 1 ))
    done
    echo ${items[@]}
}

version_compare() {
    local ver_a=${1} ver_b=${2} parts_a parts_b cur_idx_a=0 cur_idx_b=0
    parts_a=( $(get_all_version_components "${ver_a}" ) )
    parts_b=( $(get_all_version_components "${ver_b}" ) )

    ### compare number parts.
    local inf_loop=0
    while true ; do
        # grab the current number components
        local cur_tok_a=${parts_a[${cur_idx_a}]}
        local cur_tok_b=${parts_b[${cur_idx_b}]}

        # number?
        if  -n ${cur_tok_a}  && [[ -z ${cur_tok_a//:digit:} ]] ; then
            cur_idx_a=$(( ${cur_idx_a} + 1 ))
            [[ ${parts_a[${cur_idx_a}]} == "." ]] \
                && cur_idx_a=$(( ${cur_idx_a} + 1 ))
        else
            cur_tok_a=""
        fi

        if  -n ${cur_tok_b}  && [[ -z ${cur_tok_b//:digit:} ]] ; then
            cur_idx_b=$(( ${cur_idx_b} + 1 ))
            [[ ${parts_b[${cur_idx_b}]} == "." ]] \
                && cur_idx_b=$(( ${cur_idx_b} + 1 ))
        else
            cur_tok_b=""
        fi

        # done with number components?
         -z ${cur_tok_a}  &&  -z ${cur_tok_b}  && break

        # to avoid going into octal mode, strip any leading zeros. otherwise
        # bash will throw a hissy fit on versions like 6.3.068.
        cur_tok_a=${cur_tok_a##+(0)}
        cur_tok_b=${cur_tok_b##+(0)}

        # if a component is blank, make it zero.
         -z ${cur_tok_a}  && cur_tok_a=0
         -z ${cur_tok_b}  && cur_tok_b=0

        # compare
         ${cur_tok_a} -lt ${cur_tok_b}  && return 1
         ${cur_tok_a} -gt ${cur_tok_b}  && return 3
    done

    ### number parts equal. compare letter parts.
    local letter_a=
    letter_a=${parts_a[${cur_idx_a}]}
    if  ${#letter_a} -eq 1  && [[ -z ${letter_a/[a-z]} ]] ; then
        cur_idx_a=$(( ${cur_idx_a} + 1 ))
    else
        letter_a="@"
    fi

    local letter_b=
    letter_b=${parts_b[${cur_idx_b}]}
    if  ${#letter_b} -eq 1  && [[ -z ${letter_b/[a-z]} ]] ; then
        cur_idx_b=$(( ${cur_idx_b} + 1 ))
    else
        letter_b="@"
    fi

    # compare
     ${letter_a} < ${letter_b}  && return 1
     ${letter_a} > ${letter_b}  && return 3

    ### letter parts equal. compare suffixes in order.
    local suffix rule part r_lt r_gt
    for rule in "alpha=1" "beta=1" "pre=1" "rc=1" "p=3" "r=3" ; do
        suffix=${rule%%=*}
        r_lt=${rule##*=}
         ${r_lt} -eq 1  && r_gt=3 || r_gt=1

        local suffix_a=
        for part in ${parts_a[@]} ; do
             ${part#${suffix}} != ${part}  && \
                [[ -z ${part##${suffix}*(:digit:)} ]] && \
                suffix_a=${part#${suffix}}0
        done

        local suffix_b=
        for part in ${parts_b[@]} ; do
             ${part#${suffix}} != ${part}  && \
                [[ -z ${part##${suffix}*(:digit:)} ]] && \
                suffix_b=${part#${suffix}}0
        done

         -z ${suffix_a}  &&  -z ${suffix_b}  && continue

         -z ${suffix_a}  && return ${r_gt}
         -z ${suffix_b}  && return ${r_lt}

        # avoid octal problems
        suffix_a=${suffix_a##+(0)} ; suffix_a=${suffix_a:-0}
        suffix_b=${suffix_b##+(0)} ; suffix_b=${suffix_b:-0}

         ${suffix_a} -lt ${suffix_b}  && return 1
         ${suffix_a} -gt ${suffix_b}  && return 3
    done

    ### no differences.
    return 2
}

get_all_version_components() {
    local ver_str=${1} result result_idx=0
    result=( )

    while  -n "$ver_str"  ; do
        case "${ver_str:0:1}" in
            # number: parse whilst we have a number
            :digit:)
                result[$result_idx]="${ver_str%%[^[:digit:]]*}"
                ver_str="${ver_str##+(:digit:)}"
                result_idx=$(($result_idx + 1))
                ;;

            # separator: single character
            [-_.])
                result[$result_idx]="${ver_str:0:1}"
                ver_str="${ver_str:1}"
                result_idx=$(($result_idx + 1))
                ;;

            # letter: grab the letters plus any following numbers
            :alpha:)
                local not_match="${ver_str##+(:alpha:)*(:digit:)}"
                result[$result_idx]=${ver_str:0:$((${#ver_str} - ${#not_match}))}
                ver_str="${not_match}"
                result_idx=$(($result_idx + 1))
                ;;

            # huh?
            *)
                result[$result_idx]="${ver_str:0:1}"
                ver_str="${ver_str:1}"
                result_idx=$(($result_idx + 1))
                ;;
        esac
    done

    echo ${result[@]}
}

get_package_dir() {
    if  -z ${1}  ; then
        pwd
        return 0
    fi

    if  -d ${1}  ; then
        readlink -f ${1}
        return 0
    fi

    get_portage_dir 1>/dev/null
    if  ${1/\/} != ${1}  ; then
        local d=$(get_portage_dir )/${1}
        if  -d ${d}  ; then
            echo ${d}
            return 0
        fi
    else
        local d
        d=( $(echo $(get_portage_dir )/*-*/${1} ) )
        if [[ ${#d[@]} -gt 1 ]] ; then
            die "${1} is ambiguous"
        elif [[ -d ${d[0]} ]] ; then
            echo ${d[0]}
            return 0
        fi
    fi

    return 1
}

repeat() {
    local i
    for (( i=0 ; i < ${1} ; i=$(( ${i} + 1 )) )) ; do
        echo -n "${2}"
    done
}

get_keywords() {
    (
        inherit() { :; }
        source ${1} 2>/dev/null
        echo ${KEYWORDS}
    )
}

colorarch() {
    case "${1}" in
        amd64)
            echo -n -e "\033[0;33m${2}\033[0;0m"
            ;;
        x86)
            echo -n -e "\033[0;31m${2}\033[0;0m"
            ;;
        *)
            echo -n "${2}"
            ;;
    esac
}

colourise() {
    case "${1}" in
        \*)
            echo -n -e "\033[0;31m*\033[0;0m"
            ;;
        +)
            echo -n -e "\033[0;32m+\033[0;0m"
            ;;
        -)
            echo -n -e "\033[0;31m-\033[0;0m"
            ;;
        \~)
            echo -n -e "\033[0;33m~\033[0;0m"
            ;;
        *)
            echo -n "${1}"
            ;;
    esac
}

show_keyword_diagram() {
    echo -n -e "Keywords for \033[1;34m"
    local title=$(readlink -f $(pwd ) )
    title=${title#$(readlink -f ../.. )/*( )}
    echo -n "${title}"
    echo -e "\033[0;0m:"
    echo

    local archs= arch_length=0 arch=
    archs=( $(< $(get_portage_dir )/profiles/arch.list ) )
    for arch in "${archs[@]}" ; do
         ${#arch} -gt ${arch_length}  && arch_length=${#arch}
    done

    local versions= pkgname= version_length=0 version=
    pkgname=$(basename $(readlink -f ./ ) )
    versions=( $(for e in $(echo *.ebuild ) ; do \
             -f ${e}  && echo ${e} | sed -e 's/\.ebuild$//g' \
                    -e "s/^${pkgname}-//g" ; \
            done ) )
    versions=( $(version_sort ${versions[@]} ) )
    for version in "${versions[@]}" ; do
         ${#version} -gt ${version_length}  && version_length=${#version}
    done

    local i=0 archletter=
    for (( i = 0 ; i < ${arch_length} ; i=$(( ${i} + 1 )) )) ; do
        repeat ${version_length} " "
        echo -n " | "
        for arch in "${archs[@]}" ; do
            archletter="${arch:${i}:1}"
            echo -n "$(colorarch "${arch}" "${archletter:- }" ) "
        done
        echo
    done

    repeat ${version_length} "-"
    echo -n "-+"
    repeat ${#archs[@]} "--"
    echo

    for version in "${versions[@]}" ; do
        echo -n "${version}"
        repeat $(( ${version_length} - ${#version} )) " "
        echo -n " | "

        local keyword keywords
        keywords=( $(get_keywords "${pkgname}-${version}.ebuild" ) )
        for arch in "${archs[@]}" ; do
            local display=" "
            [[ ${keywords[@]/-\*} != ${keywords[@]} ]] && display="*"
            for keyword in "${keywords[@]}" ; do
                [[ ${arch} == "${keyword#[~-]}" ]] && \
                    display=${keyword:0:1} && \
                    break;
            done
            [[ -z ${display#[~ *-]} ]] || display="+"
            echo -n "$(colourise "${display}" ) "
        done

        echo
    done
}

main() {
    local dir=$(get_package_dir "${1}" )
     -z ${dir}  && die "Couldn't find '${1}'"
    cd ${dir}
     $(echo *.ebuild ) != "*.ebuild"  || die "No ebuilds in ${dir}"
    show_keyword_diagram
    true
}

main "$@"

En el caso de que no se encuentre en la ubicación original he hecho un micro mirror de la versión de fecha de hoy:

eshowkw

screenshot-07_01_2008-11_35_19_ver001.png

Slàinte!