Monthly Archives: August 2013

unhandled error code result hostbyte=did_bad_target driverbyte=driver_ok

If you see this kind of error and something like “sd 0:0:0:0: [sda] Unhandled error code” in your dmesg output. it means its something wrong with your sata device port and you should reset ad re-scan it.

Also it means your linux system don’t see that device and you can’t use it.  This problem can occurs when you are trying to replace bad  disk in RAID array.

readlink /sys/block/sda

echo 1 > /sys/block/sda/device/delete

echo “- – -” > /sys/class/scsi_host/host1/scan

Now you can add your sda, also you can try other sata port if its available.

 

Fast install WHM/cPanel on Centos / Centos 7

If you have minimal Centos OS installation you should install perl and wget and screen packages, also disable selinux protection:

yum install wget perl screen

setenforce 0
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config

screen
cd && wget -N http://httpupdate.cpanel.net/latest && chmod +x ./latest && ./latest

And should wait WHM/cPanel installation about 2 hours.

Custom selinux rule fro virtd_lxc_t

We need create new Type Enforcement policy:

cat > virtd_lxc_t.te

module lxc 1.0; 

require {
        type hald_t;
        type virtd_lxc_t;
        class dbus send_msg;
}

#============= hald_t ==============
allow hald_t virtd_lxc_t:dbus send_msg;

and this for manually compile and load the edited custom Selinux policy module:

checkmodule -M -m -o virtd_lxc_t.mod virtd_lxc_t.te
semodule_package -o virtd_lxc_t.pp -m virtd_lxc_t.mod
semodule -i virtd_lxc_t.pp

LXC container on Centos

LXC isn’t a real Virtualization technique, but is more like a chroot environment, but on “steroids”. Its similar to OpenVZ virtualization, but can use your native kernel version. In some cases its very important.

mkdir /var/lib/libvirt/lxc/centos-6-x86_64/etc/yum.repos.d/ -p  
cat /etc/yum.repos.d/CentOS-Base.repo |sed s/'$releasever'/6/g > /var/lib/libvirt/lxc/centos-6-x86_64/etc/yum.repos.d/CentOS-Base.repo
yum groupinstall core --installroot=/var/lib/libvirt/lxc/centos-6-x86_64/ --nogpgcheck -y
yum install plymouth libselinux-python --installroot=/var/lib/libvirt/lxc/centos-6-x86_64/ --nogpgcheck -y

You should crate selinux rule:

module lxc 1.0;

require {
type hald_t;
type virtd_lxc_t;
class dbus send_msg;
}

#============= hald_t ==============
allow hald_t virtd_lxc_t:dbus send_msg;

You should create manually your selinux rule to allow virtd_lxc_t to use dbus daemon. How crate custom selinux rules, you can check in other my article there.

chroot /var/lib/libvirt/lxc/centos-6-x86_64/ 

echo your_password_there |passwd root --stdin

#Fix root login on console

echo "pts/0" >>/etc/securetty

sed -i s/"session    required     pam_selinux.so close"/"#session    required     pam_selinux.so close"/g /etc/pam.d/login

sed -i s/"session    required     pam_selinux.so open"/"#session    required     pam_selinux.so open"/g /etc/pam.d/login

sed -i s/"session    required     pam_loginuid.so"/"#session    required     pam_loginuid.so"/g /etc/pam.d/login

#Configuring basic networking

cat > /etc/sysconfig/network << EOF

NETWORKING=yes

HOSTNAME=lxc.linux4you.tk

EOF

cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF

DEVICE=eth0

BOOTPROTO=dhcp

ONBOOT=yes

EOF

#Enabling sshd

chkconfig sshd on

# Fixing root login for sshd

sed -i s/"session    required     pam_selinux.so close"/"#session    required     pam_selinux.so close"/g /etc/pam.d/sshd

sed -i s/"session    required     pam_loginuid.so"/"#session    required     pam_loginuid.so"/g /etc/pam.d/sshd

sed -i s/"session    required     pam_selinux.so open env_params"/"#session    required     pam_selinux.so open env_params"/g /etc/pam.d/sshd

# Leaving the chroot'ed filesystem

exit
virt-install --connect lxc:/// --name test --ram 512 --vcpu 1 --filesystem /var/lib/libvirt/lxc/centos-6-x86_64/,/ --noautoconsole

CPU frequency Debian, don’t waste power

If you have Debian lenny platform and want to decrease server CPU  power consumption, lowering temperatures and fan speed:

modprobe acpi-cpufreq

but first of all you should check your CPU capabilities:

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
2660000 2527000 2394000 2261000 2128000 1995000 1862000 1729000 1596000 1463000 1330000 1197000

current CPU frequency:

cat /proc/cpuinfo | grep MHz
cpu MHz : 2660.000
cpu MHz : 2660.000
cpu MHz : 2660.000
cpu MHz : 2660.000

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
performance

also you should load ondemand governor:

modprobe cpufreq_ondemand

now: cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

ondemand performance

OK, now we need enable new feature ondemand:

echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

Done.

To make permanent changes: echo acpi_cpufreq >> /etc/modules && echo cpufreq_ondemand >> /etc/modules

you could also use sysfsutils for this:

echo “devices/system/cpu/cpu0/cpufreq/scaling_governor = ondemand” >>  /etc/sysfs.conf

 

Temperature above threshold cpu clock throttled

It means server could randomly freeze., what to do?

You should check your server sensors with lm_sensors or reboot server and check some BIOS information about CPU temperatures or you can just feel with your hand if CPU fan is warm.

If you see this, its not normal:

Aug 11 02:36:27 tvandmovies kernel: [354969.654819] CPU2: Temperature above threshold, cpu clock throttled (total events = 33273076)
Aug 11 02:36:27 tvandmovies kernel: [354969.654819] CPU0: Temperature above threshold, cpu clock throttled (total events = 33273080)
Aug 11 02:41:27 tvandmovies kernel: [355274.041807] CPU2: Temperature above threshold, cpu clock throttled (total events = 33321213)
Aug 11 02:41:27 tvandmovies kernel: [355274.041807] CPU1: Temperature/speed normal
Aug 11 02:41:27 tvandmovies kernel: [355274.041807] CPU3: Temperature/speed normal
Aug 11 02:41:27 tvandmovies kernel: [355274.041807] CPU0: Temperature above threshold, cpu clock throttled (total events = 33321217)
Aug 11 02:46:49 tvandmovies kernel: [355601.753974] CPU1: Temperature/speed normal
Aug 11 02:46:49 tvandmovies kernel: [355601.753974] CPU3: Temperature/speed normal
Aug 11 02:46:49 tvandmovies kernel: [355601.753974] CPU2: Temperature above threshold, cpu clock throttled (total events = 33353604)
Aug 11 02:46:49 tvandmovies kernel: [355601.754219] CPU0: Temperature above threshold, cpu clock throttled (total events = 33353607)
Aug 11 02:56:12 tvandmovies kernel: [356171.441703] CPU3: Temperature/speed normal
Aug 11 02:56:12 tvandmovies kernel: [356171.441703] CPU1: Temperature/speed normal
Aug 11 02:56:12 tvandmovies kernel: [356171.441703] CPU2: Temperature above threshold, cpu clock throttled (total events = 33355515)
Aug 11 02:56:12 tvandmovies kernel: [356171.441703] CPU0: Temperature above threshold, cpu clock throttled (total events = 33355518)

Replace failing RAID disk

If your /dev/sda disk are failing, you should replace it with new one. You server should support hot swapping:

mdadm –manage /dev/md0 –fail /dev/sda1

mdadm –manage /dev/md0 –remove /dev/sda1

this will copy partition table:

sfdisk -d /dev/sdb |sfdisk --force /dev/sda

mdadm -a /dev/md0 /dev/sda1

if you have more partitions, you should repeat that steps with sda2, sda3 and etc.

 

CloudFlare Error 522

An Error 522 means that the connection started on the origin web server, but that
the request was not completed. The most common reason why this would occur is
that either a program, cron job or resource is taking up more resources than it should
causing the server not to be able to respond to all requests properly. The origin web
server is not functioning consistently for each request. Contact your hosting provider
to identify and resolve the issue.

502