標籤:centos nosql linux redis
1.下載redis
可以線上安裝或者下載 redis
①線上安裝前需要檢測是否存在rpm包不存在的話查看yum線上是否存在rpm包不存在的話就只能手動下載或者用別的方式下載
[[email protected] ~]# rpm -qa|grep redis[[email protected] ~]# yum list|grep redis
說明不存在。
②去官網下載或者線上下載
wget http://redis.googlecode.com/files/redis-2.2.13.tar.gz
官網下載好的 redis 已經存在部落格中了點擊下載 redis。
2.安裝
由於是tar.gz格式的所以需要解壓安裝
下載好之後尋找下載檔案所在路徑
[[email protected] ~]# whereis redisredis: /etc/redis[[email protected] ~]#
解壓編譯redis的軟體包需要有gcc環境
總之缺少什麼安裝什麼。
tar -zxvf reids-2.8.13.tar.gzcd redis-2.8.13makesudo make install#配置開始---編譯完成後在Src目錄下有四個可執行檔redis-server、redis-benchmark、redis-cli和redis.conf。然後拷貝到一個目錄下。mkdir /usr/rediscp redis-server /usr/rediscp redis-benchmark /usr/rediscp redis-cli /usr/rediscp redis.conf /usr/rediscd /usr/redis#配置結束--
或者可以這樣配置
mkdir /etc/rediscp redis.conf /etc/redis/redis.confmkdir /var/lib/redis
可從此處下載修改好的 redis.conf
啟動redisredis-server /etc/redis/redis.conf#即可在後台啟動redis服務確認運行了之後可以用redis-benchmark命令測試看看還可以通過redis-cli命令實際操作一下比如#install的時候redis的命令會被拷貝到/usr/local/bin下面
3.測試
用戶端測試一下是否啟動成功
[[email protected] src]# ps -aux|grep redisWarning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQroot 23266 0.0 0.7 137356 7768 ? Sl 00:23 0:04 redis-server *:6379root 23982 0.0 0.5 19404 5100 pts/0 S+ 01:09 0:00 redis-cliroot 24398 0.0 0.0 103244 876 pts/2 S+ 01:44 0:00 grep redis[[email protected] src]# redis-cli127.0.0.1:6379> set w wangOK127.0.0.1:6379> get w"wang"127.0.0.1:6379>
4.關閉服務
redis-cli shutdown如果連接埠變化可以指定連接埠:redis-cli -p 6379 shutdown
127.0.0.1:6379> i+jCould not connect to Redis at 127.0.0.1:6379: Connection refusednot connected> set w 3Could not connect to Redis at 127.0.0.1:6379: Connection refusednot connected>
5.啟動服務
[[email protected] src]# redis-server[24502] 28 Oct 01:54:35.784 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf[24502] 28 Oct 01:54:35.784 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ‘‘-._ _.-`` `. `_. ‘‘-._ Redis 2.8.13 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ‘‘-._ ( ‘ , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|‘` _.-‘| Port: 6379 | `-._ `._ / _.-‘ | PID: 24502 `-._ `-._ `-./ _.-‘ _.-‘ |`-._`-._ `-.__.-‘ _.-‘_.-‘| | `-._`-._ _.-‘_.-‘ | http://redis.io `-._ `-._`-.__.-‘_.-‘ _.-‘ |`-._`-._ `-.__.-‘ _.-‘_.-‘| | `-._`-._ _.-‘_.-‘ | `-._ `-._`-.__.-‘_.-‘ _.-‘ `-._ `-.__.-‘ _.-‘ `-._ _.-‘ `-.__.-‘ [24502] 28 Oct 01:54:35.786 # Server started, Redis version 2.8.13[24502] 28 Oct 01:54:35.786 # 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.[24502] 28 Oct 01:54:35.786 * DB loaded from disk: 0.000 seconds[24502] 28 Oct 01:54:35.786 * The server is now ready to accept connections on port 6379
啟動之後最好重新開啟個視窗運行redsi-cli進入控制台
否則可能出現串連錯誤。和windows下cmd運行tomcat類似。
[[email protected] redis]# redis-cliCould not connect to Redis at 127.0.0.1:6379: Connection refusednot connected> redis-cliCould not connect to Redis at 127.0.0.1:6379: Connection refusednot connected> [[email protected] redis]# redis-cli127.0.0.1:6379> set name = wangxin(error) ERR syntax error127.0.0.1:6379> set name wangxinOK127.0.0.1:6379> set age 26OK127.0.0.1:6379> get name age(error) ERR wrong number of arguments for ‘get‘ command127.0.0.1:6379> get name"wangxin"127.0.0.1:6379> get age"26"127.0.0.1:6379>
本文出自 “路漫漫兮” 部落格,請務必保留此出處http://wangxin88.blog.51cto.com/3228434/1569084
NoSQL之Redis - CentOS 6.5安裝測試