Redis的部署
笔者Q:972581034 交流群:605799367 欢迎加群交流
官方网站
redis.io
下载
cd /usr/local/src
wget http://download.redis.io/releases/redis-3.0.7.tar.gz
安装redis
tar xf redis-3.0.7.tar.gz
cd redis-3.0.7/
make PREFIX=/usr/local/redis-3.0.7 install
复制启动文件到etc下
cp redis_init_script /etc/init.d/redis
修改启动文件默认路径
[root@redis utils]# sed -i 's#EXEC=/usr/local/bin/redis-server#EXEC=/usr/local/redis/bin/redis-server#g' /etc/init.d/redis
修改停止文件默认路径
[root@redis utils]# sed -i 's#CLIEXEC=/usr/local/bin/redis-cli#CLIEXEC=/usr/local/redis/bin/redis-cli#g' /etc/init.d/redis
添加关闭脚本密码和监听主机
vim +30 /etc/init.d/redis
#30行下添加
30 $CLIEXEC -h 10.0.0.20 -p $REDISPORT -a oldboy shutdown
创建软连接,加执行权限
[root@redis utils]# ln -s /usr/local/redis-3.0.7/ /usr/local/redis
[root@redis utils]# cd
[root@redis ~]# chmod +x /etc/init.d/redis
复制配制文件
[root@redis ~]# mkdir /etc/redis
[root@redis ~]# cp /usr/local/src/redis-3.0.7/redis.conf /etc/redis/
修改端口
[root@redis ~]# cd /etc/redis/
[root@redis redis]# cp redis.conf 6379.conf
[root@redis redis]# ls
6379.conf redis.conf
修改配置文件后台启动
[root@redis redis]# sed -i 's#daemonize no#daemonize yes#g' /etc/redis/6379.conf
修改pid文件,加上端口号区分。因为redis单线程不能使用多个CPU
[root@redis redis]# sed -i 's#pidfile /var/run/redis.pid#pidfile /var/run/redis_6379.pid#g' /etc/redis/6379.conf
tcp-backlog
[root@redis redis]# grep "tcp-backlog" 6379.conf
tcp-backlog 511
解释一下:
backlog其实是一个连接队列,以下是backlog队列大小公式。
backlog队列总和=未完成三次握手队列 + 已经完成三次握手队列
未完成三次握手队列:服务器处于listen状态时收到客户端syn 报文(connect)时放入未完成队列中。
已经完成三次握手队列:三路握手的第二个状态即服务器syn+ ack响应client后,此时第三个状态ack报文到达前(客户端对服务器syn的ack)一直保留在未完成连接队列中,如果三路握手完成,该条目将从未完成连接队列搬到已完成连接队列尾部.
backlog参数设置既可以在linux内核参数设置(修改文件/etc/sysctl相关参数),也可以在socket系统调用listen函数时设置(第二个参数),这二者区别是,前者为全局性的,影响所有socket,后者为局部性的,影响当前socket。
配置文件提示/proc/sys/net/core/somaxconn的值不能低于tcp-backlog的值,不然启动时会有警告提示
[root@redis redis]# cat /proc/sys/net/core/somaxconn
128
#这里设置为512
[root@redis redis]# echo 512 > /proc/sys/net/core/somaxconn
[root@redis redis]# cat /proc/sys/net/core/somaxconn
512
绑定监听端口主机
[root@redis redis]# sed -i 's@# bind 127.0.0.1@bind 10.0.0.20@g' /etc/redis/6379.conf
[root@redis redis]# grep bind 6379.conf
# interfaces using the "bind" configuration directive, followed by one or
# bind 192.168.1.100 10.0.0.1
bind 10.0.0.20
修改默认的日志文件名为redis_6379.log
[root@redis redis]# sed -i 's@logfile ""@logfile "/var/log/redis_6379.log"@g' /etc/redis/6379.conf
[root@redis redis]# grep logfile /etc/redis/6379.conf
logfile "/var/log/redis_6379.log"
默认的数据库大小为0-16个,有需求可以修改
[root@redis redis]# grep databases 6379.conf
# Set the number of databases. The default database is DB 0, you can select
# dbid is a number between 0 and 'databases'-1
databases 16
# Compress string objects using LZF when dump .rdb databases?
配置持久化数据目录/var/lib/redis_6379
随意定义路径可能会导致数据被误删,单实例建议也配置路径,若以后增加实例会比较麻烦
[root@redis redis]# sed -i 's#dir ./#dir /var/lib/redis_6379#g' 6379.conf
[root@redis redis]# grep 'dir /' 6379.conf
dir /var/lib/redis_6379
[root@redis redis]# mkdir /var/lib/redis_6379 -p
修改password,不设密码是很容易被入侵的。
[root@redis redis]# sed -i 's@# requirepass foobared@requirepass oldboy@g' /etc/redis/6379.conf
[root@redis redis]# grep "requirepass" /etc/redis/6379.conf
# If the master is password protected (using the "requirepass" configuration
requirepass oldboy
启动服务
[root@redis redis]# /etc/init.d/redis start
Starting Redis server...
查看日志检查服务
[root@redis redis]# less /var/log/redis_6379.log
20557:M 10 Jun 03:52:51.625 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.7 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 20557
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
20557:M 10 Jun 03:52:51.626 # Server started, Redis version 3.0.7
20557:M 10 Jun 03:52:51.626 # 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.
20557:M 10 Jun 03:52:51.626 * The server is now ready to accept connections on port 6379
警告信息
20557:M 10 Jun 03:52:51.626 # 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.
表示voercommit_memory文件指定了内核针对内存分配的策略,其值可以是0、1、2。
0 表示内存将检查是否有足够的可用内存供用进程使用;如果有足够的可用内存,内存申请允许;
否则,内存申请失败,并把错误返回给应用进程。1 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2 表示内核允许分配超过所有物理内存和交换空间总和的内存
登录redis
[root@redis redis]# redis-cli -h 10.0.0.20 -p 6379
Could not connect to Redis at 10.0.0.20:6379: Connection refused
not connected>
Redis的部署的更多相关文章
- Redis笔记(二)Redis的部署和启动
Linux下Redis的部署和启动 下载安装介质 Redis官网地址:http://www.redis.io/目前最新版本是redis-3.0.3. 可以访问 http://download.redi ...
- Redis分布式部署,一致性hash
一致性哈希 由于hash算法结果一般为unsigned int型,因此对于hash函数的结果应该均匀分布在[0,2^32-1]区间,如果我们把一个圆环用2^32 个点来进行均匀切割,首先按照hash( ...
- Window Redis分布式部署方案 java
Redis分布式部署方案 Window 1. 基本介绍 首先redis官方是没有提供window下的版本, 是window配合发布的.因现阶段项目需求,所以研究部署的是window版本的,其实都 ...
- windows下安装Redis并部署成服务
windows下安装Redis并部署成服务 Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 一:下载 下载地址: windows版本: http ...
- 第一章· Redis入门部署及持久化介绍
Redis简介 Redis安装部署 Redis持久化 Redis简介 软件说明: Redis是一款开源的,ANSI C语言编写的,高级键值(key-value)缓存和支持永久存储NoSQL数据库产品. ...
- VMware虚拟机安装CentOS6.4、部署web项目全过程(设置固定IP、安装JDK、Tomcat、Redis、部署项目)
概述:该篇随笔介绍了在VMware上安装centOS.在centOS上安装JDK.安装Tomcat.安装Redis并部署项目的全过程,虽然参考了很多优秀的文章,但实践.整理.补充都很用心,若要复制粘贴 ...
- Redis 主从部署
Redis 主从部署 http://www.xuchanggang.cn/archives/978.html
- Redis单机部署、添加开机自启、配置参数
1.Redis简介 redis是使用C语言编写的开源的,支持网络,基于内存,可持久性的键值对存储数据库,2013年5月之前,Redis是最流行的键值对存储数据库,Redis采用内存数据集,支持多种数据 ...
- Redis的部署使用文档
Redis的部署使用文档 简述: redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符 串).list(链表).set( ...
- Redis入门部署及持久化
软件简介 软件说明 Redis是一款开源的,ANSI C语言编写的,高级键值(key-value)缓存和支持永久存储NoSQL数据库产品. Redis采用内存(In-Memory)数据集(DataSe ...
随机推荐
- MYSQL:RELPACE用法
RELPACE类似于INSERT的方法,但如果表中的旧行与主键或惟一索引的新行具有相同的值,则在插入新行之前删除旧行 为了测试方便我们首先要创建一张表 CREATE TABLE test ( id I ...
- Maven02——回顾、整合ssh框架、分模块开发、私服
1 回顾 1.1 Maven的好处 节省空间 对jar包做了统一管理 依赖管理 一键构建 可跨平台 应用在大型项目可提高开发效率 1.2 Maven安装部署配置 1.3 Maven的仓库 本地仓库 远 ...
- zookeeper之分布式锁以及分布式计数器(通过curator框架实现)
有人可能会问zookeeper我知道,但是curator是什么呢? 其实curator是apachede针对zookeeper开发的一个api框架是apache的顶级项目 他与zookeeper原生a ...
- 使用quartz实现不重启服务器修改自定义配置
为了方便维护系统,开发中通常会设置一些自定义参数,写在单独的配置文件里,需要调整时可直接登录服务器修复配置文件,而不需要修改程序.但尴尬的是,web服务器并不会自动重新加载配置文件,重启服务器又会中断 ...
- ex_gcd(个人模版)
ex_gcd: #include<stdio.h> #include<string.h> using namespace std; int x,y; int ex_gcd(in ...
- BZOJ:1443: [JSOI2009]游戏Game
原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1443 反正不看题解我是完全想不出系列…… 先把棋盘黑白染色,也就是同一对角线上颜色相同,使 ...
- Trees on the level(指针法和非指针法构造二叉树)
Trees on the level Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- c++(非递归排序)
在上面一篇博客当中,我们发现普通查找和排序查找的性能差别很大.作为一个100万的数据,如果使用普通的查找方法,那么每一个数据查找平均下来就要几十万次,那么二分法的查找呢,20多次就可以搞定.这中间的差 ...
- 分布式计算框架学习笔记--hadoop工作原理
(hadoop安装方法:http://blog.csdn.net/wangjia55/article/details/53160679这里不再累述) hadoop是针对大数据设计的一个计算架构.如果你 ...
- 解决 重启nginx: [alert] kill(189, 1) failed (3: No such process)
解决 nginx: [alert] kill(189, 1) failed (3: No such process) [root@localhost/]# nginx -s reloadnginx: ...