centos 6.8安裝Redis和簡單的使用

一、安裝依賴包,準備環境。

yum install -y gcc

依賴包情況可能會不一樣,按照編譯時候的提示安裝就可以了。但是gcc一定要裝。
二、1、下載tar包,安裝啓動。

wget http://source.goyun.org:8000/source/Redis/redis-3.2.9.tar.gz
--2018-01-12 19:15:07--  http://source.goyun.org:8000/source/Redis/redis-3.2.9.tar.gz
Resolving source.goyun.org... 59.110.136.26
Connecting to source.goyun.org|59.110.136.26|:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1547695 (1.5M) [application/x-gzip]
Saving to: “redis-3.2.9.tar.gz.1100%[===================================================================================================================>] 1,547,695   73.8K/s   in 42s

2018-01-12 19:15:49 (36.4 KB/s) - “redis-3.2.9.tar.gz.1” saved [1547695/1547695]

默認是下載在當前目錄下的,
2、解壓:

tar zxvf redis-3.2.9.tar.gz
[root@localhost ~]# ll
drwxrwxr-x 6 root root    4096 May 17  2017 redis-3.2.9
-rw-r--r-- 1 root root 1547695 Jan 12 15:07 redis-3.2.9.tar.gz

會在當前目錄下面產生一個redis-3.2.9目錄。
3、進入目錄並make:

[root@localhost ~]# cd redis-3.2.9
[root@localhost redis-3.2.9]# ll
total 208
-rw-rw-r--  1 root root 87407 May 17  2017 00-RELEASENOTES
-rw-rw-r--  1 root root    53 May 17  2017 BUGS
-rw-rw-r--  1 root root  1805 May 17  2017 CONTRIBUTING
-rw-rw-r--  1 root root  1487 May 17  2017 COPYING
drwxrwxr-x  7 root root  4096 May 17  2017 deps
-rw-rw-r--  1 root root    11 May 17  2017 INSTALL
-rw-rw-r--  1 root root   151 May 17  2017 Makefile
-rw-rw-r--  1 root root  4223 May 17  2017 MANIFESTO
-rw-rw-r--  1 root root  6834 May 17  2017 README.md
-rw-rw-r--  1 root root 46695 May 17  2017 redis.conf
-rwxrwxr-x  1 root root   271 May 17  2017 runtest
-rwxrwxr-x  1 root root   280 May 17  2017 runtest-cluster
-rwxrwxr-x  1 root root   281 May 17  2017 runtest-sentinel
-rw-rw-r--  1 root root  7606 May 17  2017 sentinel.conf
drwxrwxr-x  2 root root  4096 May 17  2017 src
drwxrwxr-x 10 root root  4096 May 17  2017 tests
drwxrwxr-x  7 root root  4096 May 17  2017 utils
[root@localhost redis-3.2.9]# make

4、進入解壓的目錄下:

[root@localhost redis-3.2.9]# cd src/
[root@localhost src]# pwd
/root/redis-3.2.9/src
[root@localhost src]#make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1

注意,注意,這裏出現報錯,解決的辦法:下載並安裝TCL

[root@localhost src]#cd 
[root@localhost ~]#wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
[root@localhost ~]# ll
drwxrwxr-x 6 root root    4096 May 17  2017 redis-3.2.9
-rw-r--r-- 1 root root 1547695 Jan 12 15:07 redis-3.2.9.tar.gz
-rw-r--r-- 1 root root  229376 Jan 12 19:25 tcl8.6.1-src.tar.gz
[root@localhost ~]# tar zxvf tcl8.6.1-src.tar.gz
[root@localhost ~]# ll
drwxrwxr-x 6 root root    4096 May 17  2017 redis-3.2.9
-rw-r--r-- 1 root root 1547695 Jan 12 15:07 redis-3.2.9.tar.gz
-rw-r--r-- 1 root root  229376 Jan 12 19:25 tcl8.6.1-src.tar.gz
drwxr-xr-x 4 15399 19249    4096 Sep 20  2013 tcl8.6.1
[root@localhost Desktop]# cd tcl8.6.1/
[root@localhost tcl8.6.1]# cd unix/
[root@localhost unix]# ./configure
[root@localhost unix]# make && make install

5、回到Redis的假牙目錄再次make test

[root@localhost src]# pwd
/root/redis-3.2.9/src

顯示 All tests passed without errors !
就是測試成功啦!
可以安裝了。
6、安裝:

[root@localhost src]# make PREFIX=/usr/local/redis install
[root@loalhost redis]# cd /usr/local/redis
[root@loalhost redis]# ll
total 56
drwxr-xr-x 2 root root  4096 Jan 12 15:52 bin
-rw-r--r-- 1 root root    90 Jan 12 16:34 dump.rdb
[root@loalhost redis]# cd bin/
[root@loalhost bin]# ls
dump.rdb         redis-check-aof  redis-cli       redis-server
redis-benchmark  redis-check-rdb  redis-sentinel

7、把解壓的redis路徑下的redis.conf文件拷貝到安裝路徑下面

[root@localhost ~]# cd redis-3.2.9
[root@localhost redis-3.2.9]# ll
total 208
-rw-rw-r--  1 root root 87407 May 17  2017 00-RELEASENOTES
-rw-rw-r--  1 root root    53 May 17  2017 BUGS
-rw-rw-r--  1 root root  1805 May 17  2017 CONTRIBUTING
-rw-rw-r--  1 root root  1487 May 17  2017 COPYING
drwxrwxr-x  7 root root  4096 Jan 12 19:21 deps
-rw-rw-r--  1 root root    11 May 17  2017 INSTALL
-rw-rw-r--  1 root root   151 May 17  2017 Makefile
-rw-rw-r--  1 root root  4223 May 17  2017 MANIFESTO
-rw-rw-r--  1 root root  6834 May 17  2017 README.md
-rw-rw-r--  1 root root 46695 May 17  2017 redis.conf
-rwxrwxr-x  1 root root   271 May 17  2017 runtest
-rwxrwxr-x  1 root root   280 May 17  2017 runtest-cluster
-rwxrwxr-x  1 root root   281 May 17  2017 runtest-sentinel
-rw-rw-r--  1 root root  7606 May 17  2017 sentinel.conf
drwxrwxr-x  2 root root  4096 Jan 12 19:22 src
drwxrwxr-x 10 root root  4096 May 17  2017 tests
drwxrwxr-x  7 root root  4096 May 17  2017 utils
[root@localhost redis-3.2.9]# cp redis.conf /usr/local/redis
[root@localhost local]# cd /usr/local/redis
[root@localhost redis]# ll
total 56
drwxr-xr-x 2 root root  4096 Jan 12 15:52 bin
-rw-r--r-- 1 root root    90 Jan 12 16:34 dump.rdb
-rw-r--r-- 1 root root 46696 Jan 12 15:53 redis.conf
[root@localhost redis]# cd bin/
[root@localhost bin]# ls
dump.rdb         redis-check-aof  redis-cli       redis-server
redis-benchmark  redis-check-rdb  redis-sentinel

8、啓動Redis
第一種方法:

[root@localhost bin]# ./redis-server

會顯示下面的樣子:

[root@server51 bin]# ./redis-server
38210:C 12 Jan 18:01:18.469 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
38210:M 12 Jan 18:01:18.472 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.2.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 38210
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

38210:M 12 Jan 18:01:18.512 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
38210:M 12 Jan 18:01:18.513 # Server started, Redis version 3.2.9
38210:M 12 Jan 18:01:18.513 # 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.
38210:M 12 Jan 18:01:18.513 * The server is now ready to accept connections on port 6379

這樣其實已經啓動成功了,但是這屬於前端啓動,啓動redis之後,我們的控制檯就不能進行任何操作了。只能ctrl+c停止啓動。
第二種方法:
後端啓動
首先編輯redis.conf

[root@localhost redis]# vim redis.conf

找到daemonize no將其改爲yes

再次啓動

[root@localhost redis]# ./bin/redis-server ./redis.conf
//這裏加載配置文件
80167:C 30 Jul 16:01:58.145 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
80167:C 30 Jul 16:01:58.145 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=80167, just started
80167:C 30 Jul 16:01:58.145 # Configuration loaded

可以查看進程:

[root@localhost bin]# ps -ef | grep -i redis
root     130477      1  0 19:51 ?        00:00:00 ./bin/redis-server 127.0.0.1:6379
root     130559 130412  0 19:58 pts/0    00:00:00 grep -i redis

說明啓動了。

關閉Redis的命令:

[root@localhost redis]# ./bin/redis-cli shutdown

三、簡單的使用:

[root@localhost redis]# ./bin/redis-cli
//檢查網絡是否可以
127.0.0.1:6379> ping
PONG
//設置一個鍵值對
127.0.0.1:6379> set name xiaoyao
OK
//獲取剛剛設置的鍵值對
127.0.0.1:6379> get name
"xiaoyao"
//查看所有的鍵
127.0.0.1:6379> keys *
1) "name"
//刪除name這個鍵
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> 

至此就完成了Redis的安裝和啓動啦。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章