|
| 1 | +# Create MongoDB and RabbitMQ in Azure |
| 2 | + |
| 3 | +This guide will walk you through HOW to create MongoDB and RabbitMQ in Azure. |
| 4 | + |
| 5 | +## Prep the dev environment |
| 6 | + |
| 7 | +Prep the dev environment by populating environment variables in |
| 8 | +`.scripts/setup-env-variables-azure.sh` |
| 9 | +bash script: |
| 10 | + |
| 11 | +```bash |
| 12 | +# ====== Piggy Metrics Azure Coordinates |
| 13 | +export RESOURCE_GROUP=INSERT-your-resource-group-name |
| 14 | +export REGION=westus2 |
| 15 | +export AKS_CLUSTER=INSERT-your-AKS-cluster-name |
| 16 | +export CONTAINER_REGISTRY=INSERT-your-Azure-Container-Registry-name |
| 17 | + |
| 18 | +## ===== Mongo DB |
| 19 | +export MONGODB_DATABASE=INSERT-your-mongodb-database-name |
| 20 | +export MONGODB_USER=INSERT-your-cosmosdb-account-name |
| 21 | + |
| 22 | +## ===== Rabbit MQ |
| 23 | +export RABBITMQ_RESOURCE_GROUP=INSERT-your-rabbitmq-resource-group-name |
| 24 | +export RABBITMQ_VM_NAME=INSERT-your-rabbitmq-virtual-machine-name |
| 25 | +export RABBITMQ_VM_ADMIN_USERNAME=INSERT-your-rabbitmq-admin-user-name |
| 26 | +``` |
| 27 | + |
| 28 | +Then export these environment variables from the |
| 29 | +`java-on-aks' directory: |
| 30 | + |
| 31 | +```bash |
| 32 | +pwd |
| 33 | +/Users/selvasingh/GitHub/selvasingh/java-on-aks |
| 34 | + |
| 35 | +source .scripts/setup-env-variables-azure.sh |
| 36 | +``` |
| 37 | + |
| 38 | +## Create MongoDB |
| 39 | +Create an instance of MongoDB: |
| 40 | +```bash |
| 41 | +# Change directory |
| 42 | +cd java-on-aks |
| 43 | + |
| 44 | +# Login into Azure |
| 45 | +az login |
| 46 | + |
| 47 | +# Create a Resource Group |
| 48 | +az group create --name ${RESOURCE_GROUP} \ |
| 49 | + --location ${REGION} |
| 50 | + |
| 51 | +# Create a Cosmos DB account |
| 52 | +az cosmosdb create --kind MongoDB \ |
| 53 | + --resource-group ${RESOURCE_GROUP} \ |
| 54 | + --name ${MONGODB_USER} |
| 55 | +``` |
| 56 | +Cut and paste the resource `'id'` value from Azure CLI response into |
| 57 | +`setup-env-variables-azure.sh`, say for example: |
| 58 | + |
| 59 | +```bash |
| 60 | +"id": "/subscriptions/685ba005-af8d-4b04-8f16-a7bf38b2eb5a/resourceGroups/spring-cloud-0918/providers/Microsoft.DocumentDB/databaseAccounts/ ... |
| 61 | +``` |
| 62 | +
|
| 63 | +```bash |
| 64 | +# Get Cosmos DB connection strings |
| 65 | +az cosmosdb list-connection-strings --resource-group ${RESOURCE_GROUP} \ |
| 66 | + --name ${MONGODB_USER} |
| 67 | +``` |
| 68 | +Cut and paste the primary connection string as `MONGODB_URI` in `setup-env-variables-azure.sh` bash file. |
| 69 | +
|
| 70 | +## Create RabbitMQ |
| 71 | +
|
| 72 | +Create an instance of Bitnami RabbitMQ Stack For Microsoft Azure, go to |
| 73 | +[https://portal.azure.com/#blade/Microsoft_Azure_Marketplace/MarketplaceOffersBlade/selectedMenuItemId/home/searchQuery/rabbitmq](https://portal.azure.com/#blade/Microsoft_Azure_Marketplace/MarketplaceOffersBlade/selectedMenuItemId/home/searchQuery/rabbitmq) |
| 74 | +and start: |
| 75 | +
|
| 76 | + |
| 77 | +
|
| 78 | +Fill in the form, use the same value as `RABBITMQ_RESOURCE_GROUP`, |
| 79 | +`RABBITMQ_VM_NAME` and `RABBITMQ_VM_ADMIN_USERNAME`, and choose SSH. Select 'Standard DS3 v2' as |
| 80 | +the size: |
| 81 | + |
| 82 | +
|
| 83 | +Accept defaults: |
| 84 | + |
| 85 | +
|
| 86 | +Accept defaults: |
| 87 | + |
| 88 | +
|
| 89 | +Accept defaults in all subsequent screens, and proceed to create: |
| 90 | + |
| 91 | +
|
| 92 | + |
| 93 | +
|
| 94 | +Open RabbitMQ client and administration ports: |
| 95 | +```bash |
| 96 | +# https://docs.bitnami.com/azure/infrastructure/rabbitmq/get-started/understand-default-config/ |
| 97 | +az vm open-port --port 5672 --name ${RABBITMQ_VM_NAME} \ |
| 98 | + --resource-group ${RABBITMQ_RESOURCE_GROUP} |
| 99 | +az vm open-port --port 15672 --name ${RABBITMQ_VM_NAME} \ |
| 100 | + --resource-group ${RABBITMQ_RESOURCE_GROUP} --priority 1100 |
| 101 | +``` |
| 102 | +
|
| 103 | +Find the public IP address of the Linux virtual machine where RabbitMQ is running and |
| 104 | +and set the `RABBITMQ_HOST` environment variable in |
| 105 | +`piggymetrics/.scripts/setup-env-variables-azure.sh`: |
| 106 | +```bash |
| 107 | +# Open an SSH connection, say |
| 108 | +# First, export the environment variables |
| 109 | +source .scripts/setup-env-variables-azure.sh |
| 110 | +# Open an SSH connection |
| 111 | +ssh selvasingh@${RABBITMQ_HOST} |
| 112 | +``` |
| 113 | +
|
| 114 | +You can adjust RabbitMQ to connect with clients from a different machine: |
| 115 | +```bash |
| 116 | +# https://docs.bitnami.com/azure/infrastructure/rabbitmq/administration/control-services/ |
| 117 | +sudo /opt/bitnami/ctlscript.sh status |
| 118 | +
|
| 119 | +# Stop RabbitMQ |
| 120 | +sudo /opt/bitnami/ctlscript.sh stop |
| 121 | +
|
| 122 | +# Edit RabbitMQ configurtion file |
| 123 | +# https://docs.bitnami.com/azure/infrastructure/rabbitmq/administration/connect-remotely/ |
| 124 | +# https://github.com/rabbitmq/rabbitmq-server/blob/master/docs/rabbitmq.config.example |
| 125 | +sudo nano /opt/bitnami/rabbitmq/etc/rabbitmq/rabbitmq.config |
| 126 | +
|
| 127 | +# Particularly, change line 4 from |
| 128 | + {tcp_listeners, [{"127.0.0.1", 5672}, {"::1", 5672}]}, |
| 129 | +# TO |
| 130 | + {tcp_listeners, [{"0.0.0.0", 5672}, {"::1", 5672}]}, |
| 131 | +
|
| 132 | +# Start RabbitMQ |
| 133 | +sudo /opt/bitnami/ctlscript.sh start |
| 134 | +``` |
| 135 | +
|
| 136 | +You can get your RabbitMQ admin credentials by following the steps in |
| 137 | +[https://docs.bitnami.com/azure/faq/get-started/find-credentials/](https://docs.bitnami.com/azure/faq/get-started/find-credentials/). |
| 138 | +Particularly, open a file in the SSH terminal |
| 139 | +
|
| 140 | +```bash |
| 141 | +cat ./bitnami_credentials |
| 142 | +``` |
| 143 | +
|
| 144 | +Note down the credentials and close the SSH connections. Onto your local |
| 145 | +development machine ... |
| 146 | +
|
| 147 | +From the `bitnami_credentials` file, populate the credentials in |
| 148 | +the `piggymetrics/.scripts/setup-env-variables-azure.sh` file |
| 149 | +and export them to the environment: |
| 150 | +```bash |
| 151 | +# Rabbit MQ |
| 152 | +export RABBITMQ_USERNAME=INSERT-your-rabbitmq-username |
| 153 | +export RABBITMQ_PASSWORD=INSERT-your-rabbitmq-password |
| 154 | +
|
| 155 | +# export them |
| 156 | +source .scripts/setup-env-variables-azure.sh |
| 157 | +``` |
| 158 | +
|
| 159 | +
|
| 160 | +You should be able to reach the RabbitMQ admin console at: |
| 161 | +```bash |
| 162 | +open http://${RABBITMQ_HOST}:15672 |
| 163 | +``` |
| 164 | +
|
| 165 | + |
| 166 | +
|
| 167 | +## Re-prep the local dev environment |
| 168 | +
|
| 169 | +Re-prep the dev environment by populating environment variables in |
| 170 | +`piggymetrics/.scripts/setup-env-variables-azure.sh` and |
| 171 | +`piggymetrics/.scripts/setup-env-variables-development.sh` |
| 172 | +bash scripts: |
| 173 | +
|
| 174 | +```bash |
| 175 | +# ====== Piggy Metrics Azure Coordinates |
| 176 | +export RESOURCE_GROUP=INSERT-your-resource-group-name |
| 177 | +export REGION=eastus |
| 178 | +export SPRING_CLOUD_SERVICE=INSERT-your-spring-cloud-service-name |
| 179 | +
|
| 180 | +## ===== Mongo DB |
| 181 | +export MONGODB_DATABASE=INSERT-your-mongodb-database-name |
| 182 | +export MONGODB_USER=INSERT-your-cosmosdb-account-name |
| 183 | +export MONGODB_URI="INSERT-your-mongodb-connection-string" |
| 184 | +export MONGODB_RESOURCE_ID=INSERT-your-mongodb-resource-id |
| 185 | +
|
| 186 | +## ===== Rabbit MQ |
| 187 | +export RABBITMQ_RESOURCE_GROUP=INSERT-your-rabbitmq-resource-group-name |
| 188 | +export RABBITMQ_VM_NAME=INSERT-your-rabbitmq-virtual-machine-name |
| 189 | +export RABBITMQ_VM_ADMIN_USERNAME=INSERT-your-rabbitmq-admin-user-name |
| 190 | +
|
| 191 | +# Rabbit MQ |
| 192 | +export RABBITMQ_HOST=INSERT-your-rabbitmq-host-public-ip-address |
| 193 | +export RABBITMQ_PORT=5672 |
| 194 | +export RABBITMQ_USERNAME=INSERT-your-rabbitmq-username |
| 195 | +export RABBITMQ_PASSWORD=INSERT-your-rabbitmq-password |
| 196 | +
|
| 197 | +``` |
| 198 | +
|
| 199 | +Go back to [How to use AKS end-to-end for Java apps?](https://github.com/azure-samples/java-on-aks) |
0 commit comments