1. 程式人生 > >【NOSQL ]】 redis 安裝

【NOSQL ]】 redis 安裝

安裝redis,使用一種你熟悉的高階語言(例如ruby,python等)在redis裡建立資料併成功訪問作為測試


=======================================================================================================
1.安裝


    [[email protected] download]# ll

    -rw-r--r-- 1 root root   1048914 01-15 14:36 redis-2.8.4.tar.gz

    [[email protected] download]# tar xzf redis-2.8.4.tar.gz
    [[email protected]
download]# ll
    drwxrwxr-x 6 root root      4096 01-14 00:09 redis-2.8.4
    -rw-r--r-- 1 root root   1048914 01-15 14:36 redis-2.8.4.tar.gz

    [[email protected] download]# cd redis-2.8.4
    [[email protected] redis-2.8.4]# ls
    00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README      runtest        src    utils
    BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  sentinel.conf  tests
    [
[email protected]
redis-2.8.4]# ll
    總計 108
    -rw-rw-r-- 1 root root  9549 01-14 00:09 00-RELEASENOTES
    -rw-rw-r-- 1 root root    52 01-14 00:09 BUGS
    -rw-rw-r-- 1 root root  1439 01-14 00:09 CONTRIBUTING
    -rw-rw-r-- 1 root root  1487 01-14 00:09 COPYING
    drwxrwxr-x 6 root root  4096 01-14 00:09 deps
    -rw-rw-r-- 1 root root    11 01-14 00:09 INSTALL
    -rw-rw-r-- 1 root root   151 01-14 00:09 Makefile
    -rw-rw-r-- 1 root root  4223 01-14 00:09 MANIFESTO
    -rw-rw-r-- 1 root root  4401 01-14 00:09 README
    -rw-rw-r-- 1 root root 30113 01-14 00:09 redis.conf
    -rwxrwxr-x 1 root root   271 01-14 00:09 runtest
    -rw-rw-r-- 1 root root  5662 01-14 00:09 sentinel.conf
    drwxrwxr-x 2 root root  4096 01-14 00:09 src
    drwxrwxr-x 8 root root  4096 01-14 00:09 tests
    drwxrwxr-x 2 root root  4096 01-14 00:09 utils
    [
[email protected]
redis-2.8.4]# make

    zmalloc.o: In function `zmalloc_used_memory':
    /var/lib/tcommsvr/redis-2.8.0-rc4/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4'
    collect2: ld returned 1 exit status
    make[1]: *** [redis-server] Error 1
    make[1]: Leaving directory `/var/lib/tcommsvr/redis-2.8.0-rc4/src'
    make: *** [all] Error 2

    產生原因:

    linux為32位版本。
    檢視方式:getconf LONG_BIT


    解決辦法:

    執行make命令時加引數:make CFLAGS="-march=i686"

    make CFLAGS="-march=i686"

2.啟動:

    [[email protected] src]# ./redis-server --port 9999
    [15894] 15 Jan 16:20:23.114 * Max number of open files set to 10032
    [15894] 15 Jan 16:20:23.117 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
    ...

3.測試連線

    [[email protected] redis-2.8.4]# telnet localhost  9999
    Trying 127.0.0.1...
    Connected to localhost.localdomain (127.0.0.1).
    Escape character is '^]'.
    get a^H
    $-1
    set a
    -ERR wrong number of arguments for 'set' command
    set hpp 4
    +OK
    set hoge 4
    +OK
    abcd
    -ERR unknown command 'abcd'
    set hoge 4
    +OK
    get hoge
    $1
    4
    setex foo 5 3
    +OK
    get foo
    $-1
    get foo
    $-1
    setex foo 5 10
    +OK

4.安裝Python    

4.1.下載原始碼
        http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tar.bz2

4.2.  安裝 Python

       $ tar –jxvf Python-2.7.6.tgz
       $ cd Python-2.7.6
        ./configure
        make
        make install

4.3 測試開啟python

    [[email protected] redis-2.7.2]# python
    Python 2.7.6 (default, Jan 16 2014, 17:54:06)
    [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import redis
    >>> r= redis.StrictRedis(host='localhost',port=6379,db=0)
    >>> r.set('foo','bar')




4.4 啟動redis

    [[email protected] /]# cd /download/redis-2.8.4/
    [[email protected] redis-2.8.4]# vi redis.conf
    [[email protected] redis-2.8.4]# src/redis-server redis.conf
    [28781] 17 Jan 09:50:40.200 * Max number of open files set to 10032
    [28781] 17 Jan 09:50:40.203 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
                    _._                                                  
               _.-``__ ''-._                                             
          _.-``    `.  `_.  ''-._           Redis 2.8.4 (00000000/0) 32 bit
      .-`` .-```.  ```\/    _.,_ ''-._                                   
     (    '      ,       .-`  | `,    )     Running in stand alone mode
     |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
     |    `-._   `._    /     _.-'    |     PID: 28781
      `-._    `-._  `-./  _.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |           http://redis.io        
      `-._    `-._`-.__.-'_.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |                                  
      `-._    `-._`-.__.-'_.-'    _.-'                                   
          `-._    `-.__.-'    _.-'                                       
              `-._        _.-'                                           
                  `-.__.-'                                               

    [28781] 17 Jan 09:50:40.205 # Server started, Redis version 2.8.4
    [28781] 17 Jan 09:50:40.205 # 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.
    [28781] 17 Jan 09:50:40.206 * The server is now ready to accept connections on port 6379



4.5 使用python 連線redis


    [[email protected] opt]# python
    Python 2.7.6 (default, Jan 16 2014, 17:54:06)
    [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import redis
    >>> redisClient=redis.StrictRedis(host='127.0.0.1',port=6379,db=0)
    >>> redisClient.set('test_redis','Hello Python')
    True
    >>> value=redisClient.get('test_redis')
    >>> print value
    Hello Python
    >>> redisClient.delete('test_redis')
    True
    >>> value=redisClient.get('test_redis')
    >>> print value
    None
    >>>

4.6 4.測試例項:
    4.6 4.1.把文字資料匯入到redis
    [[email protected] backup]# cat test_data.txt
    wolys # wolysopen111 # [email protected]
    coralshanshan # 601601601 # [email protected]
    pengfeihuchao # woaidami # [email protected]
    simulategirl # @#$9608125 # [email protected]
    daisypp # 12345678 # [email protected]
    sirenxing424 # tfiloveyou # [email protected]
    raininglxy # 1901061139 # [email protected]
    leochenlei # leichenlei # [email protected]
    z370433835 # lkp145566 # [email protected]


    4.6 4.2.建立命令指令碼

    [[email protected] backup]# vi imp_redis.py
    [[email protected] backup]# cat imp_redis.py
    import redis
    import re
    pool = redis.ConnectionPool(host='127.0.0.1', port=6379)
    r = redis.Redis(connection_pool=pool)
    pipe = r.pipeline()
    p=re.compile(r'(.*)\s#\s(.*)\s#\s(.*)');
    pipe = r.pipeline()
    f = open("/opt/backup/test_data.txt")
    matchs=p.findall(f.read())
    for user in matchs:
       key='users_%s' %user[0].strip()
       pipe.hset(key,'pwd',user[1].strip()).hset(key,'email',user[2].strip())
    pipe.execute()
    f.close()

    4.6 4.3.執行指令碼

    [[email protected] backup]# python imp_redis.py

4.6 4.4.檢視匯入資料

    [[email protected] src]# redis-cli
    -bash: redis-cli: command not found
    [[email protected] src]# ./redis-cli
    127.0.0.1:6379> keys *
     1) "users_simulategirl"
     2) "users_wolys"
     3) "users_raininglxy"
     4) "users_daisypp"
     5) "users_coralshanshan"
     6) "users_pengfeihuchao"
     7) "users_leochenlei"
     8) "hoge"
     9) "users_sirenxing424"
    10) "users_z370433835"
    127.0.0.1:6379>
    [[email protected] src]#


相關推薦

NOSQL ] redis 安裝

安裝redis,使用一種你熟悉的高階語言(例如ruby,python等)在redis裡建立資料併成功訪問作為測試 ================================================================================

NoSqlRedis實踐篇-簡單demo實現(一)

     Redis是一個key-value儲存系統。Redis的出現,很大程度補償了memcached這類key/value儲存的不足,在部分場合可以對關係資料庫起到很好的補充作用     Redis

Linux數據庫Redis安裝配置

con debug top size 日誌 stream oca mono onf 一,Redis配置 1、下載安裝 $ wget http://download.redis.io/releases/redis-2.8.17.tar.gz $ tar xzf re

redis-cluster安裝配置

create source make edi onf 存儲 置配 down 配置文件 需要三臺虛擬機(生產環境是3個物理機),分配靜態IP。cluster中共6個節點。3主3從。本文中每個虛擬機上的redis端口:6379 6380。 需要註意的兩點: 3個主節點分別位於3

redis學習之一redis安裝與執行

在linux下安裝redis服務: 1、首先下載tar包,解壓,進入相應目錄: wget http://download.redis.io/releases/redis-3.2.8.tar.gz tar zxvf redis-3.2.8.tar.gz cd redis-3.2.8 make

經典Linux安裝Redis

1、檢測是否有安裝redis-cli和redis-server; [[email protected] bin]# whereis redis-cli redis-cli: /usr/bin/redis-cli [[email protected] bin]# wherei

linux安裝redis(單機版)、3種啟動方式、及配置檔案介紹。

環境ubuntu16.04 解壓 tar -zxvf redis-3.2.6.tar.gz 修改資料夾名稱 mv redis-3.2.6 redis 編譯 cd /app/redis make 編譯好後會看到redis.conf和src檔案 安裝 cd

RedisRedis安裝及常見問題

1、解壓:tar -zxvf redis-3.0.0.tar.gz 2、ll 3、cd redis-3.0.0 編譯時必須有makefile 4、make [[email protected] redis-3.0.0]#

NoSQLNoSQL簡介及常用的NoSQL資料庫對比(Redis、MongoDB、HBase等)

基本含義 NoSQL(NoSQL = Not Only SQL ),意即“不僅僅是SQL”,是一項全新的資料庫革命性運動,早期就有人提出,發展至2009年趨勢越發高漲。NoSQL的擁護者們提倡運用非關係型的資料儲存,相對於鋪天蓋地的關係型資料庫運用,這一概念無疑是一種全新的思維的注入。 2NoSQL

分享Brackets安裝emmet插件出錯解決辦法

racket img 復制 end 查看 解決辦法 目錄 nal get 1.復制下方鏈接,迅雷下載文件得到:brackets-emmet-1.2.1.zip文件 https://s3.amazonaws.com/extend.brackets/brackets-em

11 Express安裝入門與模版引擎ejs

scrip png js文件 是我 use 處理 ica direct 配置 前言 Express簡介和安裝 運行第一個基於express框架的Web 模版引擎 ejs express項目結構 express項目分析 app.set(name,value) app

Swoole簡單安裝與創建TCP服務器

客戶 編寫程序 lac nco 版本 size sock ear light pecl install swoole PHP的異步、並行、高性能網絡通信引擎,使用純C語言編寫,提供了php語言的異步多線程服務器,異步TCP/UDP網絡客戶端,異步MySQL

Linux JDK安裝及配置 (tar.gz版)

ubuntu logs 環境 pat source alt 修改 8.0 添加 安裝環境   Linux(Ubuntu 版) JDK安裝   tar.gz為解壓後就可以使用的版本,這裏我將使用jdk-8u65-linux-x64.tar.gz版,安裝到/usr/java/下

MongoDB安裝及配置

.org root 終端 配置 conn tin serve cal 數據文件 一、MongoDB安裝 1、下載並解壓 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.0.tgz

ArcGISWebAdaptorIIS 安裝前準備及配置Portal For ArcGIS的問題解決

ima 沒有 port 問題解決 準備 bad 問題 cnblogs web 1、計算機全名配置 2、IIS-服務器證書配置 3、端口綁定 備註:配置Portal For ArcGIS總會提示計算機域名、全名錯誤,可能就是沒有進行第一步操作

Linux安裝HDF5及遇到的問題總結

inf 遇到 upload 詳細步驟 iframe gunzip 總結 comm box Linux安裝HDF5及遇到的問題總結 轉自: http://www.linuxdiyf.com/linux/26164.html ubuntu版

LinuxUbuntu安裝Python3

獲取 有著 默認 conf 差距 sta ima images alt  敘述:   Ubuntu17.04自帶Python2.7與Python3.5.3的版本,由於Python2與Python3有著一些差距可能需要安裝更新Python3的版本,並且切換默認的Python解

VSC安裝了哪些擴展工具

file 文件 工具 安裝 info com 生成 src 代碼 HTML Boilerplate——HTML 模板 (只需在空文件中輸入 html ,按 Tab 鍵即可生成幹凈的文檔結構) File Peek —— 根據路徑字符串,快速定位到文件 CSS

轉載python3安裝scrapy之windows32位爬坑

命令 cep 3.2 wheel 跳過 。。 學習 自己的 打開 python3安裝scrapy之windows32位爬坑 原創 2016年11月06日 01:38:08 標簽: scrapy / windows / python / 開源框架 / 網絡爬蟲

zookeeper簡單安裝

zookeeper1.安裝java#!/bin/bash # rpm -ivh jdk-8u144-linux-x64.rpm # java -version java version "1.8.0_144"2.安裝zookeeper下載地址 : http://zookeeper.apac