Linux下Redis 6.2.6安裝和部署詳細圖文步驟

Redis(Remote Dictionary Server),即遠程字典服務,是一個開源的使用ANSI C語言編寫、支持網絡、可基於內存亦可持久化的日誌型、Key-Value數據庫,並提供多種語言的API。而Redis 6.0引入了SSL、新的 RESP3 協議、ACL、客戶端緩存、無盤副本、I/O 線程、更快的RDB加載、新模塊API和更多改進。

 

1、下載redis6.2.6安裝包

訪問https://redis.io/download地址到官網進行下載,本文已最新版redis6.2.6版本演示安裝和配置。

image.png

直接點擊上圖紅框中下載按鈕,然後通過遠程工具上傳至服務器即可,或者通過wget命令下載。

[root@Java-JingXuan home]# wget https://download.redis.io/releases/redis-6.2.6.tar.gz
--2022-01-16 22:09:18--  https://download.redis.io/releases/redis-6.2.6.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: 2476542 (2.4M) [application/octet-stream]
Saving to: ‘redis-6.2.6.tar.gz’

100%[================================================================================================================================================>] 2,476,542   53.1KB/s   in 40s    

2022-01-16 22:10:00 (61.0 KB/s) - ‘redis-6.2.6.tar.gz’ saved [2476542/2476542]

 

 

2、解壓壓縮文件

解壓redis-6.2.6.tar.gz文件,執行tar -xvf redis-6.2.6.tar.gz命令。

[root@Java-JingXuan home]# tar -xvf redis-6.2.6.tar.gz
...
redis-6.2.6/utils/srandmember/README.md
redis-6.2.6/utils/srandmember/showdist.rb
redis-6.2.6/utils/srandmember/showfreq.rb
redis-6.2.6/utils/systemd-[email protected]
redis-6.2.6/utils/systemd-redis_server.service
redis-6.2.6/utils/tracking_collisions.c
redis-6.2.6/utils/whatisdoing.sh

 

 

3、重命名和移動文件

這裏東哥將安裝目錄移動到/usr/local/目錄下,並將redis-6.2.6重名爲redis目錄,使用mv /home/redis-6.2.6 /usr/local/redis命令,因此有如下操作。

[root@Java-JingXuan home]# mv /home/redis-6.2.6 /usr/local/redis
[root@Java-JingXuan home]# cd /usr/local/redis
[root@Java-JingXuan redis]# ll
total 240
-rw-rw-r--  1 root root 33624 Oct  4 18:59 00-RELEASENOTES
-rw-rw-r--  1 root root    51 Oct  4 18:59 BUGS
-rw-rw-r--  1 root root  5026 Oct  4 18:59 CONDUCT
-rw-rw-r--  1 root root  3384 Oct  4 18:59 CONTRIBUTING
-rw-rw-r--  1 root root  1487 Oct  4 18:59 COPYING
drwxrwxr-x  7 root root  4096 Oct  4 18:59 deps
-rw-rw-r--  1 root root    11 Oct  4 18:59 INSTALL
-rw-rw-r--  1 root root   151 Oct  4 18:59 Makefile
-rw-rw-r--  1 root root  6888 Oct  4 18:59 MANIFESTO
-rw-rw-r--  1 root root 21567 Oct  4 18:59 README.md
-rw-rw-r--  1 root root 93724 Oct  4 18:59 redis.conf
-rwxrwxr-x  1 root root   275 Oct  4 18:59 runtest
-rwxrwxr-x  1 root root   279 Oct  4 18:59 runtest-cluster
-rwxrwxr-x  1 root root  1079 Oct  4 18:59 runtest-moduleapi
-rwxrwxr-x  1 root root   281 Oct  4 18:59 runtest-sentinel
-rw-rw-r--  1 root root 13768 Oct  4 18:59 sentinel.conf
drwxrwxr-x  3 root root  4096 Oct  4 18:59 src
drwxrwxr-x 11 root root  4096 Oct  4 18:59 tests
-rw-rw-r--  1 root root  3055 Oct  4 18:59 TLS.md
drwxrwxr-x  9 root root  4096 Oct  4 18:59 utils

 

 

4、redis編譯安裝

1)redis編譯,執行make命令。

[root@Java-JingXuan redis]# make
cd src && make all
make[1]: Entering directory `/usr/local/redis/src'
    CC Makefile.dep
...
    LINK redis-benchmark
    INSTALL redis-check-rdb
    INSTALL redis-check-aof

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

make[1]: Leaving directory `/usr/local/redis/src'

 

2)redis安裝執行make install命令。

[root@Java-JingXuan redis]# make install
cd src && make install
make[1]: Entering directory `/usr/local/redis/src'
    CC Makefile.dep
make[1]: Leaving directory `/usr/local/redis/src'
make[1]: Entering directory `/usr/local/redis/src'

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

    INSTALL redis-server
    INSTALL redis-benchmark
    INSTALL redis-cli
make[1]: Leaving directory `/usr/local/redis/src'

 

 

5、redis啓動

爲了方便管理,將Redis6.2.6目錄中的conf配置文件和常用命令移動到統一目錄中。

切換至redis根目錄,創建bin和etc文件,將redis.conf文件移動到/usr/local/redis/etc/目錄,將mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server 文件移動到/usr/local/redis/bin/目錄。

[root@Java-JingXuan redis]# mkdir etc
[root@Java-JingXuan redis]# mkdir bin
[root@Java-JingXuan redis]# mv redis.conf /usr/local/redis/etc/
[root@Java-JingXuan redis]# cd src/
[root@Java-JingXuan src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server /usr/local/redis/bin/
[root@Java-JingXuan src]# ll ../bin/
total 37524
-rwxrwxr-x 1 root root     735 Oct  4 18:59 mkreleasehdr.sh
-rwxr-xr-x 1 root root 4829472 Jan 16 22:30 redis-benchmark
-rwxr-xr-x 1 root root 9524032 Jan 16 22:30 redis-check-aof
-rwxr-xr-x 1 root root 9524032 Jan 16 22:30 redis-check-rdb
-rwxr-xr-x 1 root root 5003752 Jan 16 22:30 redis-cli
-rwxr-xr-x 1 root root 9524032 Jan 16 22:30 redis-server

 

執行redis-server命令,啓動redis服務。另外,更多其他軟件安裝配置步驟,如mysql、kafka、fastdfs、elasticsearch各種版本等中間件安裝配置圖文步驟,公衆號Java精選,回覆中間件三個漢字,獲取所有軟件安裝步驟。切勿亂回覆,否則什麼也沒有!!!

[root@Java-JingXuan redis]# ./bin/redis-server 
26344:C 16 Jan 2022 22:38:18.616 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
26344:C 16 Jan 2022 22:38:18.617 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=26344, just started
26344:C 16 Jan 2022 22:38:18.617 # Warning: no config file specified, using the default config. In order to specify a config file use ./bin/redis-server /path/to/redis.conf
26344:M 16 Jan 2022 22:38:18.617 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 26344
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

26344:M 16 Jan 2022 22:38:18.618 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
26344:M 16 Jan 2022 22:38:18.618 # Server initialized
26344:M 16 Jan 2022 22:38:18.618 # 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.
26344:M 16 Jan 2022 22:38:18.618 * Ready to accept connections

 

 

6、設置後臺啓動redis

編輯redis.conf文件,將daemonize屬性改爲yes,執行vim /usr/local/redis/etc/redis.conf命令。

[root@Java-JingXuan redis]# vim /usr/local/redis/etc/redis.conf

 

image.png

執行./bin/redis-server /usr/local/redis/etc/redis.conf命令,啓動redis服務。

[root@Java-JingXuan redis]# ./bin/redis-server /usr/local/redis/etc/redis.conf

 

7、設置redis密碼

編輯redis.conf文件,找到requirepass這個參數,若是沒有增加requirepass參數並設置密碼參考如下圖所示,執行vim /usr/local/redis/etc/redis.conf命令。

image.png

保存後,重啓redis服務即可生效。

 

8、設置redis服務遠程訪問

編輯redis.conf文件,找到bind 127.0.0.1 -::1配置,將用#號註釋掉即可,參考如下圖所示。

image.png

然後執行ps -ef|grep redis命令,找到已啓動的redis服務,使用kill命令殺掉redis服務進程。再執行./bin/redis-server /usr/local/redis/etc/redis.conf命令,啓動redis服務。

[root@Java-JingXuan redis]# ps -ef|grep redis
root     27715     1  0 22:45 ?        00:00:00 ./bin/redis-server 127.0.0.1:6379
root     29297 25962  0 22:53 pts/4    00:00:00 grep --color=auto redis
[root@Java-JingXuan redis]# kill -9 27715
[root@Java-JingXuan redis]# ./bin/redis-server /usr/local/redis/etc/redis.conf
[root@Java-JingXuan redis]# ps -ef|grep redis
root     29323     1  0 22:53 ?        00:00:00 ./bin/redis-server *:6379
root     29357 25962  0 22:54 pts/4    00:00:00 grep --color=auto redis

 

使用連接redis服務的客戶端連接測試,如下圖所示表示連接成功。

image.png

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章