Tag Archives: ubuntu

Migrate from mysql to percona

1
2
gpg --keyserver hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
gpg -a --export CD2EFD2A | sudo apt-key add -

add to /etc/apt/sources.list.d/percona.list

1
2
deb http://repo.percona.com/apt VERSION main
deb-src http://repo.percona.com/apt VERSION main

where VERSION is a name of your ubuntu version,
you can get it by command

1
lsb_release -a |grep name |awk '{print $2}'

backup data

1
2
cp -Rf /var/lib/mysql /var/lib/mysql-old
cp /etc/my.cnf /etc/my.cnf-old

Install percona (it automatically removes mysql and converts databases)

1
2
apt-get update
apt-get install percona-server-server-5.5 percona-server-client-5.5

Part of this article was taken from http://planet.jboss.org/post/drop_in_migration_from_mysql_to_percona_db_in_two_minutes

Postgresql 9.2 for Ubuntu 12.04 and 10.04

Add repository: http://www.postgresql.org/download/linux/ubuntu/

1
2
3
echo deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main | sudo tee /etc/apt/sources.list.d/postgresql.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update

setup postgres:

1
sudo apt-get install postgresql-9.2 postgresql-contrib-9.2

Ubuntu: kernel 3.10.1

cd /tmp/
if your linux is 64bit:

1
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.1-saucy/linux-headers-3.10.1-031001-generic_3.10.1-031001.201307131550_amd64.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.1-saucy/linux-headers-3.10.1-031001_3.10.1-031001.201307131550_all.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.1-saucy/linux-image-3.10.1-031001-generic_3.10.1-031001.201307131550_amd64.deb

else if it's 32bit:

1
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.1-saucy/linux-headers-3.10.1-031001-generic_3.10.1-031001.201307131550_i386.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.1-saucy/linux-headers-3.10.1-031001_3.10.1-031001.201307131550_all.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.1-saucy/linux-image-3.10.1-031001-generic_3.10.1-031001.201307131550_i386.deb

sudo dpkg -i *.deb
update-grub
reboot

Ubuntu: booting enctypted fs from with key on usb stick

Install ubuntu server with two partitions:

  • sda1 /boot
  • sda2 encrypted partition

make sda2 encrypted with lvm partitions into it.
Now when your system ready you can load it with password which you enter from keyboard,
but it's boring and we would like boot from keyfile on the usb stick.
mkdir /key && mount /dev/sdb1 /key # there is sdb1 partition on my usb-flash

dd if=/dev/urandom of=/key/keyfile bs=1K count=10

create file /etc/initramfs-tools/scripts/local-top/luks_key_mount with the following content

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh

case $1 in
prereqs)
     exit 0
     ;;
esac

. /scripts/functions

log_begin_msg "Decrypting root filesystem using a key file."
wait_for_udev
/bin/sleep 7
mkdir /key
/bin/mount -t ext4 /dev/sdb1 /key
/sbin/cryptsetup luksOpen /dev/sda2 crypt_sda2 --key-file /key/keyfile
log_end_msg

if [ ! -b /dev/mapper/srvlvm-srvlvmroot ]
then
  panic "
Welcome to Linux command prompt.
"
fi
exit 0

# in that script /dev/sdb1 — my usb flash card
# /dev/sda2 — my encrypted partition
# /dev/mapper/srvlvm-srvlvmroot — lvm root partition

chmod +x /etc/initramfs-tools/scripts/local-top/luks_key_mount

1
update-initramfs -u

reboot

Puppet: ubuntu update

This puppet config will make apt-get update && apt-get upgrade once a day between 2 and 4 hours.
Put it in manifests/site.pp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Exec { path => '/usr/bin:/bin:/usr/sbin:/sbin' }

class update {
        schedule { 'maintenance':
                  range  => "2 - 4",
                  period => daily,
                  repeat => 1,
        }

        exec { "upgrade_packages":
                command => "apt-get upgrade -q=2 -y",
                group => "root",
                user => "root",
                schedule => 'maintenance',
                onlyif => ["apt-get update"]
        }
}

node default {
        include update
}

Ubuntu: create own deb (example redis-server)

I got it from http://serverfault.com/questions/419201/how-do-i-install-the-latest-stable-version-of-redis

Install fpm with gem:

# apt-get install rubygems
# gem install fpm

Compile Redis:

# cd /usr/local/src/
# wget http://redis.googlecode.com/files/redis-2.4.16.tar.gz
# tar zxvf redis-2.4.16.tar.gz
# cd redis-2.4.16/
# make

Build .deb package:

# mkdir -p /tmp/redis-$VERSION.$$/usr/bin
# mkdir -p /tmp/redis-$VERSION.$$/etc

# cp src/{redis-benchmark,redis-check-aof,redis-check-dump,redis-cli,redis-server} /tmp/redis-$VERSION.$$/usr/bin

# cp redis.conf /tmp/redis-$VERSION.$$/etc/redis.conf
# cd ..

# fpm -s dir -t deb -n redis-server -v 2.4.16 -C /tmp/redis-2.4.16.18597/ -p redis-server-2.4.16_amd64.deb usr/bin/

Upgrade Redis:

# dpkg -i redis-server-2.4.16_amd64.deb
dpkg: warning: downgrading redis-server from 2:2.2.12-1build1 to 2.4.16.
(Reading database ... 148744 files and directories currently installed.)
Preparing to replace redis-server 2:2.2.12-1build1 (using redis-server-2.4.16_amd64.deb) ...
Stopping redis-server: redis-server.
Unpacking replacement redis-server ...
dpkg: warning: unable to delete old directory '/var/log/redis': Directory not empty
dpkg: warning: unable to delete old directory '/etc/redis': Directory not empty
Setting up redis-server (2.4.16) ...
Processing triggers for man-db ...
Processing triggers for ureadahead ...

Examine the version:

# /usr/bin/redis-server -v
Redis server version 2.4.16 (00000000:0)

MySQL: change data folder in ubuntu

sudo su
mkdir -p /data/mysql
mv /var/lib/mysql/* /data/mysql
rm -rf /var/lib/mysql
ln -s /data/mysql /var/lib/mysql
chown -R mysql.mysql /data/mysql /var/lib/mysql

edit /etc/mysql/conf.d/datadir.cnf // create this file
[mysqld]
datadir=                /data/mysql

edit /etc/apparmor.d/usr.sbin.mysqld
after
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,

add
/data/mysql/ r,
/data/mysql/** rwk,

/etc/init.d/apparmor reload
/etc/init.d/mysql restart

ubuntu: locale

If you took error:

perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = «ru_RU.UTF-8»
    are supported and installed on your system.
perl: warning: Falling back to the standard locale («C»).
perl: warning: Setting locale failed.

You should make follow command to setup UTF8  american locale.

1
2
3
4
5
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales