Advertisement
Guest User

Untitled

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