Ubuntu LinuxにRedisサーバーをインストールする方法を学びたいですか? このチュートリアルでは、Ubuntu LinuxにRedisサーバーをインストールして設定するために必要なすべての手順を説明します。

•Ubuntu Linuxバージョン18.04

関連チュートリアル:

このページでは、Ubuntu Linuxに関連したチュートリアルのリストにすばやくアクセスできます。

NTPを使用して日付と時刻を設定する

NTPを使用して正しい日付と時刻を使用するようにシステムを構成します。

Linuxコンソールで、以下のコマンドを使用して正しいタイムゾーンを設定します。

# dpkg-reconfigure tzdata

Ntpdateパッケージをインストールして、正しい日付と時刻をすぐに設定してください。

# apt-get update
# apt-get install ntpdate
# ntpdate pool.ntp.br

Ntpdateコマンドを使用して、サーバーを使用して正しい日付と時刻を設定しました。pool.ntp.br

NTPサービスをインストールしましょう。

# timedatectl set-ntp 0
# apt-get install ntp

NTPは私達のサーバーを常に最新の状態に保つサービスです。

Ubuntu Linuxに設定されている日時を確認するには、dateコマンドを使用します。

# date

2. Redis Serverをインストールする

Linuxコンソールで、以下のコマンドを使用してRedisサーバーパッケージをインストールします。

# apt-get update
# apt-get install redis-server

今、あなたはsysctl.confファイルを編集する必要があります。

# vi /etc/sysctl.conf

ファイルの末尾に次の行を追加します。

vm.overcommit_memory=1
net.core.somaxconn=65535
fs.file-max=100000

次のコマンドを入力して設定ファイルをリロードします。

# sysctl -p
# echo never > /sys/kernel/mm/transparent_hugepage/enabled

これで、システム上のredis.confファイルの場所がわかりました。

見つけたら、redis.confファイルを編集する必要があります。

# updatedb
# locate redis.conf

# vi /etc/redis/redis.conf

これが私たちの設定の前で、コメントなしのオリジナルファイルです。

bind 127.0.0.1 ::1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis/redis-server.pid
loglevel notice
logfile /var/log/redis/redis-server.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

設定ファイルに次の行を追加します。

maxmemory 1024mb
maxmemory-policy allkeys-lru

この例では、Redisサービス用に1GBのRAMを予約します。

以下の既存の構成行を変更します。

supervised systemd
bind 127.0.0.1 ::1

これが私たちの設定による新しいファイルです。

bind 127.0.0.1 ::1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised systemd
pidfile /var/run/redis/redis-server.pid
loglevel notice
logfile /var/log/redis/redis-server.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
maxmemory 1024mb
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

Redisサービスを再起動します。

起動中にRedisサービスを有効にします。

コンピュータを再起動して自動起動をテストします。

RedisサービスはTCPポート6379で提供されています。

# service redis-server status
# systemctl enable redis-server
# reboot

ローカルにApacheとPHPがある場合は、次のコマンドを使用して必要なPHPモジュールをインストールしてください。

# apt-get install php-redis
# service apache2 restart
# /etc/init.d/php7.2-fpm restart

3. Redisサーバーをテストする

Linuxコンソールで、次のコマンドを使用してRedisサービスをテストします。

# redis-cli
> ping
> set MYSITE "Techexpert.Tips"
> get MYSITE
> exit

Redisサービスのパフォーマンスをテストします。

# redis-benchmark -q -n 1000 -c 10 -P 5

PING_INLINE: 142857.14 requests per second
PING_BULK: 142857.14 requests per second
SET: 142857.14 requests per second
GET: 124999.99 requests per second
INCR: 124999.99 requests per second
LPUSH: 142857.14 requests per second
RPUSH: 142857.14 requests per second
LPOP: 124999.99 requests per second
RPOP: 124999.99 requests per second
SADD: 124999.99 requests per second
HSET: 124999.99 requests per second
SPOP: 142857.14 requests per second
LPUSH (needed to benchmark LRANGE): 124999.99 requests per second
LRANGE_100 (first 100 elements): 47619.05 requests per second
LRANGE_300 (first 300 elements): 14925.37 requests per second
LRANGE_500 (first 450 elements): 9433.96 requests per second
LRANGE_600 (first 600 elements): 6578.95 requests per second
MSET (10 keys): 100000.00 requests per second

おめでとうございます。 これでRedisサーバーのインストールは完了です。