如何连接两个Ec2实例,以便它们可以彼此通信 [英] How to connect two Ec2 Instance so that they can Communicate with each other

查看:587
本文介绍了如何连接两个Ec2实例,以便它们可以彼此通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此处输入图片描述

我想将两个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


  1. IP地址

  2. 端口号

  1. IP Address
  2. Port Number

考虑一下您有两个EC2实例。让我们命名它们

Consider you have two EC2 instances. Lets name them


  1. Instance1

  2. Instance2

  1. Instance1
  2. 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:-


  1. Program1(程序在Instance1上运行),在端口1000上运行

  2. Program2(程序在Instance2上运行),在端口2000上运行

让我们先谈谈Program1运行在Instance1的端口1000上。

Let us first talk about Program1 running on port 1000 of Instance1.


  1. 登录到AWS控制台

  2. 单击EC2服务

  3. 在左侧面板中,单击 安全组

  4. 单击按钮 创建安全组

  5. 将打开覆盖。

  6. 输入名称描述

  7. 单击选项卡 入站 ,然后单击 添加规则

  8. 在这里,您要添加哪个端口应接受连接。

  9. 设置以下内容详细信息:-


    -类型:自定义TCP规则

    -协议:TCP

    -端口范围:1000 [或程序运行的任何其他端口]

    -来源:可以从其中访问 Program1 的外部IP。可以是无处不在,我的IP或自定义IP

  10. 单击选项卡 Outbound >,然后单击 添加规则

  11. 如果要进行出站通信,请重复步骤9。

  1. Log onto AWS Console
  2. Click on EC2 Service
  3. In the left panel, click on Security Groups
  4. Click on the button Create Security Group
  5. An overlay will open.
  6. Put-in the name and description of your choosing
  7. Click on the tab Inbound and click on Add Rule
  8. Here, you are adding which port should accept connections.
  9. 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"
  10. Click on the tab Outbound and click on Add Rule
  11. Repeat Step 9, if you want outbound communication.

在Instance2上重复这些步骤,您会很方便。

这篇关于如何连接两个Ec2实例,以便它们可以彼此通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆