Ubuntu19.10 最新Redisをインストールする

Ubuntu19.10 最新Redisをインストールする

nosqlの1つである、インメモリの KVS( KeyとValueを組み合わた構造 Key-Value Store )であるRedisをUbuntuに導入する手順

環境

  • OS  Ubuntu19.10
  • Redis  5.0.5

インストール

こちらの公式に従いインストールを行う

## ダウンロード
wget http://download.redis.io/releases/redis-5.0.5.tar.gz

## 解凍
tar xzf redis-5.0.5.tar.gz

## 移動
cd redis-5.0.5

## ビルド
make

起動

redisを起動してみる

## 起動
src/redis-server

<出力結果>
# WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
# Server initialized
# WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
# WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
* DB loaded from disk: 0.000 seconds
* Ready to accept connections

WARNINGが幾つが発生しますが、とりあえず無視して、別ターミナルからCLIを利用

## 解凍したredis-5.0.5まで移動
cd redis-5.0.5

## cli実行
src/redis-cli

> set foo bar
OK
> get foo
"bar"
> exit

Warningに対応

warningに記述されている通りに対応する

## rootで作業
sudo su -

下記の2つのwarningに対応する

① WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

net.core.somaxconn設定値が128になっているので接続不可になる可能性がある

② WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.

overcommit_memory が0なのでメモリに空きがなくなると強制的に終了される設定になっているので、メモリーとスワップの総量以上に扱えるように sysctl vm.overcommit_memory=1 に設定した方がいいと言っている

ので /etc/sysctl.conf を編集する

## 編集
vi /etc/sysctl.conf

下記を追加する

vm.overcommit_memory = 1
net.core.somaxconn = 511

反映させる

## 永続的に反映させる
sysctl -p

次に3つ目の警告に対応する

③ WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

THPを無効にした方がいいと言ってるので 無効にする

※下記コマンドの場合、再起動した場合、有効に戻ります。

echo never > /sys/kernel/mm/transparent_hugepage/enabled

再度起動してみる

## 起動
src/redis-server

<WARNINGがなくなったことが確認できる>
# Server initialized
* DB loaded from disk: 0.000 seconds
* Ready to accept connections