一、安装redis cd /usr/local/src/ wget http://redis.googlecode.com/files/redis-2.6.11.tar.gz tar zxvf redis-2.6.11.tar.gz cd redis-2.6.11 make cd .. cp -a redis-2.6.11 /usr/local/redis-2.6.11
二、redis配置 1. 修改redis为启动在后台 修改redis.con daemonize no 为yes 说明:是否把redis-server启动在后台,默认是“否”。若改成yes,会生成一个pid文件。
2. 添加redis登陆密码 修改redis.con requirepass 123456 [iyunv@centos01 redis-2.6.11-com]# ./src/redis-cli redis 127.0.0.1:6379> get a (error) ERR operation not permitted redis 127.0.0.1:6379> exit [iyunv@centos01 redis-2.6.11-com]# ./src/redis-cli -a 123456 redis 127.0.0.1:6379> get a "4"
先登录再验证: [iyunv@slaver251 redis-2.4.16]# ./src/redis-cli -p 6379 redis 127.0.0.1:6379> redis 127.0.0.1:6379> auth test123 OK redis 127.0.0.1:6379> config get requirepass
3. 设置redis主从 主: requirepass 123456 从: slaveof 192.168.95.130 6379 masterauth 123456 [iyunv@centos01 redis-2.6.11-com]# ./src/redis-cli -a 1234567 info |grep master master_host:192.168.95.130 master_port:6379 master_link_status:up master_last_io_seconds_ago:2 master_sync_in_progress:0
三、FAQ
################## FAQ ########################## redis编译报错: 在包含自 adlist.c:34 的文件中: zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录 zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required" >>解决 make的时候加上 MALLOC=libc 参数
修改完配置文件后,就可以启动redis了,#/usr/local/bin/redis-server /etc/redis/redis.conf,可能会遇到的问题: 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. [解决办法]:键入 sysctl vm.overcommit_memory=1 或者修改/etc/sysctl.conf sysctl -p 该文件指定了内核针对内存分配的策略,其值可以是0、1、2。 0,表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。 1,表示内核允许分配所有的物理内存,而不管当前的内存状态如何。 2,表示内核允许分配超过所有物理内存和交换空间总和的内存
Warning: 32 bit instance detected but no memory limit set. Setting 3.5 GB maxmemory limit with 'noeviction' policy now. [解决办法]:修改配置文件 redis.conf,将 maxmemory 设小
|