centos7安裝redis

1.1 系統環境和版本說明

Redis的版本選取目前的穩定版本2.8.9。 客戶端選用了Redis的Java版本jedis 2.4.2。

1.2 Redis的安裝步驟

a. 進入root目錄,並下載Redis的安裝包

[html] view plain copy
 print?
  1. $ cd  
  2.   
  3. $ wget http://labfile.oss.aliyuncs.com/files0422/redis-2.8.9.tar.gz  

操作截圖:


b. 在目錄下,解壓按照包,生成新的目錄redis-2.8.9

[plain] view plain copy
 print?
  1. $ tar xvfz redis-2.8.9.tar.gz  

c. 進入解壓之後的目錄,進行編譯

[plain] view plain copy
 print?
  1. $ cd redis-2.8.9  
  2. $ make  
  3. $ make install  
說明: 如果沒有明顯的錯誤,則表示編譯成功



e. 在安裝成功之後,可以運行測試,確認Redis的功能是否正常

[plain] view plain copy
 print?
  1. $ make test  
操作截圖:



2、Redis啓動

2.1查看重要文件

在 Redis 安裝完成後,注意一些重要的文件,可用 ls 命令查看。服務端:src/redis-server,客戶端:src/redis-cls,默認配置文件:redis.conf

[plain] view plain copy
 print?
  1. $ ls  
  2. $ cd src  
  3. $ ls  

操作截圖:


2.2 、然後將可執行文件放置在$PATH環境目錄下,便於以後執行程序時可以不用輸入完整的路徑,

[plain] view plain copy
 print?
  1. $ cp redis-server /usr/local/bin/  
  2. $ cp redis-cli /usr/local/bin/  

2.3、啓動Redis-server

[plain] view plain copy
 print?
  1. $ redis-server  

操作截圖:


說明: 從以上的截圖中,可以發現啓動的端口爲缺省的6379. 用戶可以在啓動的時候,指定具體的配置文件,並在其中指定啓動的端口。

保持此終端的運行,Ctrl+shift+t 重開一個終端tab。


2.4、查看Redis

[plain] view plain copy
 print?
  1. $ ps -ef | grep redis  

操作截圖:


[plain] view plain copy
 print?
  1. # 通過啓動命令檢查Redis服務器狀態  
  2. $ netstat -nlt|grep 6379  

操作截圖:




2.5、啓動Redis-client

[plain] view plain copy
 print?
  1. $ su    ( 輸入root密碼,進入root目錄)  
  2.   
  3. $ cd  
  4.   
  5. $ redis-cli  

操作截圖:



上面的啓動方式是有點問題的,只能在redis的安裝包下面的src目錄啓動纔可以,如果是關閉服務端的cmd窗口,跟着redis服務也就關閉了,這種並不是我們想看到的,然而我們希望不管服務端的cmd窗口是否打開,redis的服務正常運行,那麼我們需要進行以下幾步即可:

1、我們要把src目錄下面的redis-cli、redis-server、redis-sentinel移到/usr/bin目錄下面

[plain] view plain copy
 print?
  1. root@localhost:/opt/deploy/redis-3.0.0-rc1# cd src  
  2. root@localhost:/opt/deploy/redis-3.0.0-rc1/src# mv redis-cli redis-server redis-sentinel /usr/bin/  
  3. root@localhost:/opt/deploy/redis-3.0.0-rc1/src# cd ..  
  4. root@localhost:/opt/deploy/redis-3.0.0-rc1# mkdir -p /etc/redis/  
  5. root@localhost:/opt/deploy/redis-3.0.0-rc1# cp redis.conf /etc/redis/redis.conf  

2、現在打開文件/etc/redis/redis.conf, 找到‘daemonize no’改爲‘daemonize yes‘,然後啓動它!

[plain] view plain copy
 print?
  1. root@localhost:/opt/deploy/redis-3.0.0-rc1/src# redis-server /etc/redis/redis.conf  
  2. root@localhost:/opt/deploy/redis-3.0.0-rc1/src#  


好了, Redis現在已經安裝好了,並且在容器裏面運行了,使用的配置文件是/etc/redis/redis.conf。

至此,redis安裝完成。

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