centos 安裝單機版 redis4.0.10

redis源碼地址: http://download.redis.io/releases/前端

 下載 redis-4.0.10.tar.gz  和  redis-stable.tar.gzjava

 

第一步:安裝gcc編譯環境linux

yum install gcc-c++c++

第二步:把redis的源碼上傳到linux服務器。redis

第三步:解壓縮。windows

tar -zxvf redis-4.0.10.tar.gz安全

第四步:進入解壓後的文件夾, make服務器

第五步:make install PREFIX=/usr/local/redisapp

第六步: (忽略,由於已經下載過了 )wget http://download.redis.io/redis-stable.tar.gz(下載redis-cli的壓縮包) 第七步:tar xvzf redis-stable.tar.gz(解壓) 第八步:cd redis-stable(進入redis-stable目錄) make(安裝) sudo cp src/redis-cli /usr/local/bin/(將redis-cli拷貝到bin下,讓redis-cli指令能夠在任意目錄下直接使用)

按照上面的指令執行以後redis-cli就能夠正常執行了,注意上面的幾條指令必須都執行,make是單獨的一條。ide

 

啓動redis

兩種啓動方式,前端啓動、後臺啓動。

前端啓動:

cd /usr/local/redis

./redis-server

後臺啓動:

一、複製redis.conf到redis的安裝目錄

二、修改redis.conf。修改daemonize yes

三、[root@bogon redis]# ./redis-server redis.conf

 

redis關閉

到redis節點目錄下執行以下命令

redis-cli -p 端口號 shutdown

 

redis啓動

./redis-server 參數

參數:redis.conf文件全路徑

 

 客戶端

redis-cli -p 端口 -h ip地址 <-c>鏈接集羣時使用此參數

 

默認端口:6379

Iplocalhost127.0.0.1

 

RedisDesktopManager

 

只能在單機版環境使用。不支持redis集羣。

 

其餘記錄:

 

沒想到在進行鏈接時報了下面這麼一個錯,fuck,Linux上的redis還真是麻煩,哪像windows上的redis這麼簡單一解壓完事 
  

 

Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside. at redis.clients.jedis.Protocol.processError(Protocol.java:127) at redis.clients.jedis.Protocol.process(Protocol.java:161) at redis.clients.jedis.Protocol.read(Protocol.java:215) at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340) at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239) at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:196) at com.example.redis.JedisTest.main(JedisTest.java:24)

 

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

 

  通過我英語八級的翻譯,上面一共提供了四種解決方案,可是綜合考慮爲了簡單起見只須要執行如下幾步便可: 
   
  1.修改redis.conf配置文件,將綁定的ip地址端口號給註釋見下圖 
  這裏寫圖片描述

 

  2.因爲Linux上的redis處於安全保護模式,這就讓你沒法從虛擬機外部去輕鬆創建鏈接,這裏就有兩種解決方法,一種是在redis.conf中設置保護模式爲no,見下圖 
  這裏寫圖片描述

 

  3.另一種方式是加上安全認證,即redis默認是沒有密碼的能夠直接登陸,這裏加上密碼,配置見下圖 
  這裏寫圖片描述

 

  4.好吧,此時你覺得輕鬆解決問題了,因而再次在Linux啓動redis服務器後,在外部鏈接仍是報錯,真是too young too native,起初我覺得是配置沒有生效,由於明明配置都寫好了,因而殺掉redis的相關進程重啓服務,結果發現仍是沒卵用。最後研究發現問題所在:以前啓動redis-server並無指定配置文件,而Linux上的redis比較操蛋的一點就是若是你不指定配置文件去啓動,那麼你作的修改就沒有用,會讀取默認配置(PS:至於這個默認配置在哪我也不清楚),因而用下面這種方式啓動就可使修改的配置文件生效,至於config rewrite命令我測試了並無什麼卵用。 
  這裏寫圖片描述

 

  5.再次測試,在windows上進行jedis鏈接測試,出現下面pong(),惱人的錯誤終於消失了,比起windows版本的redis還真是讓人龜毛啊,若是配置了密碼認證,調用Jedis的auth方法輸入密碼便可 
   這裏寫圖片描述 
   

修改redis.conf文件daemonize改成yes

 

 

 

無奈在最後關閉redis的服務的時候,redis服務報錯redis (error) ERR Errors trying to SHUTDOWN. Check logs.,怎麼關都關不掉,百度一番,信息不多,無奈屢次嘗試,終於解決。方法以下:

 

打開redis安裝目錄下的redis.conf找到

 

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.


dir ./

 

這一段

 

把die ./改成相應的目錄,如"dir /home/distance/redis_dbfiles/"(這裏須要注意最後的斜槓不能忘記,若是缺失斜槓可能會解析爲文件而非目錄),保存。

相關文章
相關標籤/搜索