Skip to content

Commit

Permalink
update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
liupeirong committed Nov 20, 2015
1 parent a71452c commit 0af2543
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mysql-replication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This template deploys a MySQL replication environment with one master and one sl
- Deploys 2 VMs in an Azure VNet, each has 2 data disks striped into Raid0
- Deploys a load balancer in front of the 2 VMs, so that the VMs are not directly exposed to the internet. MySQL and SSH ports are exposed through the load balancer using Network Security Group rules
- Configures a http based health probe for each MySQL instance that can be used to monitor MySQL health
- Installs LIS4 driver and reboots each VM 3 minutes after the installation script on each VM completes
- Installs LIS4 driver on each VM. Note that the VM is not automatically rebooted, so LIS4 will take effect the next time the VM reboots

### How to Deploy
You can deploy the template with Azure Portal, or PowerShell, or Azure cross platform command line tools. The example here uses PowerShell to deploy.
Expand Down Expand Up @@ -63,7 +63,7 @@ High availability and failover are no different from other GTID based MySQL repl
> $nic0=Get-AzureNetworkInterface -Name mysqldns-nic0 -ResourceGroupName mysqlrg
> $nic1=Get-AzureNetworkInterface -Name mysqldns-nic1 -ResourceGroupName mysqlrg
...
# $i is the index of the target nat rule, for full powershell script, see switchMySQLNatRule.sql
# $i is the index of the target nat rule, for full powershell script, please see [switchMySQLNatRule.ps1](/mysql-replication/switchMySQLNatRule.ps1)
...
> $rule0=$nic0.IpConfigurations[0].LoadBalancerInboundNatRules[$i]
> $nic0.IpConfigurations[0].LoadBalancerInboundNatRules.removeRange($i,1)
Expand All @@ -77,7 +77,7 @@ mysql> change master to master_host='10.0.1.5', master_user='admin', master_pass
* Switch the old master's NAT rule with the new master
```sh
...
# $j is the index of the target nat rule, for full powershell script, see switchMySQLNatRule.sql
# $j is the index of the target nat rule, for full powershell script, see please see [switchMySQLNatRule.ps1](/mysql-replication/switchMySQLNatRule.ps1)
...
> $rule1=$nic1.IpConfigurations[0].LoadBalancerInboundNatRules[$j]
> $nic1.IpConfigurations[0].LoadBalancerInboundNatRules.removeRange($j,1)
Expand Down
4 changes: 4 additions & 0 deletions mysql-replication/switchMySQLNatRule.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#this script switches the NAT rule on the Azure Load Balancer from the old MySQL master to the new one
$rg="mySQLResourceGroupName"
$dns="mySQLDNSName"
$from="0" #current mysql master VM postfix, disable its mysql public port
Expand All @@ -12,13 +13,15 @@ $nic1Rules=$nic1.IpConfigurations[0].LoadBalancerInboundNatRules
$nic0RuleCnt=$nic0.IpConfigurations[0].LoadBalancerInboundNatRules.Count
$nic1RuleCnt=$nic1.IpConfigurations[0].LoadBalancerInboundNatRules.Count

#find the mysql NAT rule on the old master and remove it
for ($i=0; $i -lt $nic0RuleCnt; ++$i) {if ($nic0Rules[$i].Id -like "*MySQLNatRule*") {break;}};
if ($i -ge $nic0RuleCnt) {exit 1}

$rule0=$nic0.IpConfigurations[0].LoadBalancerInboundNatRules[$i]
$nic0.IpConfigurations[0].LoadBalancerInboundNatRules.removeRange($i,1)
Set-AzureNetworkInterface -NetworkInterface $nic0

#find the mysql NAT rule on the new master, replace it with the old master's NAT rule
for ($j=0; $j -lt $nic1RuleCnt; ++$j) {if ($nic1Rules[$j].Id -like "*MySQLNatRule*") {break;}};
if ($j -ge $nic1RuleCnt) {exit 1}

Expand All @@ -27,6 +30,7 @@ $nic1.IpConfigurations[0].LoadBalancerInboundNatRules.removeRange($j,1)
$nic1.IpConfigurations[0].LoadBalancerInboundNatRules.add($rule0)
Set-AzureNetworkInterface -NetworkInterface $nic1

#the old master resumes the new master's previous NAT rule
$nic0.IpConfigurations[0].LoadBalancerInboundNatRules.add($rule1)
Set-AzureNetworkInterface -NetworkInterface $nic0
exit 0
Expand Down

0 comments on commit 0af2543

Please sign in to comment.