Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # setup mysql rep
  4. #
  5.  
  6. ROOT_PASS="rootP@ssw0rd"
  7. REPLI_PASS="replicationP@ssw0rd"
  8. SIBLING_IP="1.2.3.4"
  9. SERVER_ID=1 # first server is 1, second is 2
  10.  
  11.  
  12. ###
  13. REPLI_USER="replicator"
  14. MCLIENT="mysql -uroot -p$ROOT_PASS"
  15. CONFFILE="/etc/mysql/conf.d/repli.cnf"
  16. [ -d /etc/mysql/mariadb.conf.d ] && CONFFILE="/etc/mysql/mariadb.conf.d/72-repli.cnf"
  17. set -e
  18.  
  19.  
  20. # add config file
  21. echo "[mysqld]
  22. server-id=$SERVER_ID
  23. log-bin=\"mysql-bin\"
  24. binlog-ignore-db=test
  25. binlog-ignore-db=information_schema
  26. replicate-ignore-db=test
  27. replicate-ignore-db=information_schema
  28. relay-log=\"mysql-relay-log\"
  29. auto-increment-increment = 2
  30. auto-increment-offset = $SERVER_ID
  31. bind-address = 0.0.0.0
  32. " >$CONFFILE && echo "$CONFFILE created"
  33.  
  34.  
  35. # create replicator user
  36. echo "Create user $REPLI_USER"
  37. echo "
  38. CREATE USER $REPLI_USER@'%' IDENTIFIED BY '$REPLI_PASS';
  39. GRANT REPLICATION SLAVE ON *.* TO $REPLI_USER@'%' IDENTIFIED BY '$REPLI_PASS';
  40. " | $MCLIENT
  41.  
  42. service mysql restart
  43.  
  44. echo "---enter these to sibling:-----------";
  45. echo "SHOW MASTER STATUS;"|$MCLIENT
  46. echo "-------------------------------------";
  47. echo -n "enter remote File : ";read repliFile
  48. echo -n "enter remote Position: ";read repliPosition
  49.  
  50. echo "
  51. STOP SLAVE;
  52. CHANGE MASTER TO MASTER_HOST = '$SIBLING_IP', MASTER_USER = '$REPLI_USER', MASTER_PASSWORD = '$REPLI_PASS', \
  53. MASTER_LOG_FILE = '$repliFile', MASTER_LOG_POS = $repliPosition;
  54. START SLAVE;
  55. " |$MCLIENT
  56.  
  57. service mysql restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement