aws ec2 attach-internet-gateway --vpc-id "vpc-0e02ef59133d3b5a7" --internet-gateway-id "igw-0a871cc54507807f4" --region ap-northeast-2
인스턴스 보안 설정 방법
규칙 번호 | 유형 | 프로토콜 | 포트 범위 | 소스 | 허용/거부 |
---|---|---|---|---|---|
100 | SSH(22) | TCP(6) | 22 | 0.0.0.0/0 | Allow |
101 | SSH(22) | TCP(6) | 22 | 0.0.0.0/0 | Deny |
200 | HTTP(80) | TCP(6) | 80 | 0.0.0.0/0 | Allow |
300 | HTTPS(443) | TCP(6) | 443 | 0.0.0.0/0 | Allow |
* | 모든 트래픽 | 모두 | 모두 | 0.0.0.0/0 | Deny |
규칙 번호 | 유형 | 프로토콜 | 포트 범위 | 소스 | 허용/거부 |
---|---|---|---|---|---|
100 | SSH(22) | TCP(6) | 22 | 0.0.0.0/0 | Allow |
101 | 모든 TCP | TCP(6) | 모두(0-65535) | 0.0.0.0/0 | Deny |
200 | HTTP(80) | TCP(6) | 80 | 0.0.0.0/0 | Allow |
300 | HTTPS(443) | TCP(6) | 443 | 0.0.0.0/0 | Allow |
* | 모든 트래픽 | 모두 | 모두 | 0.0.0.0/0 | Deny |
바스티온 EC2인스턴스 생성 - 퍼블릭 서브넷 지정
#!/bin/bash
yum install httpd -y
service httpd start
같은 VPC내 보안 그룹 구분
프라이빗 EC2 생성 시 IAM역할 선택 또는 ATTACH IAM역할.
# S3버킷 리스트 조회 (VPC Endpoint설정도 안했는데 연결됨)
# 프라이빗 RT에 NAT설정 되어있기때문
aws s3 ls --region ap-northeast-2
# 프라이빗 RT에 NAT설정 삭제후 시도시 조회안됨
aws s3 ls --region ap-northeast-2
# 조회가능 확인
aws s3 ls --region ap-northeast-2
vpc-0b4163a5f741002f8 (starpass-vpc)
subnet-01ab087db1ecc6748 (starpass-private-was-a)
sg-03ceb4c49e904f0aa (starpass-redis)
# 소스 다운로드
$ su starpass
$ cd ~starpass/
$ wget http://download.redis.io/redis-stable.tar.gz
$ tar -xvzf redis-stable.tar.gz
$ vim redis-stable/redis.conf
# bind 127.0.0.1 로컬(톰캣)에서만 접근
# requirepass [your_password]
# port [your_port]
$ cd redis-stable/src
$ ./redis-server /home/starpass/redis-stable/redis.conf &
# 접속 시도
redis-cli -h {ElastiCache 엔드포인트} -p {보안그룹에 정의된 포트 7379}
> flushall
> keys *
su starpass
cd ~starpass/
wget http://download.redis.io/redis-stable.tar.gz
tar -xvzf redis-stable.tar.gz
vim redis-stable/redis.conf
# bind 127.0.0.1 로컬(톰캣)에서만 접근
# requirepass [your_password]
# port [your_port]
cd redis-stable/src
./redis-server /home/starpass/redis-stable/redis.conf &
# 접속 시도
./redis-cli -h {ElastiCache 엔드포인트} -p {보안그룹에 정의된 포트 7379}
# redis-cli 파라미터 '-a {비밀번호}' 사용 자제 (보안이슈)
./redis-cli -h 127.0.0.1 -p 7379
> AUTH {비밀번호}
> flushall
> keys *
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.async.RedisAsyncCommands;
public class LettuceConnection {
// String.format("redis://%s:%d/0", hostname, port)
private static final String REDIS_CON_URL = "redis://13.209.76.95:6379/0"; // 준호EC2 redis
// private static final String REDIS_CON_URL = "elasticache-junho-0813.eo7tpf.0001.apn2.cache.amazonaws.com:6379";
public static void main(String[] args) {
RedisClient redisClient = RedisClient.create(REDIS_CON_URL);
StatefulRedisConnection<String, String> connection = redisClient.connect();
RedisAsyncCommands<String, String> async = connection.async();
final String[] result = new String[1];
async.set("foo", "bar")
.thenComposeAsync(ok -> async.get("foo"))
.thenAccept(s -> result[0] = s)
.toCompletableFuture()
.join();
connection.close();
redisClient.shutdown();
System.out.println(result[0]); // "bar"
}
}
redis-cli
keys *
# https://emflant.tistory.com/235
docker pull redis:alpine
docker network create redis-net
docker network ls
docker network inspect redis-net
# --name 컨테이너 이름 지정
# -v host와 연결할 폴더 지정
# https://stackoverflow.com/a/32270232/12198233
# -p host에 노출할 포트 지정
docker run --name my-redis \
-p 7379:7379 \
--network redis-net \
-v $(pwd)/my/folder:/data \
-v c:/Users/feelon2/Downloads/redis.conf:/etc/redis.conf \
-d redis:alpine redis-server --appendonly yes
# --rm 실행 할때 컨테이너 id가 존재하면 삭제 후 run
winpty docker run -it --network redis-net \
--rm redis:alpine redis-cli \
-h my-redis