centos 6.8安装Redis和简单的使用

该文为转载,原文移步:https://blog.csdn.net/weixin_37998647/article/details/79047691

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.1”

100%[===================================================================================================================>] 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> 

上一篇:【Web集群】nginx-web应用 之 日志轮询切割


下一篇:ipcs、ipcrm、sysresv、kernel.shmmax