Ubuntu 24.04 Redis 7 SSL/TLS の設定方法
環境
Ubuntu 24.04
Redis 7
概要
Redis で SSL/TLS による暗号化通信の設定を有効にします。
1.自己署名の証明書を作成します。Let’s Encrypt 等の正規の証明書を使用する場合は当作業は不要です。
# cd /etc/ssl/private
# openssl req -x509 -nodes -newkey rsa:2048 -keyout redis.pem -out redis.pem -days 3650
Generating a RSA private key
.................+++++
........+++++
writing new private key to 'vsftpd.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP # 国コード
State or Province Name (full name) [Some-State]:Tokyo # 地域(県)
Locality Name (eg, city) []:Tokyo # 都市
Organization Name (eg, company) [Internet Widgits Pty Ltd]:GTS # 組織名
Organizational Unit Name (eg, section) []:Server World # 組織の部門名
Common Name (e.g. server FQDN or YOUR name) []:test.arkagme.com # サーバーの FQDN
Email Address []:root@arkgame.com # 管理者アドレスげ
Generating a RSA private key
.................+++++
........+++++
writing new private key to 'vsftpd.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP # 国コード
State or Province Name (full name) [Some-State]:Tokyo # 地域(県)
Locality Name (eg, city) []:Tokyo # 都市
Organization Name (eg, company) [Internet Widgits Pty Ltd]:GTS # 組織名
Organizational Unit Name (eg, section) []:Server World # 組織の部門名
Common Name (e.g. server FQDN or YOUR name) []:test.arkagme.com # サーバーの FQDN
Email Address []:root@arkgame.com # 管理者アドレスげ
Generating a RSA private key .................+++++ ........+++++ writing new private key to 'vsftpd.pem' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:JP # 国コード State or Province Name (full name) [Some-State]:Tokyo # 地域(県) Locality Name (eg, city) []:Tokyo # 都市 Organization Name (eg, company) [Internet Widgits Pty Ltd]:GTS # 組織名 Organizational Unit Name (eg, section) []:Server World # 組織の部門名 Common Name (e.g. server FQDN or YOUR name) []:test.arkagme.com # サーバーの FQDN Email Address []:root@arkgame.com # 管理者アドレスげ
権限を付与する
# chmod 600 redis.pem
2.Redis の SSL/TLS の設定を行う。
# cp /etc/ssl/private/redis.pem /etc/redis/
# chown redis:redis /etc/redis/redis.pem
設定ファイルを編集します
# vi /etc/redis/redis.conf
# 138行目 : 変更 : [0] 指定でリスン無効化
port 0
# 195行目 : コメント解除
tls-port 6379
# 201,202行目 : コメント解除して証明書を指定
tls-cert-file /etc/redis/redis.pem
tls-key-file /etc/redis/redis.pem
# 246行目 : コメント解除
tls-auth-clients no
# systemctl restart redis
# 138行目 : 変更 : [0] 指定でリスン無効化
port 0
# 195行目 : コメント解除
tls-port 6379
# 201,202行目 : コメント解除して証明書を指定
tls-cert-file /etc/redis/redis.pem
tls-key-file /etc/redis/redis.pem
# 246行目 : コメント解除
tls-auth-clients no
# systemctl restart redis
# 138行目 : 変更 : [0] 指定でリスン無効化 port 0 # 195行目 : コメント解除 tls-port 6379 # 201,202行目 : コメント解除して証明書を指定 tls-cert-file /etc/redis/redis.pem tls-key-file /etc/redis/redis.pem # 246行目 : コメント解除 tls-auth-clients no # systemctl restart redis
3.クライアントからの接続です。他ホストから接続する場合は、事前に証明書をクライアントへ転送しておく必要があります。
# ll /etc/redis
total 120
drwxrws--- 2 redis redis 4096 Jun 11 00:32 ./
drwxr-xr-x 109 root root 4096 Jun 11 00:10 ../
-rw-r----- 1 redis redis 106622 Jun 11 00:32 redis.conf
-rw------- 1 redis redis 3160 Jun 11 00:29 redis.pem
# ll /etc/redis
total 120
drwxrws--- 2 redis redis 4096 Jun 11 00:32 ./
drwxr-xr-x 109 root root 4096 Jun 11 00:10 ../
-rw-r----- 1 redis redis 106622 Jun 11 00:32 redis.conf
-rw------- 1 redis redis 3160 Jun 11 00:29 redis.pem
# ll /etc/redis total 120 drwxrws--- 2 redis redis 4096 Jun 11 00:32 ./ drwxr-xr-x 109 root root 4096 Jun 11 00:10 ../ -rw-r----- 1 redis redis 106622 Jun 11 00:32 redis.conf -rw------- 1 redis redis 3160 Jun 11 00:29 redis.pem
# [tls] オプションと証明書を指定して接続する
# redis-cli -h test.arkagme.com --tls \
--cert /etc/redis/redis.pem \
--key /etc/redis/redis.pem \
--cacert /etc/redis/redis.pem
test.arkagme.com:6379> auth password
OK
test.arkagme.com:6379> info
# Server
redis_version:7.0.15
# redis-cli -h test.arkagme.com --tls \
--cert /etc/redis/redis.pem \
--key /etc/redis/redis.pem \
--cacert /etc/redis/redis.pem
test.arkagme.com:6379> auth password
OK
test.arkagme.com:6379> info
# Server
redis_version:7.0.15
# redis-cli -h test.arkagme.com --tls \ --cert /etc/redis/redis.pem \ --key /etc/redis/redis.pem \ --cacert /etc/redis/redis.pem test.arkagme.com:6379> auth password OK test.arkagme.com:6379> info # Server redis_version:7.0.15