1. 程式人生 > 實用技巧 >02_Redis入門介紹--3_Redis的安裝

02_Redis入門介紹--3_Redis的安裝

目錄

一、下載redis(這裡以redis-6.0.6為例)

下載路徑

安裝下載工具wget
yum install wget

直接使用 wget 在 centos7 上下載
wget http://download.redis.io/releases/redis-6.0.6.tar.gz

使用如下方式,需要先在windows下載,然後上傳到linux中的 opt 目錄下

官網 :https://redis.io 或 http://www.redis.cn/

二、安裝redis

1、解壓

tar -zxvf  redis-6.0.6.tar.gz

2、進入redis-6.0.6目錄

cd redis-6.0.6

3、編譯

make

4、問題

使用 make 會出現錯誤,原因是沒有 gcc 編譯環境,或 gcc 版本太低。

5、辦法

安裝高版本的 gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
source /opt/rh/devtoolset-9/enable
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

6、刪除剛才出錯的檔案

make distclean

7、將redis安裝到 /usr/local/redis 目錄下

make install PREFIX=/usr/local/redis

8、檢視安裝結果

ll /usr/local/redis/bin
-rwxr-xr-x. 1 root root 4739824 7月  28 13:38 redis-benchmark
-rwxr-xr-x. 1 root root 9653552 7月  28 13:38 redis-check-aof
-rwxr-xr-x. 1 root root 9653552 7月  28 13:38 redis-check-rdb
-rwxr-xr-x. 1 root root 5059024 7月  28 13:38 redis-cli
lrwxrwxrwx. 1 root root      12 7月  28 13:38 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 9653552 7月  28 13:38 redis-server

三、測試

1、檢視解壓 redis-6.0.6.tar.gz後的目錄

ll /opt/redis-6.0.6
-rw-rw-r--.  1 root root 80561 7月  21 02:08 00-RELEASENOTES
-rw-rw-r--.  1 root root    51 7月  21 02:08 BUGS
-rw-rw-r--.  1 root root  2381 7月  21 02:08 CONTRIBUTING
-rw-rw-r--.  1 root root  1487 7月  21 02:08 COPYING
drwxrwxr-x.  6 root root   192 7月  28 13:15 deps
-rw-r--r--.  1 root root   107 7月  28 14:01 dump.rdb
-rw-rw-r--.  1 root root    11 7月  21 02:08 INSTALL
-rw-rw-r--.  1 root root   151 7月  21 02:08 Makefile
-rw-rw-r--.  1 root root  6888 7月  21 02:08 MANIFESTO
-rw-rw-r--.  1 root root 20806 7月  21 02:08 README.md

# 注意不要修改原版的配置
-rw-rw-r--.  1 root root 83392 7月  21 02:08 redis.conf

-rwxrwxr-x.  1 root root   275 7月  21 02:08 runtest
-rwxrwxr-x.  1 root root   280 7月  21 02:08 runtest-cluster
-rwxrwxr-x.  1 root root   679 7月  21 02:08 runtest-moduleapi
-rwxrwxr-x.  1 root root   281 7月  21 02:08 runtest-sentinel
-rw-rw-r--.  1 root root 10743 7月  21 02:08 sentinel.conf
drwxrwxr-x.  3 root root  8192 7月  28 13:38 src
drwxrwxr-x. 11 root root   182 7月  21 02:08 tests
-rw-rw-r--.  1 root root  3055 7月  21 02:08 TLS.md
drwxrwxr-x.  9 root root  4096 7月  21 02:08 utils

2、建立 myredis目錄, 儲存 redis.conf

mkdir /myredis

3、複製redis.conf

cp /usr/local/redis/redis.conf  /myredis/

4、進入 myredis 目錄

cd /myredis

5、修改 /myredis/redis.conf 檔案(找到GENERAL中的 daemonize no,將 no 改為 yes)

vim redis.conf

218 ################################# GENERAL #####################################
 219 
 220 # By default Redis does not run as a daemon. Use 'yes' if you need it.
 221 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
 
 222 daemonize yes
 
 223 
 224 # If you run Redis from upstart or systemd, Redis can interact with your
 225 # supervision tree. Options:
 226 #   supervised no      - no supervision interaction
 227 #   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
 228 #   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
 229 #   supervised auto    - detect upstart or systemd method based on
 230 #                        UPSTART_JOB or NOTIFY_SOCKET environment variables
 231 # Note: these supervision methods only signal "process is ready."
 232 #       They do not enable continuous liveness pings back to your supervisor.
 233 supervised no
 234 
 235 # If a pid file is specified, Redis writes it where specified at startup

6、到 /usr/local/redis/bin 目錄下

cd /usr/local/redis/bin

7、載入 /myredis/redis.conf檔案

./redis-server /myredis/redis.conf
1511:C 29 Jul 2020 13:37:36.613 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1511:C 29 Jul 2020 13:37:36.613 # Redis version=6.0.6, bits=64, commit=00000000, modified=0, pid=1511, just started
1511:C 29 Jul 2020 13:37:36.613 # Configuration loaded

8、測試是否安裝成功

./redis-cli -p 6379

9、顯示結果

[root@hadoop1 bin]# ./redis-cli -p 6379
127.0.0.1:6379>