如何连接两个Ec2实例,以便它们可以彼此通信 [英] How to connect two Ec2 Instance so that they can Communicate with each other
问题描述
我想将两个ec2实例彼此连接,以便它们可以彼此通信。我在将两个Ec2实例彼此连接的方式上发现了问题。
I want to connect two ec2 instances with each other so that they can communicate with each other. I found the problem on the way we can connect 2 Ec2 instances with each other.
我也提供了此方案。 EC2-情况
推荐答案
To保持简单,要使任何两个程序通过网络相互通信,都需要两件事
To keep it very simple, For any two programs to communicate with each other over a network, you need two things
- IP地址
- 端口号
- IP Address
- Port Number
考虑一下您有两个EC2实例。让我们命名它们
Consider you have two EC2 instances. Lets name them
- Instance1
- Instance2
- Instance1
- Instance2
在每个这些实例上,您都必须具有要在其间进行通信的某些程序。另外,这些程序必须在实例的 PORT 上运行。例如,默认情况下,tomcat实例在端口8080上运行。让我们命名程序:-
On each of these instances, you must be having some programs between which you want the communication to take place. Also, these programs must be running on a PORT of the instance. For example, tomcat instance runs on port 8080 by default. Lets name our programs:-
- Program1(程序在Instance1上运行),在端口1000上运行
- Program2(程序在Instance2上运行),在端口2000上运行
让我们先谈谈Program1运行在Instance1的端口1000上。
Let us first talk about Program1 running on port 1000 of Instance1.
- 登录到AWS控制台
- 单击EC2服务
- 在左侧面板中,单击 安全组
- 单击按钮 创建安全组
- 将打开覆盖。
- 输入名称和描述
- 单击选项卡 入站 ,然后单击 添加规则
- 在这里,您要添加哪个端口应接受连接。
- 设置以下内容详细信息:-
-类型:自定义TCP规则
-协议:TCP
-端口范围:1000 [或程序运行的任何其他端口]
-来源:可以从其中访问 Program1 的外部IP。可以是无处不在,我的IP或自定义IP
- 单击选项卡 Outbound >,然后单击 添加规则
- 如果要进行出站通信,请重复步骤9。
- Log onto AWS Console
- Click on EC2 Service
- In the left panel, click on Security Groups
- Click on the button Create Security Group
- An overlay will open.
- Put-in the name and description of your choosing
- Click on the tab Inbound and click on Add Rule
- Here, you are adding which port should accept connections.
- Set the following details:-
-Type: Custom TCP Rule
-Protocol: TCP
-Port Range: 1000 [Or any other port on which your program runs]
-Source: External IP from where Program1 can be accessed. It can be "Everywhere", "My IP" or a "Custom IP" - Click on the tab Outbound and click on Add Rule
- Repeat Step 9, if you want outbound communication.
在Instance2上重复这些步骤,您会很方便。
这篇关于如何连接两个Ec2实例,以便它们可以彼此通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!