Topics

bash

Simple MySQL migration bash script

#!/usr/bin/env bash

set -e


mkdir -p /root/tmp

#migrate "original db params" "new db params" "new db name"
function migrate(){
    mysqldump --skip-lock-tables --single-transaction --add-drop-table $1 > /root/tmp/${3}.sql
    echo "CREATE DATABASE IF NOT EXISTS ${3};" | mysql $2
    mysql --max_allowed_packet=1000M $2  $3 < /root/tmp/${3}.sql
    rm -f /root/tmp/${3}.sql
}


migrate "-uolduser -poldpassword -h oldhost olddbname" "-unewuser -pnewpassword -h newhost" "newdbname"

#more migrates here ...

Fork here

install memcached 1.4.13 on CentOS 6.2

– Make sure to check PHP-FPM and MYSQL posts.

– One of the dependencies of memcache is libevent, get latest version from libevent.org

mkdir libevent
cd libevent
wget https://github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz
tar xfz libevent-2.0.17-stable.tar.gz
cd libevent-2.0.17-stable

– get latest version from memcached.org

Install curl 7.24 on CentOS 6.2

– Make sure to check PHP-FPM post.

– install from source

yum remove curl curl-devel

wget http://curl.haxx.se/download/curl-7.24.0.tar.bz2
tar xfj curl-7.24.0.tar.bz2
cd curl-7.24.0
./configure --prefix=/usr
make
make install
#check version
curl -V

– To install with support

./configure --with-curl=/usr --with-curlwrappers

Adding new users and admins to Linux server

Check Installing CentOS 6.2 on VMware post.

Using admin user avoids common mistakes done when logging as root, instead use sudo to run root commands.

mkdir /server

#adding web-server user www
adduser www -d /server -s /sbin/nologin

#adding admins group to use instead of root
groupadd admins
visudo
#add
%admins ALL=(ALL)       NOPASSWD: ALL

#add new admin 
adduser admin -g admins
#set password
passwd admin

#add email for user admin
vi /etc/aliases
#add
admin: admin@example.com
#rebuild data
newaliases

Mounting partitions with noatime

Check Installing CentOS 6.2 on VMware and increase linux file descriptors posts.

This should help reduce disk IO by telling the system not to update inode access times. more here

vi /etc/fstab
#add noatime to the options of the / file system ex:
/dev/mapper/vg_centos6-lv_root /                       ext4    defaults,noatime         1 1

– remount file system

mount -o remount /
#check
cat /proc/mounts | grep noatime