본문 바로가기
[AWS]/Highly Available, Scalable, AWS Stack

17. Separate db tier

by SAMSUNG CLOUD-OKY 2022. 1. 19.
반응형

 

OK so in this video let's launch our RDS instance this one.

And once we launch this will connect to the instance from our EC2 instance using my sql client

I'm using my sql client.

So let's start with this launch and then once we verify the connectivity then we can configure this

RDS instance in our application.

In a later step in this module and then test out our application as well.

OK.

So the way we will launch RDS is we will have to go to the launch sequence and we'll have to configure

a few things.

That's right.

And first we have to make sure that the RDS instance comes up in the same default VPC that will

be that we've been using so far.

Right.

So.

So the EC2 instances is in this VPC so the RDS instance has to be in the same VPC as well.

And we use the default security default security group as well so that we have no network connectivity

issues at this at this stage.

And of course this has to be a mysql database engine right.

Because it has options like Oracle or SQL Server as well.

But this application works with my sql.

And also we will have to set up a multi AZ deployment which means the RDS instance

will have a primary server.

This one here and then a secondary server as well which is one here and RDS automatically will

create the two instances in in separate zones this way we get more fault tolerance but we don't

have to do anything RDS when we create that automatically.

And by the way we also create the replication by to also set up the replication so that any data you

write in the primary will also be replicated synchronously to be to the secondary server.

Ok so.

So this is what we have to do.

And once the server comes up the server will have an endpoint it'll have a DNS endpoint.

So it's not an IP address RDS does not have an IP address.

It has a DNS end point and this endpoint will become available once the instance comes up.

Right.

And we will test the connectivity from the EC2 instance to the RDS instance using the DNS endpoint.

So this is what we need to do.

So let's see how do how to launch the instance and then also how to connect to the instance from the

from the EC2 instance.

All right so let's go ahead and launch our RDS instance So here is the management console

Let's find RDS.

Under the database category and and let's use this button to launch the db instance and choose my sql

choose my sql.

And also let's use this option this is the multi AZ option.

We do have an option of a single instance which is what you should be using normally when you're learning

AWS and you're doing experiment experiments.

Right.

And also this is good for dev or Test and small production applications as well.

Right.

where you don't need that level of fault tolerance that multi az deployment offers.

But given the topic in this module which is fault tolerance.

Let's use this one.

We have to suppose the second re in two different zones.

The replication will be turned on and we'll have automated failover as well.

OK so let's go with this one.

And and here we configure a few things.

For instance let's configure the server size just use micro always use micro even though multi AZ is

not free tier eligible.

OK multi AZ is not free tier eligible but once you practice this you can you can remove this instance

quickly.

OK.

The other thing is that you can change is is we will change the storage type to general purpose, this is cheaper

OK this is just for cost reasons.

Let's change it to a general purpose here.

And let's also give this a name.

So this would be the identifier of the instance and let's call this say PHP app.

RDS

And then the master user name which is essentially the root user of the mysql server and that this is

the password entered twice as usual.

OK.

In the next page right.

This is where you might make mistakes.

So what you need to make sure right is choose the default VPC.

And right now we don't have any other so.

So this should not be or should not be a problem.

Also over here use the existing security group so don't create a new one because RDS will create

a new one and and the rule is set set up in such a way that you can connect only from your your network.

Right so.

So right now we want to connect from that EC2 instance.

Therefore let's make sure that you make this change and select an existing security group.

And we just have one security group in the region which is the default security group.

So this is crucial.

This is Don't make a mistake here.

Otherwise you'll need to spend some time troubleshooting it.

Otherwise we can leave everything at default values and default values.

And now we can launch this instance.

OK so this is how we launch the instance and this will take a bit of time because this will take a bit

of time but once the instance becomes available then we can then we can find the endpoint.

The RDS end point and then we can test out the connectivity from our from our EC2 server.

So let's take a look at this instance.

All right so right now it's it's in a it's in a create mode it's in a create mode.

This one right is the one that we just launched.

And this will take maybe two three or four minutes to become available.

Right.

But in the meantime what I've done is I have a separate instance.

Let me just show you the endpoint using this one the one that I created earlier.

And if you look at this instance you can you're going to scroll down and you'll find the end point.

This is the end point right.

And what we can do is copy this and end point and S-sh into your EC2 instance right which you have in

the same VPC.

Right.

And from here you can initiate a mysql connection using the minus h option.

This is host minus h for host.

Right.

And there just paste the end point

just paste the endpoint like this and then minus u which is the master use the name of the RDS instance.

This is something you would have specified when creating the RDS instance.

Right.

And I specified root so I'm going to use root here but you might have specified something else like admin

or something like that.

But to specify that user and then minus p for password and then enter the password you setup in

RDS and you can now see that we have connected to RDS from the EC2 instance right.

And you can see the my sql prompt here you can run the usual mysql commands like show

databases.

Or you can also create a database.

say create database mydb or something like that

So this is stuff we are doing on RDS but when connecting from the EC2 instance.

OK so now let me exit the mysql connection and now I can also exit the the S-sh connection to the EC2

instance.

OK so.

So this is how we launch the RDS instance and remember a few things.

I mean when you launch the instance or make sure that you choose the default VPC.

This is usually not a problem like this is not a problem because it's only be the VPC right now and

that is automatically selected.

But this one is crucial.

The default way in which RDS works is that it creates a separate security group with access only

from your current IP address.

But what we want to do is use the default security group because this way you'd be able to connect from

the EC2 instance that you have.

OK.

So this is important this is important to do this correctly.

Right.

And of course you have to choose my sql.

That's probably not a problem.

And also make sure that you choose multi-az just a quick note here.

This is not free tier eligible not free.

tier eligible but hopefully you can practice this and remove the instance quickly.

OK.

Now once the server comes up you will have an endpoint.

The DNS endpoint and you can connect to the RDS instance from EC2 instance by first doing an

SSH SSH into the server.

And then use the my sql client that is already available on the server using the minus h option

minus h option.

And then the RDS endpoint should be entered over here and then minus u the user and then

minus p in the usual manner.

Right but the difference is that you have to add a minus h option and then enter the RDS and point.

OK.

And then you can verify the connectivity from the EC2 instance into the into the RDS instance.

Right.

Once you do this you're ready to update your application and make your PHP application talk to.

RDS.

And that we can do in the the next section in this module.

So good luck.

Good luck with this.

this.

 

 

 

반응형

댓글