redis安装

来源:互联网 发布:java负数转正数 编辑:程序博客网 时间:2024/06/07 17:59

redis安装

  • redis安装
  • 环境
  • 下载最新版
  • 安装
  • 启动
  • 其他
    • 清理没用的源文件和编译文件
    • 启动关闭redis服务
    • Linux服务器配置
    • 配置文件
  • 说明

环境

CentOS6.6 X86_64

下载最新版

当前2015-11-26最新版为3.0.5

wget http://download.redis.io/releases/redis-3.0.5.tar.gz

安装

tar -xf redis-3.0.5.tar.gzcd redis-3.0.5make

启动

安装完成后,进入src目录,启动redis-server

cd src./redis-server

看到如下输出,启动成功,redis默认监听6379端口

6420:C 26 Nov 15:09:17.096 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf6420:M 26 Nov 15:09:17.097 * Increased maximum number of open files to 10032 (it was originally set to 1024).                _._                                                             _.-``__ ''-._                                                   _.-``    `.  `_.  ''-._           Redis 3.0.5 (00000000/0) 64 bit  .-`` .-```.  ```\/    _.,_ ''-._                                    (    '      ,       .-`  | `,    )     Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379 |    `-._   `._    /     _.-'    |     PID: 6420  `-._    `-._  `-./  _.-'    _.-'                                    |`-._`-._    `-.__.-'    _.-'_.-'|                                   |    `-._`-._        _.-'_.-'    |           http://redis.io          `-._    `-._`-.__.-'_.-'    _.-'                                    |`-._`-._    `-.__.-'    _.-'_.-'|                                   |    `-._`-._        _.-'_.-'    |                                    `-._    `-._`-.__.-'_.-'    _.-'                                         `-._    `-.__.-'    _.-'                                                 `-._        _.-'                                                         `-.__.-'                                               ......输入Ctrl+C停止redis服务

客户端连接测试

在src目录中执行

./redis-cli

输出如下所示

127.0.0.1:6379> info# Serverredis_version:3.0.5redis_git_sha1:00000000redis_git_dirty:0redis_build_id:61a2748bb135354bredis_mode:standaloneos:Linux 2.6.32-504.el6.x86_64 x86_64arch_bits:64multiplexing_api:epoll...输入exit退出客户端

其他

清理没用的源文件和编译文件

在src目录中

rm -rf *.c *.o *.h

启动关闭redis服务

在src目录下执行

启动./redis-server ../redis.conf关闭(默认-h 127.0.o.1 -p 6379,可以省略)./redis-cli -h 127.0.0.1 -p 6379 shutdown 

Linux服务器配置

redis启动时会检查系统相关参数,如有问题会提示,主要是以下参数

max open file

先临时修改ulimit -n 32768查看结果 ulimit -a永久修改/etc/security/limits.conf,添加* soft nofile 32768* hard nofile 32768

somaxconn参数:定义了系统中每一个端口最大的监听队列的长度,这是个全局的参数,默认值为128

echo 1000 >/proc/sys/net/core/somaxconn

虚拟内存overcommit:

在/etc/sysctl.conf中增加vm.overcommit_memory = 1运行  sysctl vm.overcommit_memory=1  使用配置生效

Transparent Huge Pages (THP) support enabled:

执行echo never > /sys/kernel/mm/transparent_hugepage/enabled添加上述命令到开机启动  /etc/rc.local  中

配置文件

安装目录下的redis.conf是默认的配置文件

将守护模式no改为yes
daemonize yes
日志文件默认”“改为”redis6379.log”
logfile “redis6379.log”

以下根据实际情况调整,贴出默认配置
pidfile /var/run/redis.pid
port 6379
dbfilename dump.rdb
loglevel notice

说明

所有相关的参数,ip地址,端口等请根据实际情况自行调整。

0 0
原创粉丝点击