天天看點

No.01 AWS Redis 啟用TLS和AUTH

一、首先建立aws elc時,啟用tls,terraform code 

resource "aws_elasticache_replication_group" “test”{

  transit_encryption_enabled = true

}

二、編譯redis-cli,env = ubuntu 18.0.4

參考aws doc : 

https://docs.aws.amazon.com/zh_cn/amazonelasticache/latest/red-ug/in-transit-encryption.html

1.安裝依賴包

$ apt-get update

$ apt-get upgrade

$ apt-get install gcc openssl tcl clang wget

$ apt-get install libssl-dev     // 其實安裝的是 opnessl-devel

$ apt-get install libjemalloc-dev // 其實安裝的是 jemalloc-devel

// tcl-devel ,ubuntu找不到,至今也未安裝成功

2.編譯 redis-cli,必須是redis 6.0版本,才能支援tls

$ wget http://download.redis.io/redis-stable.tar.gz

$ tar zxvf redis-stable.tar.gz

$ cd redis-stable/

$ make distclean

$ make redis-cli cc=clang build_tls=yes

$ install -m 755 src/redis-cli /usr/local/bin/

三、使用aws elc cli啟用auth(elc必須已經啟用了tls)并驗證:注意參數 --tls 的位置

// auth-token-update-strategy rotate,因為建立之初,無法設定auth,是以這裡必須指定rotate政策,使得無密碼和設定的密碼同時可用狀态

aws elasticache modify-replication-group --replication-group-id "建立的elc name" --auth-token "密碼:必須符合aws密碼要求" --auth-token-update-strategy rotate --apply-immediately

// 設定為僅用密碼登入

aws elasticache modify-replication-group --replication-group-id "建立的elc name" --auth-token "必須是上面已經設定的密碼" --auth-token-update-strategy set --apply-immediately

// 驗證:如果elc是叢集模式,必須使用參數 -c 

redis-cli -c -h hostname --tls -a "auth token" -p port