Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # setup mysql replication.
- # run this script parallel on both servers as we need log file name and position on the other node
- #
- #
- ROOT_PASS="rootP@ssw0rd"
- REPLI_PASS="replicationP@ssw0rd"
- SIBLING_IP="1.2.3.4"
- SERVER_ID=1 # first server is 1, second is 2
- ###
- REPLI_USER="replicator"
- MCLIENT="mysql -uroot -p$ROOT_PASS"
- CONFFILE="/etc/mysql/conf.d/repli.cnf"
- [ -d /etc/mysql/mariadb.conf.d ] && CONFFILE="/etc/mysql/mariadb.conf.d/72-repli.cnf"
- set -e
- # add config file
- echo "[mysqld]
- server-id=$SERVER_ID
- log-bin=\"mysql-bin\"
- binlog-ignore-db=test
- binlog-ignore-db=information_schema
- replicate-ignore-db=test
- replicate-ignore-db=information_schema
- relay-log=\"mysql-relay-log\"
- auto-increment-increment = 2
- auto-increment-offset = $SERVER_ID
- bind-address = 0.0.0.0
- " >$CONFFILE && echo "$CONFFILE created"
- # create replicator user. drop first manually if already exists
- echo "Create user $REPLI_USER"
- echo "
- CREATE USER $REPLI_USER@'%' IDENTIFIED BY '$REPLI_PASS';
- GRANT REPLICATION SLAVE ON *.* TO $REPLI_USER@'%' IDENTIFIED BY '$REPLI_PASS';
- " | $MCLIENT
- service mysql restart
- echo "---enter these on $SIBLING_IP:-----------";
- echo "SHOW MASTER STATUS;"|$MCLIENT
- echo "-------------------------------------";
- echo -n "enter File as shown on $SIBLING_IP: ";read repliFile
- echo -n "enter Position as shown on $SIBLING_IP: ";read repliPosition
- echo "
- STOP SLAVE;
- CHANGE MASTER TO MASTER_HOST = '$SIBLING_IP', MASTER_USER = '$REPLI_USER', MASTER_PASSWORD = '$REPLI_PASS', \
- MASTER_LOG_FILE = '$repliFile', MASTER_LOG_POS = $repliPosition;
- START SLAVE;
- " |$MCLIENT
- service mysql restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement