1. 程式人生 > >redis 安裝及安裝遇到的問題解決

redis 安裝及安裝遇到的問題解決

Redis Quick Start

This is a quick start document that targets people without prior experience with Redis. Reading this document will help you:

  • Download and compile Redis to start hacking.
  • Use redis-cli to access the server.
  • Use Redis from your application.
  • Understand how Redis persistence works.
  • Install Redis more properly.
  • Find out what to read next to understand more about Redis.

Installing Redis

The suggested way of installing Redis is compiling it from sources as Redis has no dependencies other than a working GCC compiler and libc. Installing it using the package manager of your Linux distribution is somewhat discouraged as usually the available version is not the latest.

You can either download the latest Redis tar ball from the redis.io web site, or you can alternatively use this special URL that always points to the latest stable Redis version, that is, http://download.redis.io/redis-stable.tar.gz.

In order to compile Redis follow this simple steps:

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make

At this point you can try if your build works correctly typing make test, but this is an optional step. After the compilation the src directory inside the Redis distribution is populated with the different executables that are part of Redis:

  • redis-server is the Redis Server itself.
  • redis-cli is the command line interface utility to talk with Redis.
  • redis-benchmark is used to check Redis performances.
  • redis-check-aof and redis-check-dump are useful in the rare event of corrupted data files.

It is a good idea to copy both the Redis server than the command line interface in proper places using the following commands:

  • sudo cp redis-server /usr/local/bin/
  • sudo cp redis-cli /usr/local/bin/

In the following documentation I assume that /usr/local/bin is in your PATH environment variable so you can execute both the binaries without specifying the full path.

Starting Redis

The simplest way to start the Redis server is just executing the redis-server binary without any argument.

$ redis-server
[28550] 01 Aug 19:29:28 # Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf'
[28550] 01 Aug 19:29:28 * Server started, Redis version 2.2.12
[28550] 01 Aug 19:29:28 * The server is now ready to accept connections on port 6379
... and so forth ...

In the above example Redis was started without any explicit configuration file, so all the parameters will use the internal default. This is perfectly fine if you are starting Redis just to play a bit with it or for development, but for production environments you should use a configuration file.

To start Redis with a configuration file just give the full path of the configuration file to use as the only Redis argument, for instance: redis-server /etc/redis.conf. You can use the redis.conf file included in the root directory of the Redis source code distribution as a template to write your configuration file.

Check if Redis is working

External programs talk to Redis using a TCP socket and a Redis specific protocol. This protocol is implemented in the Redis client libraries for the different programming languages. However to make hacking with Redis simpler Redis provides a command line utility that can be used to send commands to Redis. This program is called redis-cli.

The first thing to do in order to check if Redis is working properly is sending a PING command using redis-cli:

$ redis-cli ping
PONG

Running redis-cli followed by a command name and its arguments will send this command to the Redis instance running on localhost at port 6379. You can change the host and port used by redis-cli, just try the --help option to check the usage information.

Another interesting way to run redis-cli is without arguments: the program will start into an interactive mode where you can type different commands:

$ redis-cli                                                                
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379> set mykey somevalue
OK
redis 127.0.0.1:6379> get mykey
"somevalue"

At this point you can talk with Redis. It is the right time to pause a bit with this tutorial and start the fifteen minutes introduction to Redis data types in order to learn a few Redis commands. Otherwise if you already know a few basic Redis commands you can keep reading.

Using Redis from your application

Of course using Redis just from the command line interface is not enough as the goal is to use it from your application. In order to do so you need to download and install a Redis client library for your programming language. You'll find afull list of clients for different languages in this page.

For instance if you happen to use the Ruby programming language our best advice is to use the Redis-rb client. You can install it using the command gem install redis (also make sure to install the SystemTimer gem as well).

These instructions are Ruby specific but actually many library clients for popular languages look quite similar: you create a Redis object and execute commands calling methods. A short interactive example using Ruby:

>> require 'rubygems'
=> false
>> require 'redis'
=> true
>> r = Redis.new
=> #<Redis client v2.2.1 connected to redis://127.0.0.1:6379/0 (Redis v2.3.8)>
>> r.ping
=> "PONG"
>> r.set('foo','bar')
=> "OK"
>> r.get('foo')
=> "bar"

Redis persistence

You can learn how Redis persisence works in this page, however what is important to understand for a quick start is that by default, if you start Redis with the default configuration, Redis will spontaneously save the dataset only from time to time (for instance after at least five minutes if you have at least 100 changes in your data), so if you want your database to persist and be reloaded after a restart make sure to call the SAVE command manually every time you want to force a data set snapshot. Otherwise make sure to shutdown the database using the SHUTDOWN command:

$ redis-cli shutdown

This way Redis will make sure to save the data on disk before quitting. Reading the persistence page is strongly suggested in order to better understand how Redis persistence works.

Installing Redis more properly

Running Redis from the command line is fine just to hack a bit with it or for development. However at some point you'll have some actual application to run on a real server. For this kind of usage you have two different choices:

  • Run Redis using screen.
  • Install Redis in your Linux box in a proper way using an init script, so that after a restart everything will start again properly.

A proper install using an init script is strongly suggested. The following instructions can be used to perform a proper installation using the init script shipped with Redis 2.4 in a Debian or Ubuntu based distribution.

We assume you already copied redis-server and redis-cli executables under /usr/local/bin.

  • Create a directory where to store your Redis config files and your data:

    sudo mkdir /etc/redis
    sudo mkdir /var/redis
    
  • Copy the init script that you'll find in the Redis distribution under the utils directory into /etc/init.d. We suggest calling it with the name of the port where you are running this instance of Redis. For example:

    sudo cp utils/redis_init_script /etc/init.d/redis_6379
    
  • Edit the init script.

    sudo vi /etc/init.d/redis_6379
    

Make sure to modify REDIS_PORT accordingly to the port you are using. Both the pid file path and the configuration file name depend on the port number.

  • Copy the template configuration file you'll find in the root directory of the Redis distribution into /etc/redis/ using the port number as name, for instance:

    sudo cp redis.conf /etc/redis/6379.conf
    
  • Create a directory inside /var/redis that will work as data and working directory for this Redis instance:

    sudo mkdir /var/redis/6379
    
  • Edit the configuration file, making sure to perform the following changes:

  • Set daemonize to yes (by default it is set to no).
  • Set the pidfile to /var/run/redis_6379.pid (modify the port if needed).
  • Change the port accordingly. In our example it is not needed as the default port is already 6379.
  • Set your preferred loglevel.
  • Set the logfile to /var/log/redis_6379.log
  • Set the dir to /var/redis/6379 (very important step!)
  • Finally add the new Redis init script to all the default runlevels using the following command:

    sudo update-rc.d redis_6379 defaults
    

You are done! Now you can try running your instance with:

/etc/init.d/redis_6379 start

Make sure that everything is working as expected:

  • Try pinging your instance with redis-cli.
  • Do a test save with redis-cli save and check that the dump file is correctly stored into /var/redis/6379/ (you should find a file called dump.rdb).
  • Check that your Redis instance is correctly logging in the log file.
  • If it's a new machine where you can try it without problems make sure that after a reboot everything is still working.

Note: in the above instructions we skipped many Redis configurations parameters that you would like to change, for instance in order to use AOF persistence instead of RDB persistence, or to setup replication, and so forth. Make sure to read the redis.conf file (that is heavily commented) and the other documentation you can find in this web site for more information.

相關推薦

yum安裝問題解決

升級Python而導致的YUM服務無法使用的修復方法 2009年2月6日 閱讀評論 發表評論 由於YUM包管理是使用Python編寫的,因此如果單獨對Python進行升級可能會導致YUM服務無法使用。 出現這種情況的主要原因在於新安裝的Python沒有YUM服務所依賴的Packages。 可以嘗試在Pyth

redis 安裝安裝遇到的問題解決

Redis Quick Start This is a quick start document that targets people without prior experience with Redis. Reading this document will help you: Download a

Centos下給php安裝Redis擴充套件編譯問題解決

1、第一步自然是去github下載原始碼了,記得加上引數 --no-check-certificate,不然https校驗會出錯 wget https://github.com/phpredis/phpredis/archive/develop.zip --no-check

MYSQL5.7 ZIP版本安裝相關問題解決

對於mysql5.7以後版本,沒有了my.ini檔案,這裡要自己新建。 安裝過程: 1、解壓zip檔案。例如D:\ProgramFile\mysql-5.7.19-winx64 2、新增環境變數。D:\ProgramFile\mysql-5.7.19-winx64\bin到pa

docker學習之 安裝啟動錯誤解決

docker學習 Linux centos7下安裝docker需要 linux 核心在 3.10.0 以上, 檢視核心的方法為: # 檢視版本號 [[email protected] sysconfig]# uname -r 3.10.0-327.el7.

手把手教你進行R語言的安裝安裝過程中相關問題解決方案

這篇文章旨在為R語言的新手鋪磚引路,行文相對基礎,希望對在R語言安裝上有問題的小夥伴提供幫助和指引。一、什麼是 R 語言R 程式語言被廣泛應用在統計科學和商業領域。 在各種程式語言排名中 R 語言的排名都很靠前。 它是一款集成了資料操作、統計,以及視覺化功能的優秀開源軟體。免費,開源是 R 重要的特點。二

mongodb安裝安裝後warning的解決方法

整理一下工作中業務遷移遇到的問題 大的問題暫時沒有,主要與mongodb有關。 小的問題諸如更改指令碼檔案裡面的路徑資訊。更改指令碼中的部分配置資訊等等。 mongodb 安裝之後會出現警告的情況。為了解決我花費了不少時間。這裡整理一下。 安裝的過程可參考: https://blog.c

Redis入門安裝

一、什麼是Redis Redis是Remote Dictionary Server(遠端資料服務)的縮寫,由義大利人antirez(Salvatore Sanflippo) 開發的一款 記憶體高速快取資料庫,該軟體使用C語言編寫,它的資料模型為(key-value),它支援

python中Jupyter Notebook庫的安裝安裝失敗的解決方法學習

一、Jupyter notebook的認識Jupyter Notebook(此前被稱為 IPython notebook)是一個互動式筆記本,支援執行 40 多種程式語言。其本質是一個 Web 應用程式,它執行以網頁的形式存在,便於建立和共享文學化程式文件,支援實時程式碼,數

Win10下loadRunner安裝執行問題解決——在安裝時提示被管理員禁止解決辦法

Win10下loadRunner安裝及執行問題解決 loadRunner是一種預測系統行為和效能的負載測試工具。 其通過以模擬上千萬使用者實施併發負載及實時效能監測的方式來確認和查詢問題,能夠對整個企業架構進行測試。 在安裝loadRunner時首先要選擇一個帶有

001.Redis簡介安裝

一 Redis簡介 1.1 Redis 簡介 Redis 是完全開源免費的,遵守BSD協議,是一個高效能的key-value資料庫。 Redis 與其他 key-value 快取產品有以下三個特點: Redis支援資料的持久化,可以將記憶體中的資料儲存在磁碟

Anaconda安裝更新失敗解決方式

Anaconda 安裝anaconda從官網上下載慢,使用清華映象連結下載 https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/ 下載完之後,儘量的按照anaconda預設的行為安裝,打鉤的兩個地方都勾上,它會自動將b

sysbench安裝常見問題解決

第一步.下載安裝包。(這裡地址選擇github) wget https://github.com/akopytov/sysbench/archive/0.5.zip 第二步.解壓,並進入到目錄。

Hive安裝啟動異常解決

前期準備 1、關於Hive的安裝包和文件可以從這裡獲取: 2、Hive依賴於Hadoop,關於Hadoop的安裝可以檢視這裡: 3、安裝mysql 由於Hive需要在資料庫中儲存元資料資訊,所以安裝hive之前需要先安裝mysql。h

CUDA安裝常見問題解決辦法

解決方法:解除安裝N卡驅動(單卡的請跳過),重新安裝Intel顯核 若安裝時出現:N卡驅動有問題時,請解除安裝後到官網重灌。(不裝也能安CUDA) 安裝結束後發現安裝失敗。 解決辦法:在檢查完相容性後,開始安裝前,右擊我的電腦->管理-

Vue.js devtool外掛下載安裝後續問題解決

下載 在中國,你是無法使用谷歌應用商店,所以你下載外掛,要使用一些別的手段,一種是下載原始碼編譯,另一種是通過第三方網站。第一種不適合小白,所以現在介紹第二組。 下載外掛網站 國外網站:https://www.crx4chrome.com/ 國內網站:http://w

VVDocumenter-Xcode安裝遇到問題解決方案

是不是寫註釋變成了一件非常有趣的事,你還可以對其進行一些設定,在xcode->window選單欄中,有VVDocumenter這個標籤,裡面可以對生成註釋的模板進行一些設定,比如生成註釋的快捷鍵,註釋的對齊模式,註釋顯示建立者和時間等。例如如下設定就會生成這樣的註釋:

SimpleElastix安裝問題(windows)

三大步驟: 用CMake生成構建檔案用Visual Studio編譯器編譯安裝Python模組看著這三步和把大象裝冰箱分幾步一樣簡單。然並簡。在安裝SimpleElastix前確認Python3.4已經安裝。 下載並安裝CMake以後,從git上下載SimpleEla

elasticsearch的安裝常見問題解決、配置檔案的介紹

elasticsearch  的安裝  1 :輸入命令:  wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz2 : 安裝完成後解壓:tar -vxf ela

Redis 使用安裝

Redis 安裝1、Redis的資料型別:  字串、列表(lists)、集合(sets)、有序集合(sorts sets)、雜湊表(hashs)2、Redis和memcache相比的獨特之處:  (1)redis可以用來做儲存(storge)、而memcache是來做快取(cache)。這個特點主要是因為其有