在AWS中,您可以创建一个手动防火墙(安全组),并将其与您的EC2实例相关联。以下是使用AWS CLI命令的示例:
-
创建安全组:
aws ec2 create-security-group --group-name allow-rstudio-server --description "Security group for RStudio Server"
-
授权入站流量:
aws ec2 authorize-security-group-ingress --group-name allow-rstudio-server --protocol tcp --port 8787 --cidr 0.0.0.0/0
此命令允许端口8787上来自任何IP地址的传入TCP流量(
0.0.0.0/0
).根据您的具体需要调整CIDR块。
-
启动您的EC2实例并关联安全组:
使用AWS管理控制台或CLI启动EC2实例时,请确保关联您创建的安全组(
allow-rstudio-server
)使用您的实例。
以下是使用AWS CLI启动实例的示例:
aws ec2 run-instances --image-id ami-xxxxxxxxxxxxxxxxx --instance-type t2.micro --key-name YourKeyPairName --security-groups allow-rstudio-server
代替
ami-xxxxxxxxxxxxxxxxx
为您的实例提供适当的Amazon Machine Image(AMI),以及
YourKeyPairName
和你的钥匙对。
请记住用您的特定详细信息替换占位符值。此外,请确保安装了AWS CLI,并使用必要的凭据进行了配置。