您的位置:首页 > 数据库 > Redis

Redis安装部署

2015-06-08 14:13 573 查看
1. 下载最新版本的redis(这里以redis-3.0.2为例)
http://redis.io/download
2. 解压缩

$ tar xzf redis-3.0.2.tar.gz

以我的机子为例,解压后的目录为:/home/jason/tools/redis-3.0.2

3. 编译依赖的库或者文件:

进入到目录:deps下(即对应我的机子中的/home/jason/tools/redis-3.0.2/deps),该目录下共有以下依赖的东西:

drwxrwxrwx. 4 root root 4096 6月   8 12:02 hiredis
drwxrwxrwx. 8 root root 4096 6月   8 14:28 jemalloc
drwxrwxrwx. 2 root root 4096 6月   8 12:02 linenoise
drwxrwxrwx. 6 root root 4096 6月   8 12:00 lua
-rwxrwxrwx. 1 root root 2480 6月   8 12:00 Makefile
-rwxrwxrwx. 1 root root  282 6月   8 12:00 update-jemalloc.sh
编译上述redis依赖的玩意儿,使用命令:

make hiredis jemalloc linenoise lua

4.编译redis

进入到redis解压缩之后的目录,对应我的机子就是:/home/jason/tools/redis-3.0.2

执行命令:make和make install即可完成redis的编译和安装;

5.运行redis,直接直接命令(没有指定配置文件,即使用默认配置):

redis-server

如下图所示:



6. 修改系统的内存参数vm.overcommit_memory的值为1,该参数在文件/etc/sysctl.conf中,可用下命令直接修改:

sysctl vm.overcommit_memory=1

关于此参数的解释可以参考下列文章:
http://houjixin.blog.163.com/blog/static/3562841020155825711171/#
或者:
http://blog.csdn.net/houjixin/article/details/46412557
7. 启动redis并指定配置文件

redis-server /etc/redis.conf
即在启动命令之后直接指定配置文件的完整路径

8. redis的一些常用工具:

redis安装之后,将在目录/usr/local/bin产生若干工具:

-rwxr-xr-x. 1 root root      145 6月   8 14:21 jemalloc.sh
-rwxr-xr-x. 1 root root   171375 6月   8 14:21 pprof
-rwxr-xr-x. 1 root root  2084846 6月   8 14:29 redis-benchmark
-rwxr-xr-x. 1 root root    25173 6月   8 14:29 redis-check-aof
-rwxr-xr-x. 1 root root    52796 6月   8 14:29 redis-check-dump
-rwxr-xr-x. 1 root root  2208936 6月   8 14:29 redis-cli
lrwxrwxrwx. 1 root root       12 6月   8 14:29 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root  4338352 6月   8 14:29 redis-server
-rwxr-xr-x. 1 root root 40567102 6月   8 11:55 thrift


这些工具当中,比较有用的工具有:

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

redis-cli:Redis客户端,该工具经常使用,其使用方法为:

[root@localhost ~]# redis-cli -h 192.168.1.201 -p 6379

192.168.1.201:6379> 

redis-benchmark:Redis性能测试工具

redis-check-aof:数据修复

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

9. redis的重点配置项

配置文件的名字: redis.conf

daemonize:是否以后台daemon方式运行

pidfile:pid文件位置

port:监听的端口号

timeout:请求超时时间

loglevel:log信息级别

logfile:log文件位置

databases:开启数据库的数量

save * *:保存快照的频率,第一个*表示多长时间,第三个*表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。可设置多个条件。

rdbcompression:是否使用压缩

dbfilename:数据快照文件名(只是文件名,不包括目录)

dir:数据快照的保存目录(这个是目录)

appendonly:是否开启appendonlylog,开启的话每次写操作会记一条log,这会提高数据抗风险能力,但影响效率。

appendfsync:appendonlylog如何同步到磁盘(三个选项,分别是每次写都强制调用fsync、每秒启用一次fsync、不调用fsync等待系统自己同步)

10. 检查是否启动成功 $ ps -ef | grep redis
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: