Linux

Minimal rsync process for multinode web cluster

install rsync pkg if not installed on every node

yum install rsync

choose a “master node” to take code from, in our example we name it node1 and the others node2,3,4 etc

NODE 1
useradd rsyncuser
cat /home/ec2-user/.ssh/authorized_keys

copy the auth key inside

su rsyncuser
cd /home/rsyncuser
mkdir .ssh
chmod 700 .ssh
vi .ssh/authorized_keys

paste the key in your clipboard

chmod 600 .ssh/authorized_keys
exit

NODE 2,3,4
mkdir /root/keys
vi /root/keys/node1rsync.key

and copy inside your node1 ec2 private key

chmod 600 /root/keys/node1rsync.key

now you can launch an rsync command from node2,3,4 to node1 every X minutes

crontab -e

and add

*/X * * * * /usr/bin/rsync -avzhe "ssh -i /root/keys/nide1rsync.key" rsyncuser@NODE1_IP_OR_FQDN:/var/www/vhosts/www.yourwebsite.it /var/www/vhosts/

enjoy

mysql restore slave from master dump

On the master:

RESET MASTER;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS \G;
Copy and paste the result
mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 28808
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)

you’ll need file and position to point the slave on the correct binlog position

mysqldump - u root -p dbname > /usr/local/src/dump.sql
UNLOCK TABLES;

On the slave;

STOP SLAVE;
scp root@masteraddress:/usr/local/src/dump.sql /usr/local/src
mysql -u root -p < /usr/local/src/dump.sql
RESET SLAVE;
now remember to use what you got from the master status
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=28808;
START SLAVE;

and check with
SHOW SLAVE STATUS \G;

Slave_IO_Running: Yes
Slave_SQL_Running: Yes