【NOSQL ]】 redis 安装
生活随笔
收集整理的這篇文章主要介紹了
【NOSQL ]】 redis 安装
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
安裝redis,使用一種你熟悉的高級語言(例如ruby,python等)在redis里創(chuàng)建數(shù)據(jù)并成功訪問作為測試
=======================================================================================================
1.安裝
?? ?[root@ractdg3 download]# ll
?? ?-rw-r--r-- 1 root root?? 1048914 01-15 14:36 redis-2.8.4.tar.gz
?? ?[root@ractdg3 download]# tar xzf redis-2.8.4.tar.gz
?? ?[root@ractdg3 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
?? ?[root@ractdg3 download]# cd redis-2.8.4
?? ?[root@ractdg3 redis-2.8.4]# ls
?? ?00-RELEASENOTES? CONTRIBUTING? deps???? Makefile?? README????? runtest??????? src??? utils
?? ?BUGS???????????? COPYING?????? INSTALL? MANIFESTO? redis.conf? sentinel.conf? tests
?? ?[root@ractdg3 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
?? ?[root@ractdg3 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
?? ?產(chǎn)生原因:
?? ?linux為32位版本。
?? ?查看方式:getconf LONG_BIT
?? ?解決辦法:
?? ?執(zhí)行make命令時加參數(shù):make CFLAGS="-march=i686"
?? ?make CFLAGS="-march=i686"
2.啟動:
?? ?[root@ractdg3 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.測試連接
?? ?[root@ractdg3 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
?? ?[root@ractdg3 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
?? ?[root@ractdg3 /]# cd /download/redis-2.8.4/
?? ?[root@ractdg3 redis-2.8.4]# vi redis.conf
?? ?[root@ractdg3 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
?? ?[root@ractdg3 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.把文本數(shù)據(jù)導(dǎo)入到redis
?? ?[root@ractdg3 backup]# cat test_data.txt
?? ?wolys # wolysopen111 # wolys@21cn.com
?? ?coralshanshan # 601601601 # zss1984@126.com
?? ?pengfeihuchao # woaidami # 294522652@qq.com
?? ?simulategirl # @#$9608125 # simulateboy@163.com
?? ?daisypp # 12345678 # zhoushigang_123@163.com
?? ?sirenxing424 # tfiloveyou # sirenxing424@126.com
?? ?raininglxy # 1901061139 # lixinyu23@qq.com
?? ?leochenlei # leichenlei # chenlei1201@gmail.com
?? ?z370433835 # lkp145566 # 370433835@qq.com
?? ?4.6 4.2.創(chuàng)建命令腳本
?? ?[root@ractdg3 backup]# vi imp_redis.py
?? ?[root@ractdg3 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.執(zhí)行腳本
?? ?[root@ractdg3 backup]# python imp_redis.py
4.6 4.4.查看導(dǎo)入數(shù)據(jù)
?? ?[root@ractdg3 src]# redis-cli
?? ?-bash: redis-cli: command not found
?? ?[root@ractdg3 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>
?? ?[root@ractdg3 src]#
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖
=======================================================================================================
1.安裝
?? ?[root@ractdg3 download]# ll
?? ?-rw-r--r-- 1 root root?? 1048914 01-15 14:36 redis-2.8.4.tar.gz
?? ?[root@ractdg3 download]# tar xzf redis-2.8.4.tar.gz
?? ?[root@ractdg3 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
?? ?[root@ractdg3 download]# cd redis-2.8.4
?? ?[root@ractdg3 redis-2.8.4]# ls
?? ?00-RELEASENOTES? CONTRIBUTING? deps???? Makefile?? README????? runtest??????? src??? utils
?? ?BUGS???????????? COPYING?????? INSTALL? MANIFESTO? redis.conf? sentinel.conf? tests
?? ?[root@ractdg3 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
?? ?[root@ractdg3 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
?? ?產(chǎn)生原因:
?? ?linux為32位版本。
?? ?查看方式:getconf LONG_BIT
?? ?解決辦法:
?? ?執(zhí)行make命令時加參數(shù):make CFLAGS="-march=i686"
?? ?make CFLAGS="-march=i686"
2.啟動:
?? ?[root@ractdg3 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.測試連接
?? ?[root@ractdg3 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
?? ?[root@ractdg3 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
?? ?[root@ractdg3 /]# cd /download/redis-2.8.4/
?? ?[root@ractdg3 redis-2.8.4]# vi redis.conf
?? ?[root@ractdg3 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
?? ?[root@ractdg3 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.把文本數(shù)據(jù)導(dǎo)入到redis
?? ?[root@ractdg3 backup]# cat test_data.txt
?? ?wolys # wolysopen111 # wolys@21cn.com
?? ?coralshanshan # 601601601 # zss1984@126.com
?? ?pengfeihuchao # woaidami # 294522652@qq.com
?? ?simulategirl # @#$9608125 # simulateboy@163.com
?? ?daisypp # 12345678 # zhoushigang_123@163.com
?? ?sirenxing424 # tfiloveyou # sirenxing424@126.com
?? ?raininglxy # 1901061139 # lixinyu23@qq.com
?? ?leochenlei # leichenlei # chenlei1201@gmail.com
?? ?z370433835 # lkp145566 # 370433835@qq.com
?? ?4.6 4.2.創(chuàng)建命令腳本
?? ?[root@ractdg3 backup]# vi imp_redis.py
?? ?[root@ractdg3 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.執(zhí)行腳本
?? ?[root@ractdg3 backup]# python imp_redis.py
4.6 4.4.查看導(dǎo)入數(shù)據(jù)
?? ?[root@ractdg3 src]# redis-cli
?? ?-bash: redis-cli: command not found
?? ?[root@ractdg3 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>
?? ?[root@ractdg3 src]#
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖
總結(jié)
以上是生活随笔為你收集整理的【NOSQL ]】 redis 安装的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【性能优化】 之 RAC架构性能优化
- 下一篇: 【NOSQL 】 memcache 安装