仮想計算機構

IT業界と無縁な派遣社員のブログ

Redis をソースからインストールする

環境

$ cat /etc/issue
Ubuntu 22.04.3 LTS \n \l

インストール

ダウンロード

下記参考にソースをダウンロードします。
Install Redis from Source | Redis

$ wget https://download.redis.io/redis-stable.tar.gz
--2023-09-20 19:12:43--  https://download.redis.io/redis-stable.tar.gz
Resolving download.redis.io (download.redis.io)... 45.60.125.1
Connecting to download.redis.io (download.redis.io)|45.60.125.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3477351 (3.3M) [application/octet-stream]
Saving to: 'redis-stable.tar.gz'

redis-stable.tar.gz      100%[==================================>]   3.32M  --.-KB/s    in 0.05s
2023-09-20 19:12:44 (70.1 MB/s) - 'redis-stable.tar.gz' saved [3477351/3477351]

解凍

$ tar -xzvf redis-stable.tar.gz
redis-stable/
redis-stable/src/
redis-stable/src/geohash.h
redis-stable/src/redis-trib.rb
redis-stable/src/t_string.c
(省略)

ビルド

make します。

$ cd redis-stable
redis-stable$ make

一応 make test しておきます。

redis-stable$ make test
(省略)
\o/ All tests passed without errors!
(省略)

管理者権限で make install します。

redis-stable$ sudo make install
cd src && make install
(省略)

Hint: It's a good idea to run 'make test' ;)

    INSTALL redis-server
    INSTALL redis-benchmark
    INSTALL redis-cli
(省略)

インストールされたものを確認します。

redis-stable$ ls /usr/local/bin/
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server

起動とシャットダウン

バージョン確認

$ redis-server -v
Redis server v=7.2.1 sha=00000000:0 malloc=jemalloc-5.3.0 bits=64 build=fce2f1bf15001fdc
$ redis-cli -v
redis-cli 7.2.1

サーバの起動

$ redis-server &
[1] 52809
(省略):~$ 52809:C 20 Sep 2023 21:08:37.630 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.
52809:C 20 Sep 2023 21:08:37.631 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
52809:C 20 Sep 2023 21:08:37.631 * Redis version=7.2.1, bits=64, commit=00000000, modified=0, pid=52809, just started
52809:C 20 Sep 2023 21:08:37.631 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
52809:M 20 Sep 2023 21:08:37.632 * Increased maximum number of open files to 10032 (it was originally set to 1024).
52809:M 20 Sep 2023 21:08:37.632 * monotonic clock: POSIX clock_gettime
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 7.2.1 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 52809
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           https://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

52809:M 20 Sep 2023 21:08:37.635 * Server initialized
52809:M 20 Sep 2023 21:08:37.635 * Ready to accept connections tcp

プロセスの確認

$ ps
    PID TTY          TIME CMD
  52788 pts/0    00:00:00 bash
  52809 pts/0    00:00:00 redis-server
  52814 pts/0    00:00:00 ps

サーバから返答があるか確認する

$ redis-cli ping
PONG

サーバを終了する

$ redis-cli shutdown
52809:M 20 Sep 2023 21:09:03.298 * User requested shutdown...
52809:M 20 Sep 2023 21:09:03.298 * Saving the final RDB snapshot before exiting.
52809:M 20 Sep 2023 21:09:03.301 * DB saved on disk
52809:M 20 Sep 2023 21:09:03.301 # Redis is now ready to exit, bye bye...
[1]+  Done                    redis-server

プロセスの確認

$ ps
    PID TTY          TIME CMD
  52788 pts/0    00:00:00 bash
  52817 pts/0    00:00:00 ps