このセクションでは、インメモリベースのキーバリューモデル型の NoSQL データベース(メモリ上のデータを保存する)である Redis のインストールについて紹介します。

yum の epel レポジトリをインストールします。

[root@localhost ~]# yum -y install epel-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.jaist.ac.jp
 * extras: ftp.jaist.ac.jp
 * updates: ftp.jaist.ac.jp
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch             Version         Repository        Size
================================================================================
Installing:
 epel-release           noarch           7-11            extras            15 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
epel-release-7-11.noarch.rpm                               |  15 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                     1/1 
  Verifying  : epel-release-7-11.noarch                                     1/1 

Installed:
  epel-release.noarch 0:7-11                                                    

Complete!
[root@localhost ~]# 

yum の remi レポジトリをインストールします。

[root@localhost ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Retrieving http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
warning: /var/tmp/rpm-tmp.McPiL2: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:remi-release-7.6-1.el7.remi      ################################# [100%]
[root@localhost ~]# 

epel と remi レポジトリを無効化しておきます。これらレポジトリは、必要な時にオプションで指定して使用するようにします。

[root@localhost ~]# sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/epel*
[root@localhost ~]#
[root@localhost ~]# sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/remi* [root@localhost ~]#

epel と remi レポジトリが無効化されていることを確認します。

[root@localhost ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.jaist.ac.jp
 * extras: ftp.jaist.ac.jp
 * updates: ftp.jaist.ac.jp
repo id                          repo name                       status
C7.0.1406-base/x86_64            CentOS-7.0.1406 - Base          disabled
C7.0.1406-centosplus/x86_64      CentOS-7.0.1406 - CentOSPlus    disabled
C7.0.1406-extras/x86_64          CentOS-7.0.1406 - Extras        disabled
C7.0.1406-fasttrack/x86_64       CentOS-7.0.1406 - Fasttrack     disabled
C7.0.1406-updates/x86_64         CentOS-7.0.1406 - Updates       disabled
C7.1.1503-base/x86_64            CentOS-7.1.1503 - Base          disabled
C7.1.1503-centosplus/x86_64      CentOS-7.1.1503 - CentOSPlus    disabled
C7.1.1503-extras/x86_64          CentOS-7.1.1503 - Extras        disabled
C7.1.1503-fasttrack/x86_64       CentOS-7.1.1503 - Fasttrack     disabled
C7.1.1503-updates/x86_64         CentOS-7.1.1503 - Updates       disabled
C7.2.1511-base/x86_64            CentOS-7.2.1511 - Base          disabled
C7.2.1511-centosplus/x86_64      CentOS-7.2.1511 - CentOSPlus    disabled
C7.2.1511-extras/x86_64          CentOS-7.2.1511 - Extras        disabled
C7.2.1511-fasttrack/x86_64       CentOS-7.2.1511 - Fasttrack     disabled
C7.2.1511-updates/x86_64         CentOS-7.2.1511 - Updates       disabled
C7.3.1611-base/x86_64            CentOS-7.3.1611 - Base          disabled
C7.3.1611-centosplus/x86_64      CentOS-7.3.1611 - CentOSPlus    disabled
C7.3.1611-extras/x86_64          CentOS-7.3.1611 - Extras        disabled
C7.3.1611-fasttrack/x86_64       CentOS-7.3.1611 - Fasttrack     disabled
C7.3.1611-updates/x86_64         CentOS-7.3.1611 - Updates       disabled
C7.4.1708-base/x86_64            CentOS-7.4.1708 - Base          disabled
C7.4.1708-centosplus/x86_64      CentOS-7.4.1708 - CentOSPlus    disabled
C7.4.1708-extras/x86_64          CentOS-7.4.1708 - Extras        disabled
C7.4.1708-fasttrack/x86_64       CentOS-7.4.1708 - Fasttrack     disabled
C7.4.1708-updates/x86_64         CentOS-7.4.1708 - Updates       disabled
C7.5.1804-base/x86_64            CentOS-7.5.1804 - Base          disabled
C7.5.1804-centosplus/x86_64      CentOS-7.5.1804 - CentOSPlus    disabled
C7.5.1804-extras/x86_64          CentOS-7.5.1804 - Extras        disabled
C7.5.1804-fasttrack/x86_64       CentOS-7.5.1804 - Fasttrack     disabled
C7.5.1804-updates/x86_64         CentOS-7.5.1804 - Updates       disabled
base/7/x86_64                    CentOS-7 - Base                 enabled: 10,019
base-debuginfo/x86_64            CentOS-7 - Debuginfo            disabled
base-source/7                    CentOS-7 - Base Sources         disabled
c7-media                         CentOS-7 - Media                disabled
centosplus/7/x86_64              CentOS-7 - Plus                 disabled
centosplus-source/7              CentOS-7 - Plus Sources         disabled
cr/7/x86_64                      CentOS-7 - cr                   disabled
epel/x86_64                      Extra Packages for Enterprise L disabled
epel-debuginfo/x86_64            Extra Packages for Enterprise L disabled
epel-source/x86_64               Extra Packages for Enterprise L disabled
epel-testing/x86_64              Extra Packages for Enterprise L disabled
epel-testing-debuginfo/x86_64    Extra Packages for Enterprise L disabled
epel-testing-source/x86_64       Extra Packages for Enterprise L disabled
extras/7/x86_64                  CentOS-7 - Extras               enabled:    321
extras-source/7                  CentOS-7 - Extras Sources       disabled
fasttrack/7/x86_64               CentOS-7 - fasttrack            disabled
remi                             Remi's RPM repository for Enter disabled
remi-debuginfo/x86_64            Remi's RPM repository for Enter disabled
remi-glpi91                      Remi's GLPI 9.1 RPM repository  disabled
remi-glpi92                      Remi's GLPI 9.2 RPM repository  disabled
remi-glpi93                      Remi's GLPI 9.3 RPM repository  disabled
remi-glpi94                      Remi's GLPI 9.4 RPM repository  disabled
remi-php54                       Remi's PHP 5.4 RPM repository f disabled
remi-php55                       Remi's PHP 5.5 RPM repository f disabled
remi-php55-debuginfo/x86_64      Remi's PHP 5.5 RPM repository f disabled
remi-php56                       Remi's PHP 5.6 RPM repository f disabled
remi-php56-debuginfo/x86_64      Remi's PHP 5.6 RPM repository f disabled
remi-php70                       Remi's PHP 7.0 RPM repository f disabled
remi-php70-debuginfo/x86_64      Remi's PHP 7.0 RPM repository f disabled
remi-php70-test                  Remi's PHP 7.0 test RPM reposit disabled
remi-php70-test-debuginfo/x86_64 Remi's PHP 7.0 test RPM reposit disabled
remi-php71                       Remi's PHP 7.1 RPM repository f disabled
remi-php71-debuginfo/x86_64      Remi's PHP 7.1 RPM repository f disabled
remi-php71-test                  Remi's PHP 7.1 test RPM reposit disabled
remi-php71-test-debuginfo/x86_64 Remi's PHP 7.1 test RPM reposit disabled
remi-php72                       Remi's PHP 7.2 RPM repository f disabled
remi-php72-debuginfo/x86_64      Remi's PHP 7.2 RPM repository f disabled
remi-php72-test                  Remi's PHP 7.2 test RPM reposit disabled
remi-php72-test-debuginfo/x86_64 Remi's PHP 7.2 test RPM reposit disabled
remi-php73                       Remi's PHP 7.3 RPM repository f disabled
remi-php73-debuginfo/x86_64      Remi's PHP 7.3 RPM repository f disabled
remi-php73-test                  Remi's PHP 7.3 test RPM reposit disabled
remi-php73-test-debuginfo/x86_64 Remi's PHP 7.3 test RPM reposit disabled
remi-safe                        Safe Remi's RPM repository for  disabled
remi-safe-debuginfo/x86_64       Remi's RPM repository for Enter disabled
remi-test                        Remi's test RPM repository for  disabled
remi-test-debuginfo/x86_64       Remi's test RPM repository for  disabled
updates/7/x86_64                 CentOS-7 - Updates              enabled:    624
updates-source/7                 CentOS-7 - Updates Sources      disabled
repolist: 10,964
[root@localhost ~]#

epel と remi レポジトリを指定して、yum でインストールできる Redis の情報を確認します。ここでは、バージョン 5.0.3 の Redis が yum でインストールできることが確認できます。

[root@localhost ~]# yum info --enablerepo=epel,remi redis
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                     | 9.3 kB     00:00     
 * base: ftp.jaist.ac.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.jaist.ac.jp
 * remi: ftp.riken.jp
 * updates: ftp.jaist.ac.jp
remi                                                     | 3.0 kB     00:00     
remi/primary_db                                            | 2.3 MB   00:04     
Available Packages
Name        : redis
Arch        : x86_64
Version     : 5.0.3
Release     : 1.el7.remi
Size        : 919 k
Repo        : remi
Summary     : A persistent key-value database
URL         : http://redis.io
License     : BSD
Description : Redis is an advanced key-value store. It is often referred to as a
            : data structure server since keys can contain strings, hashes,
            : lists, sets and sorted sets.
            : 
            : You can run atomic operations on these types, like appending to a
            : string; incrementing the value in a hash; pushing to a list;
            : computing set intersection, union and difference; or getting the
            : member with highest ranking in a sorted set.
            : 
            : In order to achieve its outstanding performance, Redis works with
            : an in-memory dataset. Depending on your use case, you can persist
            : it either by dumping the dataset to disk every once in a while, or
            : by appending each command to a log.
            : 
            : Redis also supports trivial-to-setup master-slave replication,
            : with very fast non-blocking first synchronization,
            : auto-reconnection on net split and so forth.
            : 
            : Other features include Transactions, Pub/Sub, Lua scripting, Keys
            : with a limited time-to-live, and configuration settings to make
            : Redis behave like a cache.
            : 
            : You can use Redis from most programming languages also.

[root@localhost ~]# 

epel、remi レポジトリを指定して redis をインストールします。

[root@localhost ~]# yum install --enablerepo=epel,remi redis
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.jaist.ac.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.jaist.ac.jp
 * remi: ftp.riken.jp
 * updates: ftp.jaist.ac.jp
Resolving Dependencies
--> Running transaction check
---> Package redis.x86_64 0:5.0.3-1.el7.remi will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package        Arch            Version                     Repository     Size
================================================================================
Installing:
 redis          x86_64          5.0.3-1.el7.remi            remi          919 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 919 k
Installed size: 3.0 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/remi/packages/redis-5.0.3-1.el7.remi.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Public key for redis-5.0.3-1.el7.remi.x86_64.rpm is not installed
redis-5.0.3-1.el7.remi.x86_64.rpm                          | 919 kB   00:01     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Importing GPG key 0x00F97F56:
 Userid     : "Remi Collet <RPMS@FamilleCollet.com>"
 Fingerprint: 1ee0 4cce 88a4 ae4a a29a 5df5 004e 6f47 00f9 7f56
 Package    : remi-release-7.6-1.el7.remi.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : redis-5.0.3-1.el7.remi.x86_64                                1/1 
  Verifying  : redis-5.0.3-1.el7.remi.x86_64                                1/1 

Installed:
  redis.x86_64 0:5.0.3-1.el7.remi                                               

Complete!
[root@localhost ~]# 

redis がインストールされていることを確認します。

[root@localhost ~]# rpm -qa | grep redis
redis-5.0.3-1.el7.remi.x86_64
[root@localhost ~]# 

redis サービスの自動起動を有効化します。

■ 自動起動の有効化
[root@localhost ~]# systemctl enable redis.service
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
[root@localhost ~]# 

■ 自動起動の状態確認
[root@localhost ~]# systemctl is-enabled redis.service
enabled
[root@localhost ~]# 

redis サービスを起動します。

■ 起動
[root@localhost ~]# systemctl start redis
[root@localhost ~]# 

■ 起動状態の確認 
[root@localhost ~]# systemctl status redis
● redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: active (running) since 土 2019-01-19 20:20:53 JST; 1s ago
 Main PID: 1371 (redis-server)
   CGroup: /system.slice/redis.service
           └─1371 /usr/bin/redis-server *:6379

 1月 19 20:20:53 localhost.localdomain systemd[1]: Starting Redis persistent...
 1月 19 20:20:53 localhost.localdomain systemd[1]: Started Redis persistent ...
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# 

redis で必要となる TCP 6379 通信をファイアウォールで許可します。

■ TCP 6379 を許可する設定
[root@localhost ~]# firewall-cmd --add-port=6379/tcp --zone=public --permanentsuccess
[root@localhost ~]# 

■ ファイアウォールでの許可状況の確認
[root@localhost ~]# firewall-cmd --list-port --zone=public --permanent
6379/tcp
[root@localhost ~]# 

■ 設定の反映
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]#