打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Linux值Redis缓存的编译安装

通过wget方式直接在linux上下载Redis
[root@livecd root]#wget http://download.redis.io/releases/redis-3.2.3.tar.gz
解压下载的redis-2.6.17.tar.gz 文件
[root@livecd root]#tar -zxvf redis-3.2.3.tar.gz
进入解压后的文件夹
[root@livecd root]#cd redis-3.2.3
编译

[root@livecd redis-3.2.3]# make
测试是否正常编译成功:
[root@livecd redis-3.2.3]# make test #正常情况下显示各个模块都安装成功[ok]
安装:
[root@livecd redis-3.2.3]# make install
在安装redis成功后,你将可以在/usr/local/bin看到一个bin的目录,里面包括了以下文件,当然在解压的安装包目录(即执行make install的工作目录)下的./src(本案例中/root/redis-3.2.3/src)目录下也会生成下面的文件:(如果在编译的时候指定安装目录make prefix=/usr/local/redis,那么下面文件同样会出在/usr/local/redis/bin目录) 

redis-benchmark  redis-check-aof  redis-check-dump(wyq:该文件在2.4.4版本生成,在3.2.3版本貌似改称为redis-check-rdb)  redis-cli  redis-server

redis-server:Redis服务器的daemon启动程序

redis-cli:Redis命令行操作工具。也可以用telnet根据其纯文本协议来操作

redis-benchmark:Redis性能测试工具,测试Redis在当前系统下的读写性能

redis-check-aof:数据修复

redis-check-dump:检查导出工具

运行:

通过执行src文件夹下的redis-server,可以启动redis服务:
[root@livecd redis-3.2.3]# src/redis-server ./redis.conf #当然也可以执行/usr/local/bin/redis-server /root/redis-3.2.3/redis.conf来启动
5713:M 23 Aug 09:53:09.277 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.2.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 5713
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

5713:M 23 Aug 09:53:09.279 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
5713:M 23 Aug 09:53:09.279 # Server started, Redis version 3.2.3
5713:M 23 Aug 09:53:09.279 # 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.
5713:M 23 Aug 09:53:09.279 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
5713:M 23 Aug 09:53:09.279 * The server is now ready to accept connections on port 6379

我们在第一步中开启redis进程后不要关闭该进程,因为上述进程是一个普通进程,即如果关闭上述客户端命令窗口或终止上述进程,那么redis进行会被关闭,为了redis可以持久执行我们可以通过将该进程改为守护进程或者将其加工为一个服务的形式,后面我们将介绍。此处在不结束第一步的命令的前提下,我们重新打开一个与服务器的ssh通信,通过执行src文件夹下的redis-cli, 可以访问redis服务。

[root@livecd redis-3.2.3]# src/redis-cli
127.0.0.1:6379> set foo wangyaqiang
OK
127.0.0.1:6379> get foo
"wangyaqiang"
127.0.0.1:6379> exit
[root@livecd redis-3.2.3]#
将redis做成一个守护进程(参见本节点同级节点【redis做成守护进程】)
将redis的命令所在目录添加到系统环境变量$PATH,从而实现在任意目录可以调用redis-server等命令(参见本节点同级节点【redis操作目录添加到系统环境变量PATH】)
复制一份配置文件到/etc目录,从而方便以后管理修改启动等。
[root@livecd redis-3.2.3]# cp ./redis.conf  /etc/redis.conf
6ok啦,现在我们可以在任何目录以下面的方式来启动或操作redis喽!
[root@iZ25ja2kaemZ redis-3.2.3]# redis-server /etc/redis.conf
[root@iZ25ja2kaemZ redis-3.2.3]# ps axu|grep redis
root      1070  0.0  0.7 133524  7544 ?        Ssl  13:37   0:00 redis-server 127.0.0.1:6379
root      1074  0.0  0.0 103252   836 pts/0    S+   13:37   0:00 grep redis
[root@iZ25ja2kaemZ redis-3.2.3]#
关闭redis服务
[root@iZ25ja2kaemZ redis-3.2.3]# redis-cli -p 6379 shutdown #如果不指定端口默认端口为6379
如果有密码,那么 [root@iZ25ja2kaemZ ~]#  redis-cli -p 6379 -a 123456789abc  shutdown

为了以后重启服务器时候,希望该redis服务自动启动,那么我们可以将其做成一个服务(参见本节点同级节点【redis做成一个服务】))

测试用例:

/usr/local/bin/redis-server /root/redis-3.2.3/redis.conf  #开启
/ root/redis-3.2.3/src/redis-cli #使用客户端链接服务
/root/redis-3.2.3/src/redis-server /root/redis-3.2.3/redis.conf  #开启

安装过程可能出现的问题:

1.CentOS6.5默认没有安装gcc,因为如果使用源码安装软件包,必须用到该gcc模块,这会导致我们无法make成功。出现如下错误:

make: cc: Command not found make: *** [adlist.o] Error 127

使用yum安装:

yum -y install gcc

2.make时报如下错误:

[root@livecd redis-3.2.3]# make
cd src && make all
make[1]: Entering directory `/usr/local/redis/redis-3.2.3/src'
    CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/usr/local/redis/redis-3.2.3/src'
make: *** [all] Error 2
原因是jemalloc重载了Linux下的ANSI C的malloc和free函数。解决办法:make时添加参数。

make MALLOC=libc

3.make之后,会出现一句提示

Hint: To run 'make test' is a good idea ;) 
但是不测试,通常是可以使用的。若我们运行make test ,会有如下提示

[devnote@devnote src]$ make test
You need tcl 8.5 or newer in order to run the Redis test
make: ***[test] Error_1
解决办法是用yum安装tcl8.5(或去tcl的官方网站http://www.tcl.tk/下载8.5版本,并参考官网介绍进行安装)

yum install tcl

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Redis主从配置及主从切换
redis-cli远程连接redis-server服务器的问题
linux 开机自启动redis服务
Redis连接时报错:Could not connect to Redis at 127.0.0.1:6379: Connection refused
redis单机多实例
redis集群部署
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服