2. Who am I ?
about.me/lefred
Copyright @ 2020 Oracle and/or its affiliates.2
3. @lefred
MySQL Evangelist
Managing MySQL since
3.20
devops believer
living in Belgium
h ps://lefred.be
Frédéric Descamps
Copyright @ 2020 Oracle and/or its affiliates.3
6. Breakout Lab Support
Today's Experts Standing By:
- Miguel - Dave
- Olivier - Ted
- Vi orio
Have a Question?
Direct your question via chat to one of our experts above or the instructor.
Breakout Rooms
If you are not able to get your question answered within the chat, we have
breakout rooms available for you.
We ask that if your question requires the use of a breakout room, that the time
within the breakout room remains brief to ensure experts can assist others in
need of help.
Copyright @ 2020 Oracle and/or its affiliates.6
7. use only Germany Central (Frankfurt) !!
and use the same email you used to register
to this session
Prerequisites
Please create your OCI free account following all the instructions from the Livelabs:
h ps://oracle.github.io/learning-library/oci-library/oci-hol/odl-mysql-idc-terraform-hol-
master/workshops/freetier/
Copyright @ 2020 Oracle and/or its affiliates.7
8. Free Trier: note on always free
To perform this lab, you need to use a new Free Trier account provided today. If you have
an old one, it might not work if you don't have the free credits.
If this is your case you won't be able to:
use more than 1 node in your cluster
use the NAT gateway and split the databases in a private subnet
And you will have to use VM.Standard.E2.1.Micro shape.
Copyright @ 2020 Oracle and/or its affiliates.8
10. What is Terraform ?
Terraform is a tool for building, changing, and versioning infrastructure safely and
e ciently. Terraform can manage existing and popular service providers as well as custom
in-house solutions.
Copyright @ 2020 Oracle and/or its affiliates.10
11. Terraform & OCI
Oracle Cloud Infrastructure is supported by Terraform.
We provide many OCI quickstarts in github: h ps://github.com/oracle-quickstart/.
Copyright @ 2020 Oracle and/or its affiliates.11
12. Terraform & OCI
Oracle Cloud Infrastructure is supported by Terraform.
We provide many OCI quickstarts in github: h ps://github.com/oracle-quickstart/.
Today we will use a contribution to the original MySQL one: h ps://github.com/lefred/oci-
mysql-idc.git
Copyright @ 2020 Oracle and/or its affiliates.11
14. Architecture
MySQL 1
MySQL 3
VCN
10.0.0.0/16
Public Subnet
10.0.0.0/24
Private Subnet
10.0.1.0/24
Private Subnet
10.0.1.0/24
Group Replication
Fault Domain 1
Fault Domain2
Fault Domain3
MySQL 2
Bastion Host
Copyright @ 2020 Oracle and/or its affiliates.13
15. Get ready
Se ing up your environment
Copyright @ 2020 Oracle and/or its affiliates.14
16. an OCI account
Terraform
git
ssh client
on Windows, for git and ssh, you should use
h ps://github.com/git-for-windows/git/releases/latest
Se ing up your environment
You need:
Copyright @ 2020 Oracle and/or its affiliates.15
19. Update your feedback
At the end of each LAB, please update your feedback in the participants list:
Copyright @ 2020 Oracle and/or its affiliates.17
20. Creating your API keys:
$ mkdir ~/.oci
$ openssl genrsa -out ~/.oci/oci_api_key.pem 2048
$ chmod go-rwx ~/.oci/oci_api_key.pem
$ openssl rsa -pubout -in ~/.oci/oci_api_key.pem -out ~/.oci/oci_api_key_public.pem
And for SSH don't provide passphrase:
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/fred/.ssh/id_rsa): id_rsa_oci
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa_oci
Your public key has been saved in id_rsa_oci.pub
Prepare your OCI environment
Copyright @ 2020 Oracle and/or its affiliates.18
21. Prepare your OCI environment (2)
Example for our Windows user friends:
Copyright @ 2020 Oracle and/or its affiliates.19
22. Prepare your OCI environment (3)
Example for our Windows user friends - API keys:
Copyright @ 2020 Oracle and/or its affiliates.20
23. Prepare your OCI environment (4)
Example for our Windows user friends - SSH keys:
Copyright @ 2020 Oracle and/or its affiliates.21
24. In our example, the key is
~/.oci/oci_api_key_public.pem
Prepare your OCI environment - deploy your API key
You need to deploy your public API key on OCI:
Copyright @ 2020 Oracle and/or its affiliates.22
26. LAB 1
ready ? update your feedback !
Copyright @ 2020 Oracle and/or its affiliates.23
27. Terraform is a unique binary you can download from
h ps://www.terraform.io/downloads.html
$ cd ~bin
$ wget
https://releases.hashicorp.com/terraform/0.13.4/terraform_0.13.4_linux_amd64.zip
$ unzip terraform_0.13.4_linux_amd64.zip
Archive: terraform_0.13.4_linux_amd64.zip
inflating: terraform
$ terraform --version
Terraform v0.13.4
Installing Terraform
Copyright @ 2020 Oracle and/or its affiliates.24
29. $ git clone https://github.com/lefred/oci-mysql-idc.git
Ge ing the git repo
Copyright @ 2020 Oracle and/or its affiliates.26
30. $ git clone https://github.com/lefred/oci-mysql-idc.git
Ge ing the git repo
Now we need to copy terraform.tfvars.template to edit it:
$ cd oci-mysql-idc
$ cp terraform.tfvars.template terraform.tfvars
Copyright @ 2020 Oracle and/or its affiliates.26
31. $ git clone https://github.com/lefred/oci-mysql-idc.git
Ge ing the git repo
Now we need to copy terraform.tfvars.template to edit it:
$ cd oci-mysql-idc
$ cp terraform.tfvars.template terraform.tfvars
This is maybe the most complex task of the deployment ;-)
Copyright @ 2020 Oracle and/or its affiliates.26
39. Key & Fingerprint
The private_key_path value is the path of oci_api_key.pem:
private_key_path = "/home/fred/.oci/oci_api_key.pem"
Copyright @ 2020 Oracle and/or its affiliates.34
40. Key & Fingerprint
The private_key_path value is the path of oci_api_key.pem:
private_key_path = "/home/fred/.oci/oci_api_key.pem"
And to get the Fingerprint:
Copyright @ 2020 Oracle and/or its affiliates.34
44. compartment_ocid
You may or not have setup di erent compartments. I usually use a sandbox for example.
Copyright @ 2020 Oracle and/or its affiliates.38
47. SSH Keys
You need to specify keys to connect in ssh to the compute instances (only via the bastion
host to the MySQL InnoDB Cluster nodes).
Copyright @ 2020 Oracle and/or its affiliates.41
48. SSH Keys
You need to specify keys to connect in ssh to the compute instances (only via the bastion
host to the MySQL InnoDB Cluster nodes).
Pay a ention to provide the full path and to verify that the private keys are those without
.pub !
Copyright @ 2020 Oracle and/or its affiliates.41
49. SSH Keys
You need to specify keys to connect in ssh to the compute instances (only via the bastion
host to the MySQL InnoDB Cluster nodes).
Pay a ention to provide the full path and to verify that the private keys are those without
.pub !
ssh_authorized_keys_path = "/home/fred/.ssh/id_rsa_oci.pub"
ssh_private_key_path = "/home/fred/.ssh/id_rsa_oci"
Copyright @ 2020 Oracle and/or its affiliates.41
51. Cluster information
The dedicated user that we create is called clusteradmin and you can specify its password.
You can also specify and name for the cluster.
clusteradmin_password = "MyB1gPassw0rd!"
cluster_name = "MyClusterInOCI"
Copyright @ 2020 Oracle and/or its affiliates.43
52. Cluster information
The dedicated user that we create is called clusteradmin and you can specify its password.
You can also specify and name for the cluster.
clusteradmin_password = "MyB1gPassw0rd!"
cluster_name = "MyClusterInOCI"
You can also specify the number of nodes that needs to be deployed in your cluster. 3 is
the recommended amount but for testing purpose when you develop your Terraform
recipes, you can reduce it.
number_of_nodes = "2"
Copyright @ 2020 Oracle and/or its affiliates.43
54. More info on
h ps://docs.cloud.oracle.com/en-
us/iaas/Content/Compute/References/compute
Node Shape
This speci es the Compute Instance's Shape. Of course it depends on your limits.
You can nd the di erent shapes on OCI Dashboard:
Copyright @ 2020 Oracle and/or its affiliates.45
55. Node Shape (2)
Using the Free Trier provided today, the node shape should be VM.Standard.E2.1
Copyright @ 2020 Oracle and/or its affiliates.46
57. Oracle Linux 8.2-2020.07.28-0 is for example:
eu-
frankfurt-
1
ocid1.image.oc1.eu-frankfurt-
1.aaaaaaaau6ypymprt22fhkenua6fbz2mhy62kdbn6zskrv3fy7fdrq c4ka
us-
ashburn-
1
ocid1.image.oc1.iad.aaaaaaaa7loygdwzmew3hud3bqjyzamzqnz3krpiuhjb3z3u5s3hmmtar6mq
node_image_id - (optional)
This is the ocid of the compute instance you will use. For this demo, we will use the same
on all nodes. The image depends of your region.
You can nd the list of images on h ps://docs.cloud.oracle.com/en-us/iaas/images/
Copyright @ 2020 Oracle and/or its affiliates.48
58. Oracle Linux 8.2-2020.07.28-0 is for example:
eu-
frankfurt-
1
ocid1.image.oc1.eu-frankfurt-
1.aaaaaaaau6ypymprt22fhkenua6fbz2mhy62kdbn6zskrv3fy7fdrq c4ka
us-
ashburn-
1
ocid1.image.oc1.iad.aaaaaaaa7loygdwzmew3hud3bqjyzamzqnz3krpiuhjb3z3u5s3hmmtar6mq
node_image_id - (optional)
This is the ocid of the compute instance you will use. For this demo, we will use the same
on all nodes. The image depends of your region.
You can nd the list of images on h ps://docs.cloud.oracle.com/en-us/iaas/images/
If you don't specify any, Oracle Linux 8 images in your region
will be used.
Copyright @ 2020 Oracle and/or its affiliates.48
62. Terraform
Now that everything is setup, we need to init our environment:
$ terraform init
Copyright @ 2020 Oracle and/or its affiliates.51
63. Terraform
Now that everything is setup, we need to init our environment:
$ terraform init
Copyright @ 2020 Oracle and/or its affiliates.51
64. Terraform - plan
Let's see if everything is correct and what the system will deploy in OCI using the plan
command:
$ terraform plan
Copyright @ 2020 Oracle and/or its affiliates.52
65. Terraform - plan
Let's see if everything is correct and what the system will deploy in OCI using the plan
command:
$ terraform plan
Copyright @ 2020 Oracle and/or its affiliates.52
66. Terraform - deployment
Let's deploy our infrastructure with apply:
$ terraform apply
Copyright @ 2020 Oracle and/or its affiliates.53
67. Terraform - deployment
Let's deploy our infrastructure with apply:
$ terraform apply
Copyright @ 2020 Oracle and/or its affiliates.53
68. Terraform - deployment (2)
While the deployment is happening, you can verify in OCI Dashboard, the creation of the
compute instances:
Copyright @ 2020 Oracle and/or its affiliates.54
73. Connection to the Bastion Host
To connect to the bastion host, we use ssh with the user opc on the public IP (use yours!)
and the ssh key we created:
Copyright @ 2020 Oracle and/or its affiliates.58
74. MySQL InnoDB Cluster
Let's connect to the cluster using MySQL Shell
Copyright @ 2020 Oracle and/or its affiliates.59
77. MySQL InnoDB Cluster - Router
For security reason, we didn't open the MySQL Router ports on the public IP.
Copyright @ 2020 Oracle and/or its affiliates.61
79. LAB 4
ready ? update your feedback !
Copyright @ 2020 Oracle and/or its affiliates.62
80. House keeping, you only pay what you
consume !
Cleaning up !
Copyright @ 2020 Oracle and/or its affiliates.63
81. Terraform - terminating our environment
It's also very easy to terminate everything using the destroy command:
$ terraform destroy
Copyright @ 2020 Oracle and/or its affiliates.64
82. Terraform - terminating our environment
It's also very easy to terminate everything using the destroy command:
$ terraform destroy
Copyright @ 2020 Oracle and/or its affiliates.64
83. Terraform - terminating our environment
It's also very easy to terminate everything using the destroy command:
$ terraform destroy
Copyright @ 2020 Oracle and/or its affiliates.64
85. LAB 5
ready ? update your feedback !
Copyright @ 2020 Oracle and/or its affiliates.65
86. OCI Resource Manager
... and now for smart & lazy people ;-)
Copyright @ 2020 Oracle and/or its affiliates.66
87. OCI Resource Manager
It's also possible to deploy without pain, the same architecture using OCI Resource and
Stacks !
Copyright @ 2020 Oracle and/or its affiliates.67
89. OCI Resource Manager - stack creation (2)
Now we can download the stack package on h ps://github.com/lefred/oci-mysql-
idc/releases/tag/1.1.0
Copyright @ 2020 Oracle and/or its affiliates.69
90. OCI Resource Manager - stack creation (3)
Just drop the zip le here:
Copyright @ 2020 Oracle and/or its affiliates.70
91. OCI Resource Manager - stack creation (5)
Fill some variables:
Copyright @ 2020 Oracle and/or its affiliates.71
92. OCI Resource Manager - stack creation (6)
Let's start with only 1 MySQL InnoDB Cluster node:
Copyright @ 2020 Oracle and/or its affiliates.72
93. OCI Resource Manager - stack creation review
We can review the variables and create it:
Copyright @ 2020 Oracle and/or its affiliates.73
94. OCI Resource Manager - jobs
The rst job we will run it the plan to see what will be the required modi cations:
Copyright @ 2020 Oracle and/or its affiliates.74
95. OCI Resource Manager - jobs (2)
If all went well, we will see it as succeeded:
Copyright @ 2020 Oracle and/or its affiliates.75
96. OCI Resource Manager - apply job
As the plan succeeded, we can apply our code for this infrastructure:
Copyright @ 2020 Oracle and/or its affiliates.76
97. OCI Resource Manager - apply job (2)
It's possible to follow the process in "real time" in the logs:
Copyright @ 2020 Oracle and/or its affiliates.77
98. The Terraform output
is a bit di erent as
everything was
handled by the stack.
All required SSH keys
were also created:
OCI Resource Manager - apply job (3)
Copyright @ 2020 Oracle and/or its affiliates.78
99. OCI Resource Manager - compute instances
Of course the compute instances were created:
Copyright @ 2020 Oracle and/or its affiliates.79
100. Connection
We need to copy the SSH private key from the jobs output in a le if we want to connect to
the bastion host. We also need to change the ownership of it:
$ vi priv.key
<-- paste the content in the file and save it -->
$ chmod 600 priv.key
$ ssh -i priv.key opc@130.61.xx.xx
[opc@mysqlshellbastion ~]$
Copyright @ 2020 Oracle and/or its affiliates.80