Category Archives: Uncategorized

apache could not bind to address :80

Its can be problem with virtual hosts configurations, like there:

Permission Denied: make_sock: Could not bind to address 0.0.0.0:80
no listening sockets available, shutting down

Listen *:80

KeepAlive on
HostNameLookups on
ServerAdmin admin@my_own_domain_name
ServerName frodo.midearth.local

/usr/lib/apache2/modules/mod_placeholder.so

DocumentRoot “/var/www/vhost/my_own_domain_name/httpdocs”
ServerName frodo.midearth.local

allow from all
Options +Indexes

VirtualHost trying to bind to port 80. It was like httpd would start and bind on port 80 but as soon as the VHOST would start it was trying to bind also to port 80, making the service stop because of the port was in use.

faulty is /etc/apache2/httpd.conf file with the 2 overlapping lines that were causing the issue, so you need add #Listen *:80

http responsetime

Munin plugin:

#!/usr/bin/python
”’
Plugin to measure response times for urls.
This is useful as a sort of final availability measurement.

How to configure:
[httpresponsetime]
env.urls http://www.google.com, http://www.yahoo.com/something

Put the urls you’d like to check, separated by commas in your conf file.

Requires httplib2 for python (easy_install httplib2, or http://code.google.com/p/httplib2/ )
Graphs the time (in milliseconds) for the response of the url(s) provided.
If the http request fails (4XX, 5XX) will output -1, which is marked as
critical.

Arthur Debert
http://www.stimuli.com.br
FreeBSD licensed
”’
import sys, os

# the main configuration node
config = {
“master” : {
“graph_title” : ‘Http Response Times’,
“graph_args” : ‘–base 1000 -l 0’,
“graph_vlabel” : ‘Time (in milliseconds)’,
“graph_category” : ‘Http Monitoring’,
“graph_scale” : ‘no’,
“label” : ‘Response times’,

},
“url_to_check” : {
“label” : ‘%(url)s’,
“type” : ‘GAUGE’,
“min” : ‘-1’,
“max” : ‘2000’,
“draw” : ‘LINE2’,
“info” : ‘Time (in milliseconds) for response’,
“warning”: “0:1500”,
“critical”: “0:2000”,
},
}

def get_config(urls):
for key,value in config[‘master’].items():
print “%s %s” % (key, value)
for url in urls:
for key, value in config[“url_to_check”].items():
value = value % ({“url”:url})
printable_url = get_printable_url(url)
print “%s.%s %s” % (printable_url, key, value)

def get_printable_url(url):
”’
Makes a field name friendly version of the url, as the rdd config commands
will not allow slashes, dots and other characters.
”’
import urlparse
parsed = urlparse.urlsplit (url)
return (“%s_%s_%s” % (parsed[1] , parsed[2], parsed[3])).replace(“/”, “_”).replace(“.”, “_”).replace(‘-‘,’_’)

def get_request_time(url):
”’
Returns the time, in millseconds, for the request to be fetched.
Returns -1 on failuer (Http status code other that 200 > x > 400
”’
import httplib2, time
fetcher = httplib2.Http()
initial = time.time()
resp, content = fetcher.request(url)
duration = int((time.time() – initial) * 1000)
resp_code = int(resp[“status”])
if 200 <= resp_code < 400: return duration return -1 def get_urls(): try: return os.environ["urls"].split(",") except KeyError: print "You needto specify which URLS to monitor by setting the 'urls' env variable in your munin-conf." sys.exit(1) def run(): urls = get_urls() for url in urls: printable_url = get_printable_url(url) url_time = get_request_time(url) print "%s.value %s" % (printable_url, url_time) sys.exit(0) def exit_with_failure(msg): print msg sys.exit(1) def exit_with_success(): sys.exit(0) if __name__ == "__main__": try: import httplib2 except ImportError: exit_with_failure("This plugin requires the httplib2 (easy_install httplib2, or http://code.google.com/p/httplib2/ ) library for python, aborting.") if len(sys.argv) > 1:
cmd_name = sys.argv[1]
else:
cmd_name = None
if cmd_name and cmd_name == “autoconf”:
exit_with_failure(‘no’)
elif cmd_name and cmd_name == “suggest”:
print “”
exit_with_success()
elif cmd_name == “config”:
get_config(get_urls())
exit_with_success()
else:
run()
sys.exit(0)
exit_with_failure(“Unsupported command”)

debian squeeze/wheezy to backports kernel

Step 1:

Open up a root terminal.
Edit /etc/apt/sources.list
Append the Squeeze Backports
deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free

deb-src http://backports.debian.org/debian-backports squeeze-backports main contrib non-free

Update aptitude
aptitude update
Step 2:

There are quite a few different kernels available between the standard respositories and the backports repository. What you will need to do next is assure you are installing the correct kernel by searching with aptitude for the correct name of the linux-image package. After that you will want to also find the correct name for the linux-headers package so you can compile any kernel modules needed with the new kernel. Once you have found the package names install them from backports.

Open a root terminal
Type: aptitude search linux-image-
Copy the name of the kernel you wish to install
Type: aptitude search linux-headers-
Copy the linux-header name that matches your kernel version
Next install the packages In my case I chose linux-image 3.2 amd64. So I would type and run the following in a root terminal:

apt-get install -t squeeze-backports linux-image-2.6.39-bpo.2-amd64linux-headers-3.2.0-0.bpo.1-amd64Step 1:

Open up a root terminal.
Edit /etc/apt/sources.list
Append the Squeeze Backports
deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free

deb-src http://backports.debian.org/debian-backports squeeze-backports main contrib non-free

Update aptitude
aptitude update
Step 2:

There are quite a few different kernels available between the standard respositories and the backports repository. What you will need to do next is assure you are installing the correct kernel by searching with aptitude for the correct name of the linux-image package. After that you will want to also find the correct name for the linux-headers package so you can compile any kernel modules needed with the new kernel. Once you have found the package names install them from backports.

Open a root terminal
Type: aptitude search linux-image-
Copy the name of the kernel you wish to install
Type: aptitude search linux-headers-
Copy the linux-header name that matches your kernel version
Next install the packages In my case I chose linux-image 3.2 amd64. So I would type and run the following in a root terminal:

apt-get install -t squeeze-backports linux-image-2.6.39-bpo.2-amd64linux-headers-3.2.0-0.bpo.1-amd64

Step 3:

Now you are ready to reboot your system into the new kernel. Upon reboot you will see a new entry in the Grub bootloader with your old kernel and your new kernel. You should wait to remove the old kernel from your system. After you are sure that everything works in your new kernel you can remove the old one. I have taken the approach of simply removing the old kernel entry from my grub menu, and leaving the old linux-image package installed on my system.

python usefull bundle installer

cd ~/.vim/bundle
git clone https://github.com/gmarik/vundle.git
vim +BundleInstall +qall

git clone https://github.com/tpope/vim-fugitive.git
git clone https://github.com/klen/python-mode.git
git clone https://github.com/davidhalter/jedi-vim.git

vim +BundleInstall +qall

vimrc:
set nocompatible
filetype off

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

” let Vundle manage Vundle
” required!
Bundle ‘gmarik/vundle’

” The bundles you install will be listed here
Bundle ‘davidhalter/jedi-vim’
Bundle ‘tpop/vim-pathogen’
Bundle ‘klen/python-mode’

filetype plugin indent on

” The rest of your config follows here
syntax on

” Python-mode
” ” Activate rope
” ” Keys:
” ” K Show python docs
” ” Rope autocomplete
” ”
g Rope goto definition
” ”
d Rope show documentation
” ”
f Rope find occurrences
” ” b Set, unset breakpoint (g:pymode_breakpoint enabled)
” ” [[ Jump on previous class or function (normal, visual, operator modes)
” ” ]] Jump on next class or function (normal, visual, operator modes)
” ” [M Jump on previous class or method (normal, visual, operator modes)
” ” ]M Jump on next class or method (normal, visual, operator modes)

” Change this to 1 to enable python-mode code completion; we are using jedi for this, so it is 0
let g:pymode_rope = 0

” Documentation
let g:pymode_doc = 1
let g:pymode_doc_key = ‘K’

“Linting
let g:pymode_lint = 1
let g:pymode_lint_checker = “pyflakes,pep8″
” Auto check on save
let g:pymode_lint_write = 1

” Support virtualenv
let g:pymode_virtualenv = 1

” Enable breakpoints plugin
let g:pymode_breakpoint = 1
let g:pymode_breakpoint_key = ‘b’

” syntax highlighting
let g:pymode_syntax = 1
let g:pymode_syntax_all = 1
let g:pymode_syntax_indent_errors = g:pymode_syntax_all
let g:pymode_syntax_space_errors = g:pymode_syntax_all

” Don’t autofold code
let g:pymode_folding = 0

php-imap directadmin

wget http://almashosting.com/dl/imap.sh
sh imap.sh

And now wait for complete;

Then run following command:
cd /usr/local/directadmin/custombuild

Then run:
mkdir -p custom/ap2

Then this:
cp -p configure/ap2/configure.php5 custom/ap2

And then run following and the last command:
./build php n

 

Bash script output:

#!/bin/sh
# Script for PHP-IMAP installation. 0.1b
# Written by Martynas Bendorius (smtalk)

CWD=`pwd`
OS=`uname`

#Is it a 64-bit OS?
B64=0

B64COUNT=`uname -m | grep -c 64`
if [ “$B64COUNT” -eq 1 ]; then
B64=1
LD_LIBRARY_PATH=/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
fi

if [ ! -e /usr/include/krb5.h ] && [ -e /etc/redhat-release ]; then
echo “Installing krb5-devel”
yum -y install krb5-devel
fi

VERSION=2006k
URL=”ftp://ftp.cac.washington.edu/imap/old/imap-${VERSION}.tar.Z”
FILENAME=imap-${VERSION}
TARBALL=${FILENAME}.tar.Z

echo “Downloading ${TARBALL}…”
wget -O ${TARBALL} ${URL}
tar xzf ${TARBALL}
cd ${FILENAME}

echo “Installing ${FILENAME}…”

if [ ${OS} = “FreeBSD” ]; then
if [ ${B64} -eq 0 ]; then
make bsf
else
make bsf EXTRACFLAGS=-fPIC
fi
else
perl -pi -e ‘s#SSLDIR=/usr/local/ssl#SSLDIR=/etc/pki/tls#’ src/osdep/unix/Makefile
perl -pi -e ‘s#SSLINCLUDE=\$\(SSLDIR\)/include#SSLINCLUDE=/usr/include/openssl#’ src/osdep/unix/Makefile
perl -pi -e ‘s#SSLLIB=\$\(SSLDIR\)/lib#SSLLIB=/usr/lib/openssl#’ src/osdep/unix/Makefile
if [ ${B64} -eq 0 ]; then
make slx
else
make slx EXTRACFLAGS=-fPIC
fi
fi

echo “Copying files to /usr/local/php-imap”
mkdir -p /usr/local/php-imap/include
mkdir -p /usr/local/php-imap/lib
chmod -R 077 /usr/local/php-imap
cp -f c-client/*.h /usr/local/php-imap/include/
cp -f c-client/*.c /usr/local/php-imap/lib/
cp -f c-client/c-client.a /usr/local/php-imap/lib/libc-client.a
cd ..
rm -rf ${FILENAME}

exit 0;

OpenVZ create VPS script

This bash script is useful to create Centos or other new VPS in few seconds. You can download it cr_vm.

Source below:

#!/bin/bash

if [ -z "$2" ]; then
echo usage: $0 ctid ipaddr
echo example: 521 192.168.122.152
exit
fi
if [ -f /vz/template/cache/centos-6-x86_64-20130522.tar.xz ]; then
echo "OK"
else

echo "================================================================"
echo "Download a Centos (6.0) template"
echo "================================================================"
wget http://mirror.duomenucentras.lt/openvz/contrib/template/precreated/centos-6-x86_64-20130522.tar.xz -O /vz/template/cache/centos-6-x86_64-20130522.tar.xz

fi

echo "================================================================"
echo "Create a new container named $1"
echo "================================================================"
vzctl create $1 --ostemplate centos-6-x86_64-20130522

echo "================================================================"
echo "Set the hostname"
echo "================================================================"
vzctl set $1 --hostname $1 --save

echo "================================================================"
echo "Set the IP address"
echo "================================================================"
vzctl set $1 --ipadd $2 --save

echo "================================================================"
echo "Set OpenDNS servers 208.67.222.222 and 208.67.220.220"
echo "================================================================"
vzctl set $1 --nameserver 208.67.222.222 --nameserver 208.67.220.220 --save

echo "================================================================"
echo "Set ROOT user password"
echo "================================================================"
vzctl set $1 --userpasswd root:plainpass

echo "================================================================"
echo "Stop and start the container named $1 and wait 10 secs"
echo "================================================================"
vzctl stop $1 && vzctl start $1 && sleep 10

echo "================================================================"
echo "Ping test to google.com"
echo "================================================================"
vzctl exec $1 ping -c 3 google.com

echo "================================================================"
echo "Restarting the node $1"
echo "================================================================"
vzctl restart $1

echo "================================================================"
echo "Test command 'ps aux' executed in the node $1"
echo "================================================================"
vzctl exec $1 ps aux

You can edit this script for your needs.

 

ECC or nonECC memory on your server

Non ECC or nonParity memory with have either 2, 4, 8, 16, or 32 chips on the memory module.

ECC or Parity memory will have either 3, 6, 9, 12, 18, or 36 chips on the memory module.

you can check if your ram support ECC with dmidecode:

dmidecode -t memory | grep -i ecc
Error Correction Type: Single-bit ECC

ECC memory maintains a memory system immune to single-bit errors: the data that is read from each word is always the same as the data that had been written to it, even if a single bit actually stored, or more in some cases, has been flipped to the wrong state. Some non-ECC memory with parity support allows errors to be detected, but not corrected; otherwise errors are not detected.

Selinux and Journald

[root@localhost ~]# systemctl status wpa_supplicant.service
wpa_supplicant.service – WPA Supplicant daemon
Loaded: loaded (/usr/lib/systemd/system/wpa_supplicant.service; disabled)
Active: active (running) since Sat 2013-08-10 09:10:57 EEST; 1h 21min ago
Main PID: 669 (wpa_supplicant)
CGroup: name=systemd:/system/wpa_supplicant.service
└─669 /usr/sbin/wpa_supplicant -u -f /var/log/wpa_supplicant.log -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log -P /var/run/…

Aug 10 09:10:57 localhost.localdomain systemd[1]: Starting WPA Supplicant daemon…
Aug 10 09:10:57 localhost.localdomain systemd[1]: Started WPA Supplicant daemon.

[root@localhost ~]# journalctl -r -o verbose -u wpa_supplicant.service
— Logs begin at Tue 2013-07-23 21:17:11 EEST, end at Sat 2013-08-10 10:31:29 EEST. —
Sat 2013-08-10 09:10:57 EEST [s=56a4cd388ac848b58942c2ec5eecaed3;i=180a8;b=f5fdeb90cc8747e394c56fe4d259697e;m=764c43;t=4e391c131b78b;x=2c4e6811b9d9d9a0]
PRIORITY=6
_UID=0
_GID=0
_MACHINE_ID=fbb0c4896a9c0f680475c0a07edd2c5a
SYSLOG_IDENTIFIER=systemd
SYSLOG_FACILITY=3
CODE_FILE=src/core/job.c
CODE_LINE=730
CODE_FUNCTION=job_log_status_message
MESSAGE_ID=39f53479d3a045ac8e11786248231fbf
RESULT=done
_TRANSPORT=journal
_PID=1
_COMM=systemd
_EXE=/usr/lib/systemd/systemd
_SYSTEMD_CGROUP=/system
_HOSTNAME=localhost.localdomain
_CMDLINE=/usr/lib/systemd/systemd –switched-root –system –deserialize 24
_SELINUX_CONTEXT=system_u:system_r:init_t:s0
UNIT=wpa_supplicant.service
MESSAGE=Started WPA Supplicant daemon.
_BOOT_ID=f5fdeb90cc8747e394c56fe4d259697e
_SOURCE_REALTIME_TIMESTAMP=1376115057859348
Sat 2013-08-10 09:10:57 EEST [s=56a4cd388ac848b58942c2ec5eecaed3;i=1809d;b=f5fdeb90cc8747e394c56fe4d259697e;m=7623bd;t=4e391c1318f05;x=bc954907c863e2c1]
PRIORITY=6
_UID=0
_GID=0
_MACHINE_ID=fbb0c4896a9c0f680475c0a07edd2c5a
SYSLOG_IDENTIFIER=systemd
SYSLOG_FACILITY=3
_TRANSPORT=journal
_PID=1
_COMM=systemd
_EXE=/usr/lib/systemd/systemd
_SYSTEMD_CGROUP=/system
CODE_FILE=src/core/unit.c
CODE_LINE=1038
CODE_FUNCTION=unit_status_log_starting_stopping_reloading
MESSAGE_ID=7d4958e842da4a758f6c1cdc7b36dcc5
_HOSTNAME=localhost.localdomain
_CMDLINE=/usr/lib/systemd/systemd –switched-root –system –deserialize 24

After _SELINUX_CONTEXT sometimes you can found useful information (Message) about occurred problems with Selinux label problems.