1. 程式人生 > >Linux下安裝Redis4.0版本(簡便方法)

Linux下安裝Redis4.0版本(簡便方法)

 

 

Redis介紹:

Redis 是完全開源免費的,遵守BSD協議,是一個高效能的key-value資料庫。

Redis 與其他 key - value 快取產品有以下三個特點:

  • Redis支援資料的持久化RDB和AOF,可以將記憶體中的資料儲存在磁碟中,重啟的時候可以再次載入進行使用。
  • Redis不僅僅支援簡單的key-value型別的資料,同時還提供list,set,zset,hash等資料結構的儲存。
  • Redis支援資料的備份,即master-slave模式的資料備份。
  • 效能極高 – Redis能讀的速度是110000次/s,寫的速度是81000次/s 。
  • 豐富的資料型別 – Redis支援二進位制案例的 Strings, Lists, Hashes, Sets 及 Ordered Sets 資料型別操作。
  • 原子 – Redis的所有操作都是原子性的,意思就是要麼成功執行要麼失敗完全不執行。單個操作是原子性的。多個操作也支援事務,即原子性,通過MULTI和EXEC指令包起來。
  • 豐富的特性 – Redis還支援 publish/subscribe, 通知, key 過期等等特性。

安裝環境:

作業系統:CentOS Linux release 7.7.1908 (Core)

IP地址:192.168.85.16

環境準備:

yum install -y openssl gcc

 

Redis安裝:

官網地址:http://redis.io/download

下載最新穩定版本。

本文章用到的是4.0.11版本,下載並安裝:

cd /data
wget http://download.redis.io/releases/redis-4.0.11.tar.gz tar zxvf redis-4.0.11.tar.gz

新增使用者:

[root@localhost data]# useradd  -M  -s /sbin/nologin  redis
#檢視redisid資訊:
[root@localhost data]# id redis
uid=1000(redis) gid=1000(redis) groups=1000(redis)
#設定redis使用者密碼
[root@localhost data]# passwd redis

建立相關目錄:

[root@localhost conf]# mkdir -p /data/redis/{log,conf,data}
[root@localhost conf]# chown -R redis:redis /data/redis

編譯安裝:

[root@localhost redis-4.0.11]# pwd
/data/redis-4.0.11
[root@localhost redis-4.0.11]# make
[root@localhost redis-4.0.11]# cd src/
#指定編譯安裝路徑
[root@localhost src]# make PREFIX=/data/redis install
[root@localhost src]# cp ../redis.conf /data/redis/conf

配置環境變數:

[root@localhost src]# vi ~/.bash_profile
[root@localhost src]# PATH=$PATH:$HOME/.local/bin:/data/redis/bin:$HOME/bin
[root@localhost src]# source ~/.bash_profile

調整redis配置檔案:

這個按需設定,我這裡列出僅供參考基本的引數

[root@localhost src]# vi /data/redis/conf/redis.conf
#daemonize yes #守護程序模式
daemonize yes
#日誌檔案目錄
logfile "/data/redis/log/redis.log"
#redis密碼
requirepass tse123
bind 192.168.85.16

啟停redis服務:

[root@localhost log]# /data/redis/bin/redis-server /data/redis/conf/redis.conf
#檢視服務是否啟動成功
[root@localhost log]# netstat -lntp|grep redis
tcp        0      0 192.168.85.16:6379      0.0.0.0:*               LISTEN      5613/redis-server 1 
#停止redis例項服務
/data/redis/bin/redis-cli -a 密碼 shutdown

客戶端連線測試:

[root@localhost log]# /data/redis/bin/redis-cli -h 192.168.85.16 -p 6379 -a 密碼
Warning: Using a password with '-a' option on the command line interface may not be safe.
192.168.85.16:6379> PING
PONG
192.168.85.16:6379> 

&n