Advertisement
Guest User

Untitled

a guest
May 6th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. Vagrant.configure(2) do |config|
  2. config.vm.define "db01" do |db01|
  3. db01.vm.box = "bento/centos-6.7"
  4. db01.vm.hostname = "db01"
  5. db01.vm.provision :shell, path: "bootstrap-master.sh"
  6. db01.vm.network "private_network", ip: "192.168.50.101"
  7. db01.vm.synced_folder "../", "/home/vagrant/src/twindb"
  8. end
  9. config.vm.define "db02" do |db02|
  10. db02.vm.box = "bento/centos-6.7"
  11. db02.vm.hostname = "db02"
  12. db02.vm.provision :shell, path: "bootstrap-slave.sh"
  13. db02.vm.network "private_network", ip: "192.168.50.102"
  14. db02.vm.synced_folder "../", "/home/vagrant/src/twindb"
  15. end
  16.  
  17. #!/usr/bin/env bash
  18.  
  19. set -e
  20.  
  21. hostname="`hostname`"
  22.  
  23. yum -y install https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
  24.  
  25. packages="
  26. mysql-community-server"
  27.  
  28. yum -y install ${packages}
  29.  
  30. chkconfig mysqld on
  31.  
  32. function wait_for_mysql() {
  33. # wait till mysql starts
  34. timeout=300
  35. mysql_started="NO"
  36. while [ ${timeout} -gt 0 ]
  37. do
  38. if ! [ "`mysql -e 'SELECT 1'`" = "1" ]
  39. then
  40. echo "SUCCESS"
  41. break
  42. fi
  43. sleep 1
  44. let timeout=$timeout-1
  45. done
  46. }
  47. cat <<EOF > /etc/my.cnf
  48. [mysqld]
  49. server_id=101
  50. log_bin=mysqld-bin
  51. EOF
  52.  
  53. /etc/init.d/mysqld start
  54.  
  55. if [ "`wait_for_mysql`" = "SUCCESS" ]
  56. then
  57. mysql -u root -e "RESET MASTER"
  58. mysql -u root -e "CREATE USER 'replication'@'%' IDENTIFIED BY 'bigs3cret'"
  59. mysql -u root -e "GRANT REPLICATION SLAVE ON *.* TO 'replication'@'%'"
  60. mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO root@'%'";
  61. else
  62. echo "MySQL failed to start"
  63. exit -1
  64. fi
  65.  
  66. #!/usr/bin/env bash
  67.  
  68. set -e
  69.  
  70. hostname="`hostname`"
  71.  
  72. yum -y install https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
  73.  
  74. packages="
  75. mysql-community-server"
  76.  
  77. yum -y install ${packages}
  78.  
  79. chkconfig mysqld on
  80.  
  81. function wait_for_mysql() {
  82. # wait till mysql starts
  83. timeout=300
  84. mysql_started="NO"
  85. while [ ${timeout} -gt 0 ]
  86. do
  87. if ! [ "`mysql -e 'SELECT 1'`" = "1" ]
  88. then
  89. echo "SUCCESS"
  90. break
  91. fi
  92. sleep 1
  93. let timeout=$timeout-1
  94. done
  95. }
  96. cat <<EOF > /etc/my.cnf
  97. [mysqld]
  98. server_id=102
  99. log_bin=mysqld-bin
  100. EOF
  101.  
  102. /etc/init.d/mysqld start
  103.  
  104. if [ "`wait_for_mysql`" = "SUCCESS" ]
  105. then
  106. mysql -u root -e "RESET MASTER"
  107. mysql -u root -e "CHANGE MASTER TO
  108. MASTER_HOST='192.168.50.101',
  109. MASTER_USER='replication',
  110. MASTER_PASSWORD='bigs3cret',
  111. MASTER_LOG_FILE='mysqld-bin.000001',
  112. MASTER_LOG_POS=120"
  113. mysql -u root -e "START SLAVE"
  114. else
  115. echo "MySQL failed to start"
  116. exit -1
  117. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement