Nasser Heidari

2010-10-11

MySQL fatal error 1236

Filed under: Linux — Nasser Heidari @ 17:09

DB-1:

mysql> show master status;

File Position Binlog_Do_DB Binlog_Ignore_DB
bin.007733 824963644

DB-2:

mysql> STOP SLAVE;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH TABLES WITH READ LOCK;
Query OK, 0 rows affected (0.00 sec)

mysql> UNLOCK TABLES;
Query OK, 0 rows affected (0.00 sec)

mysql> CHANGE MASTER TO
MASTER_HOST=’DB-1′,
MASTER_USER=’replication’,
MASTER_LOG_FILE=’bin.007733′,
MASTER_LOG_POS=824963644;
Query OK, 0 rows affected (0.00 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

http://www.dougreese.com/mysql-fatal-error-1236.html

2010-07-20

Move user accounts from old Linux server to a new Linux server

Filed under: Linux — Nasser Heidari @ 16:37

Following files/dirs are required for traditional Linux user management:

/etc/passwd – contains various pieces of information for each user account
/etc/shadow – contains the encrypted password information for user’s accounts and optional the password aging information.
/etc/group – defines the groups to which users belong
/etc/gshadow – group shadow file (contains the encrypted password for group)
/var/spool/mail – Generally user emails are stored here.
/home – All Users data is stored here.

————-
Backup Routine:
————-

# mkdir /root/move/
# export UGIDLIMIT=500
# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig
# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/move/group.mig
# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow >  /root/move/shadow.mig
# cp /etc/gshadow /root/move/gshadow.mig
# tar -zcvpf /root/move/home.tar.gz /home
# tar -zcvpf /root/move/mail.tar.gz /var/spool/mail

————- Move Backup Files to New Linux Server: ————-

scp -r /root/move/*  nasser@linax.wordpress.com:/var/tmp

————- Restore : ————-

# mkdir /root/newsusers.bak

# cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/newsusers.bak

# cd /var/tmp

# cat passwd.mig >> /etc/passwd

# cat group.mig >> /etc/group

# cat shadow.mig >> /etc/shadow

# /bin/cp gshadow.mig /etc/gshadow

# cd /

# tar -zxvf /var/tmp/home.tar.gz

# tar -zxvf /var/tmp/mail.tar.gz

2010-05-02

Generating a Random mac Address

Filed under: Linux — Nasser Heidari @ 07:02

# 2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1|sed '2d;s/0000000 *//;s/ /:/g;s/::*$//'

2010-04-22

Too many connections in TIME_WAIT state

Filed under: Linux — Nasser Heidari @ 16:25

Applications that handle a huge number of TCP connections, either as a server, or as a client, will often see a large number of sockets in TIME_WAIT state.
The sockets in TIME_WAIT can be seen with the “netstat -epn –tcp ” command.
If the number of TIME_WAIT sockets gets too large, your address space will be exhausted, causing a disruption of TCP traffic.
If you try a little Googling, you may be find tcp_fin_timeout option .
Do not be confused by the /proc/sys/net/ipv4/tcp_fin_timeout config item. The FIN TIMEOUT is not the same as the TIMEWAIT length.

You can force the kernel to reuse the TIME_WAIT buckets though, by setting the /proc/sys/net/ipv4/tcp_tw_recycle entry to 1. I have tested this, and it works: very few TIME_WAIT entries will be present when using this setting.

# echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
or
add net.ipv4.tcp_tw_recycle = 1 to /etc/sysctl.conf .

Socket state counter

Filed under: Linux — Nasser Heidari @ 16:10

# netstat -an | awk '/^tcp/ {A[$(NF)]++} END {for (I in A) {printf "%5d %s\n", A[I], I}}'

1 LAST_ACK
16 LISTEN
2 SYN_RECV
5 CLOSE_WAIT
26 ESTABLISHED
1 FIN_WAIT1
2 SYN_SENT
4 CLOSING
18 TIME_WAIT

2010-04-04

Obtain the HP Server Model information and Serial Number

Filed under: freebsd,Linux — Nasser Heidari @ 09:44

To do this, first install dmidecode , in FreeBSD you can install it easily:

# pkg_add -r dmidecode

then try this:

# dmidecode -s chassis-serial-number
# dmidecode -s system-product-name

FreeBSD: You can find all installed Hard Drives using this way:

# df
Filesystem 1K-blocks Used Avail Capacity Mounted on
/dev/da0s1a 10154158 263394 9078432 3% /
devfs 1 1 0 100% /dev
/dev/da0s1e 5077038 86 4670790 0% /tmp
/dev/da0s1f 99246150 18245382 73061076 20% /usr
/dev/da0s1d 20308398 2714302 15969426 15% /var

# egrep ‘da[0-9]’ /var/run/dmesg.boot

Hitting this command will show lots of information about your hardware by :

# sysctl hw | less

2010-03-30

Mysql Replication Useful Commands

Filed under: Miscellaneous — Nasser Heidari @ 11:51

SHOW BINLOG EVENTS

SHOW BINLOG EVENTS
[IN ‘log_name’] [FROM pos] [LIMIT [offset,] row_count]
e.g:

mysql> show binlog events in 'bin.000017' from 36383578 limit 50\G

Shows the events in the binary log.

—————————————————————————————-
show binary logs;
Lists the binary log files on the server.

—————————————————————————————-

PURGE BINARY LOGS TO 'bin.000015';
PURGE BINARY LOGS BEFORE '2010-03-01 00:00:00';
PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 7 DAY);

The PURGE BINARY LOGS statement deletes all the binary log files listed in the log index file prior to the specified log file name or date. BINARY and MASTER are synonyms. Deleted log files also are removed from the list recorded in the index file, so that the given log file becomes the first in the list.

—————————————————————————————-
Recovery from binary logs:

mysqlbinlog --stop-position="368312" /data/mysql/bin.000015 | mysql -u root -p
mysqlbinlog --start-position="368315" /data/mysql/bin.000015| mysql -u root -p

mysqlbinlog --stop-date="2010-03-01 19:00:00" /data/mysql/bin.000015 | mysql -u root -p
mysqlbinlog --start-date="2010-03-01 00:00:00" /data/mysql/bin.000015 | mysql -u root -p

mysqlbinlog /data/mysql/bin.000015 > /tmp/mysql_restore.sql

2010-03-20

Mysql Master Master Repliction

Filed under: Miscellaneous — Nasser Heidari @ 11:39

I’m going to setup MySQL Multi-Master Replication, here are my systems information:

DB-1 : 172.20.1.6 —> (Master 1 / Slave 2)
DB-2 : 172.20.1.8 —> (Master 2 / Slave 1)
# uname -a
Linux DB-1.linax.wordpress.com 2.6.18-164.11.1.el5 #1 SMP Wed Jan 20 07:32:21 EST 2010 x86_64 x86_64 x86_64 GNU/Linux

also I’m using MYSQL community Edition, you can find rpm’s here :
# wget http://mirrors.bevc.net/mysql/Downloads/MySQL-5.1/MySQL-devel-community-5.1.41-0.rhel5.x86_64.rpm
# wget http://mirrors.bevc.net/mysql/Downloads/MySQL-5.1/MySQL-client-community-5.1.41-0.rhel5.x86_64.rpm
# wget http://mirrors.bevc.net/mysql/Downloads/MySQL-5.1/MySQL-server-community-5.1.41-0.rhel5.x86_64.rpm

OK, lets start:

I configured MySQL’s my.cnf file to use the tuning setup from the my-medium.cnf, which should give us good tuning parameters for our load at this point. Then I added the pieces necessary for replication in both DB-1 and DB-2:

Warning : I’ve changed default path of MYSQL data directory to /data/mysql, so you need to change it to your data directory. (default path is /var/lib/mysql/)

————————————————-
1. On Both Servers, you need to create a replication slave account in mysql:

mysql>GRANT REPLICATION SLAVE ON *.* TO 'replication'@'172.20.1.%' IDENTIFIED BY 'replication';
mysql>GRANT RELOAD ON *.* TO 'replication'@'172.20.1.%';
mysql>GRANT SUPER ON *.* TO 'replication'@'172.20.1.%';
mysql>FLUSH PRIVILEGES;

————————————————-

2. DB-1 my.cnf configuration :

server-id = 1
log-bin = /data/mysql/bin.log
log-bin-index = /data/mysql/log-bin.index
log-error = /data/mysql/error.log

relay-log = /data/mysql/relay.log
relay-log-info-file = /data/mysql/relay-log.info
relay-log-index = /data/mysql/relay-log.index
relay-log-space-limit = 6G

auto_increment_increment = 10
auto_increment_offset = 1
master-host = 172.20.1.8
master-user = replication
master-password = replication

replicate-do-db = MYDB
binlog-ignore-db = mysql
# log_bin_trust_function_creators = 1
expire_logs_days = 15
max_binlog_size = 10G

————————————————-
3. DB-2 my.cnf Configuration :

server-id = 2
log-bin = /data/mysql/bin.log
log-bin-index = /data/mysql/log-bin.index
log-error = /data/mysql/error.log

relay-log = /data/mysql/relay.log
relay-log-info-file = /data/mysql/relay-log.info
relay-log-index = /data/mysql/relay-log.index
relay-log-space-limit = 6G

auto_increment_increment = 10
auto_increment_offset = 2
master-host = 172.20.1.6
master-user = replication
master-password = replication

replicate-do-db = MYDB
binlog-ignore-db = mysql
# log_bin_trust_function_creators = 1
expire_logs_days = 15
max_binlog_size = 10G

————————————————-
4. Another thing that you should take care, when you setup Mysql Replication is Binary and Relay logs size.
as you can see in my configuration, I have set a 6GB space limit for relay-logs and 15 days expiry time for binary logs .
for purging binary-logs add a cron job like this :

0 1 * * * mysql -uroot -ppass -e "PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 15 DAY);"

this will purge your binary logs, older than 15 days .
————————————————-

I only wanted to replicate one database, so I listed it as the example shows with replicate-do-db. Since I intend on allowing for various nodes to be added, I set auto_increment_increment to 10, which will allow for 10 different servers, all of which could be read-write masters if I wanted them to be. In this case, my plan is only for 2, so this will give me a lot of room to grow. in other words :

When you have N master servers:

Set auto_increment_increment to N on each master.
Set each of the N masters to have a different auto_increment_offset, for example set to 1 in the first node, 2 in the second, and so on.

Using this two variables as described in the manual, you can ensure that all nodes in your replication array will use different sequences of auto-incrementing numbers. For example, using auto_increment_increment = 10 and auto_increment_offset=3, the numbers generated when inserting three records will be 3, 13, 23. Using 10, 7, you’ll get 7, 17, 27, and so on.

That’s it, now just start/restart mysql in both side.
you can check replication status with this mysql commands:

mysql> show master status;
mysql> show slave status\G

2010-03-05

Perl: substr

Filed under: Miscellaneous — Nasser Heidari @ 13:59

Extracts a substring out of EXPR and returns it.

* substr EXPR,OFFSET,LENGTH,REPLACEMENT
* substr EXPR,OFFSET,LENGTH
* substr EXPR,OFFSET

e.g:
1. my $s = “The black cat climbed the green tree”;
2. my $color = substr $s, 4, 5; # => black
3. my $middle = substr $s, 4, -11; # => black cat climbed the
4. my $end = substr $s, 14; # => climbed the green tree
5. my $tail = substr $s, -4; # => tree
6. my $z = substr $s, -4, 2; # => tr

Original Document => http://perldoc.perl.org/functions/substr.html

2010-03-01

FreeBSD: make install – Accept default config

Filed under: freebsd — Nasser Heidari @ 08:28

Using FreeBSD ports means compiling software by executing make install clean. This is great since it automatically fetches the dependencies then compile them.
using make install clean, most of the packages have configuration options in which I have to manually choose the options. So if I install packageA with a lot of dependencies, those dependencies may have each a configuration option in which I have to select.
To select default Configuration i know 3 options that you can make use :
1.
For csh-based Shell:
# setenv BATCH yes
OR for sh-based Shell:
# export BATCH=”yes”

2.
# make -DBATCH install clean

3.
# make config-recursive
usually to get all of the options displayed for you to choose upfront. I say “usually” because not all ports support it, but most do.

« Previous PageNext Page »

Create a free website or blog at WordPress.com.