Memcached repcached同步

Standard
#安装
wget http://downloads.sourceforge.net/project/repcached/repcached/2.2-1.2.8/repcached-2.2-1.2.8.patch.gz
wget http://downloads.sourceforge.net/repcached/memcached-1.2.8-repcached-2.2.tar.gz
 
tar zxf memcached-1.2.8-repcached-2.2.tar.gz
 
cd memcached-1.2.8-repcached-2.2
 
gzip -cd ../repcached-2.2-1.2.8.patch.gz | patch -p1
./configure --prefix=/usr/local/memcached --enable-replication
make
make install
 
#启动
cd /usr/local/memcached
#默认复制监听端口11212
#Master
./memcached -v -l 127.0.0.1 -p 11211 -uroot
#Slaver
./memcached -v -l 127.0.0.1 -p 11213 -uroot -x 127.0.0.1 -X 11212
 
#验证同步是否成功
#telnet 127.0.0.1 11211
set key1 0 0 3
111
STORED
get key2
VALUE key2 0 3
222
END
 
#telnet 127.0.0.1 11213
get key1
VALUE key1 0 3
111
END
set key2 0 0 3
222
STORED
 
#注:一开始看官方上写Master/Slaver还以为像Mysql一样只有Master才能读写.实际其Slaver上进行的写操作也会被Master同步.

使用Curlftpfs+Unison实现本地目录与FTP间双向同步

Standard

我们这边美工的基本工作流程是先从设在北美办公室的FTP机器上下载相关需求文档及图形元素,做完后再上传过去.
因为图片之类的都比较大,加上两地间网速原因,实际使用过程中浪费了不少时间在上下传的过程中.
比较简单的解决方法是在我们下班后将北美办公室的FTP和这边当天所完成的工作进行双向更新同步.

具体,先使用`curlftpfs`将北美的FTP mount到本地Server,然后在本地另建一个本地目录用于和FTP mount做双向同步,用crontab定时运行`unison`,并且将本地目录Samba.

[yemaoshen@local ~] # rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
[yemaoshen@local ~] # yum install curlftpfs
[yemaoshen@local ~] # make ftp_test
[yemaoshen@local ~] # curlftpfs ftp://IP_ADDRESS/test/ /home/yemaoshen/ftp_test/ -o user="yemaosheng:com" -o allow_other
[yemaoshen@local ~] # #相当于umout# fusermount -u /home/yemaosheng/ftp_test/
[yemaoshen@local ~] # make local_test
[yemaoshen@local ~] # yum install unison
[yemaoshen@local ~] # unison ./ftp_test ./local_test -auto -silent

要是报FATAL: Module fuse not found.记得再yum install dkms dkms-fuse一下

如果只需单向同步的话,这边有人写了个perl脚本满好用的,下载地址: http://ossw.ibcl.at/FTPSync/

[yemaoshen@local ~] # ./ftpsync.pl ftp://yemaosheng:com@IP_ADDRESS/test /home/yemaosheng/local_test

转载请注明出处 http://yemaosheng.com

mysql不停服修复主从同步的shell

Standard
#!/bin/sh
#yemaosheng.com上传到从DB修改后执行!
#主DB信息
MDB_IP=192.168.3.30
MDB_USERNAME=op
MDB_PASSWORD=123456
#从DB信息
SDB_IP=127.0.0.1
SDB_USERNAME=root
SDB_PASSWORD=132456
#相互同步的库名
DB=("db_1" "db_2")
 
/etc/init.d/mysqld restart
 
for((i=0;i<${#DB[@]};i++));do
	echo ${DB[${i}]}".sql Dump..."
	mysqldump -h${MDB_IP} -u${MDB_USERNAME} -p${MDB_PASSWORD} -R --triggers  --single-transaction --flush-logs --master-data --database ${DB[${i}]} > ${DB[${i}]}.sql 
	echo "Ok"
done
 
mysql -u${SDB_USERNAME} -p${SDB_PASSWORD} -h${SDB_IP} -e 'slave stop;'
 
for((i=0;i<${#DB[@]};i++));do
	echo ${DB[${i}]}".sql Input..."
	mysql -u${SDB_USERNAME} -p${SDB_PASSWORD} -h${SDB_IP} < ${DB[${i}]}.sql
	echo "Ok"
done
 
mysql -u${SDB_USERNAME} -p${SDB_PASSWORD} -h${SDB_IP} -e 'slave start;'
 
mysql -u${SDB_USERNAME} -p${SDB_PASSWORD} -h${SDB_IP} -e 'show slave status\G'
 
for((i=0;i<${#DB[@]};i++));do
	echo ${DB[${i}]}".sql Del..."
	rm -f ${DB[${i}]}.sql
	echo "Ok"
done

Mysql同步出错处理

Standard

Mysql主从同步出错
Last_Error: Query caused different errors on master and slave. Error on master: ‘Deadlock found when trying to get lock; try restarting transaction’ (1213), Error on slave: ‘no error’ (0). Default database: ‘…’. Query: ‘INSERT INTO …’
Last_Error: Error ‘Duplicate entry ‘…’ for key 1′ on query. Default database: ‘…’. Query: ‘…’

遇到如上情况报错可用以下方式解决

(从DB上运行)
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; #从DB运行,用来跳过1个事件,只有当同步进程出现错误而停止的时候才可以执行.
slave start;
show slave statue\G;

如果同步还有报错就继续重复以上三步操作直至无报错.

自动脚本

while [ 1 ]; do if [ `mysql -u root -e  "show slave status \G; " | grep  "Duplicate entry" | wc -l` -eq 1 ] ; then mysql -u root -e  "stop slave; set global sql_slave_skip_counter=1; start slave;" fi; sleep 1; mysql -u root -e "show slave status\G "; done

另外,最后没有报错,但slave_io_running no的话,先slave stop;slave start;还是no的话就只能通过重导数据来重做同步了.

CentOS rsync同步

Standard

A:192.168.0.1
B:192.168.0.2

A:
yum -y install xinetd
vi /etc/xinetd.d/rsync

将“disable = no
chkconfig xinetd on
service xinetd start
vi /etc/rsyncd.conf

[site] #name
path = /var/www/html #copied directory
hosts allow = 192.168.0.2
hosts deny = *
list = true
uid = root
gid = root

B:
vi /etc/rsync_exclude.lst #Write directory or files you don’t want to copy.
no.txt
nono.txt

rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst 192.168.0.1::site /home/backup

crontab -e

00 02 * * * rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst 192.168.0.1::site /home/backup