AWS EC2 CentOS release 6.5 部署redis
参考:http://blog.csdn.net/ludonqin/article/details/47211109

一.安装redis
1)     下载redis安装包
可去官网http://redis.io ,也可通过wget命令:
[root@ip-172-31-46-4 ~]# wget http://download.redis.io/redis-stable.tar.gz

2)     解压
执行命令:
[root@ip-172-31-46-4 ~]# tar –zxvf redis-stable.tar.gz

3)     编译、安装
执行命令:
[root@ip-172-31-46-4 ~]# cd redis-stable

执行命令:
[root@ip-172-31-46-4 redis-stable]# make

在make成功以后,需要执行命令:
[root@ip-172-31-46-4 redis-stable]# make test

成功后可手动拷贝src目录下redis-server、redis-cli、redis-check-aof、redis-check-dump等至/usr/local/bin目录下,也可执行命令:
[root@ip-172-31-46-4 redis-stable]# make install

验证系统目录下启动脚本:
[root@ip-172-31-46-4 ~]# cd /usr/local/bin
[root@ip-172-31-46-4 bin]# ls -ltrh
total 26M
-rwxr-xr-x 1 root root 7.5M Jan  7 08:03 redis-server
-rwxr-xr-x 1 root root 5.4M Jan  7 08:03 redis-benchmark
-rwxr-xr-x 1 root root 5.5M Jan  7 08:03 redis-cli
-rwxr-xr-x 1 root root 7.5M Jan  7 08:03 redis-check-rdb
lrwxrwxrwx 1 root root   12 Jan  7 08:03 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root  22K Jan  7 08:03 redis-check-aof

二.修改配置文件.conf

1) 创建配置文件目录,dump file 目录,进程pid目录,log目录等
配置文件一般放在/etc/下,创建redis目录
[root@ip-172-31-46-4 bin]# cd /etc/
[root@ip-172-31-46-4 etc]# mkdir redis

ll 查看创建的redis目录
~
dump file、进程pid、log目录等,一般放在/var/目录下,
[root@ip-172-31-46-4 etc]# cd /var/
[root@ip-172-31-46-4 var]# mkdir redis
[root@ip-172-31-46-4 var]# cd redis
[root@ip-172-31-46-4 redis]# mkdir data log run

至此,目录创建完毕

2)     修改配置文件,配置参数
首先拷贝解压包下的redis.conf文件至/etc/redis
[root@ip-172-31-46-4 redis]# cp ~/redis-stable/redis.conf /etc/redis/

打开配置文件:
[root@ip-172-31-46-4 redis]# vi /etc/redis/redis.conf

修改端口(默认6379)
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

修改pid目录为新建目录
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
pidfile /var/redis/run/redis_6379.pid

修改dump目录为新建目录
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/redis/data

修改log存储目录为新建目录
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile /var/redis/log/redis.log

修改配置文件使得redis在background运行(默认redis服务是console模式运行的)
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

3)持久化
默认rdb,可选择是否开启aof,若开启,修改配置文件appendonly

4)启动redis,查看各目录下文件
[root@ip-172-31-46-4 redis]# cd /usr/bin/
[root@ip-172-31-46-4 bin]# redis-server /etc/redis/redis.conf

redis已启动,查看进程,dump, log, pid等

5)客户端连接redis
[root@ip-172-31-46-4 bin]# redis-cli

默认端口6379

6)至此,redis基础配置完毕,若有其他相关配置调整,可查找文档再修改

三.服务及开机自启动
1)     创建redis启动脚本
拷贝解压包下utils下redis启动脚本至/etc/init.d/
[root@ip-172-31-46-4 bin]# cp ~/redis-stable/utils/redis_init_script /etc/init.d/

修改脚本名称(也可不修改)为redis
[root@ip-172-31-46-4 bin]# mv /etc/init.d/redis_init_script /etc/init.d/redis

修改脚本pid及conf路径为实际路径
[root@ip-172-31-46-4 bin]# vi /etc/init.d/redis_init_script
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/redis/run/redis_${REDISPORT}.pid
CONF="/etc/redis/redis.conf"
 

至此,在/etc/init.d/目录下,已经可以通过:
service redis start/stop 命令启动和关闭redis
 
若在其他目录下,不能够使用这2个命令,请继续配置2),添加权限
2)     给启动脚本添加权限
chmod +x /etc/init.d/redis

实际命令,根据目录的不同,会不一样
相应的删除权限是
chmod –x /etc/init.d/redis
如果需要在开机的时候,redis服务自动启动,可继续3)
3)     设置自启动
chkconfig redis on
如果运行报错,提示

是因为没有在启动脚本里加入redis启动优先级信息,可添加如下

再次执行chkconfig redis on,成功
 
至此,自启动配置完毕

--------------------------------------------------------

安装可能出错的地方:
a.如果提示:
gcc command不识别,请自行安装gcc;
(执行:yum -y install gcc)
b.如果提示:
couldn’t execute tcl : no such file or dicrectory,请自行安装tcl;
(执行:yum install -y tcl)
c.如果提示:
zmalloc.h:51:31: error: jemalloc/jemalloc.h: No such file or directory
原因是编译依赖或原来编译遗留出现的问题
(执行:make distclean)
d.如果提示:
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 `/data0/src/redis-2.6.2/src'
make: *** [all] Error 2zmalloc.h:50:31: error: jemalloc/jemalloc.h:;
原因是jemalloc重载了Linux下的ANSI C的malloc和free函数

(执行:make MALLOC=libc)

进阶:

配置文件说明,请参考:http://www.cnblogs.com/kreo/p/4423362.html

redis集群搭建,请参考:http://www.cnblogs.com/wuxl360/p/5920330.html

AWS EC2 CentOS release 6.5 部署redis的更多相关文章

  1. AWS EC2 CentOS release 6.5 部署zookeeper、kafka、dubbo

    AWS EC2 CentOS release 6.5 部署zookeeper.kafka.dubbo参考:http://blog.csdn.net/yizezhong/article/details/ ...

  2. AWS EC2中部署Apache服务器(LAMP)

    关键词: 1.新建aws ec2实例 2.使用putty连接到aws ec2 实例(SSH协议) 3.使用filezilla连接到aws ec2实例(SFTP协议) 4.在aws ec2上部署apac ...

  3. AWS EC2笔记

    朋友想搭一个境外网站,找我帮忙,希望服务器.域名都在境外.我没有在境外建站的经历,只能先尝试.于是上网搜索了一下境外服务器,大家比较常用的是Digital Ocean和AWS,我索性打开这两家的官网, ...

  4. Redis笔记 -- 在 Centos7.4单机中部署Redis集群(二)

    0x00--背景和目的 在单台PC服务器上部署Redis集群,通过不同的TCP端口启动多实例,模拟多台独立PC组成集群. 0x01--环境描述: Centos版本:CentOS Linux relea ...

  5. 部署Redis Cluster 6.0 集群并开启密码认证 和 Redis-cluster-proxy负载

    部署Redis Cluster集群并开启密码认证 如果只想简单的搭建Redis Cluster,不需要设置密码和公网访问,可以参考官方文档. 节点介绍 Cluster模式推荐最少有6个节点,本次实验搭 ...

  6. Amazon AWS EC2开启Web服务器配置

    在Amazon AWS EC2申请了一年的免费使用权,安装了CentOS + Mono + Jexus环境做一个Web Server使用. 在上述系统安装好之后,把TCP 80端口开启(iptable ...

  7. 在Centos 5.6下安装 redis

    先引用redis官方(http://redis.io/) 的介绍: Redis is an open source, advanced key-value store.<br>It is ...

  8. 如何用docker部署redis cluster

    前言 由于本人是个docker控,不喜欢安装各种环境,而且安装redis-trib也有点繁琐,索性用docker来做redis cluster. 本文用的是伪集群,真正的集群放到不同的机器即可.端口是 ...

  9. AWS EC2服务器的HTTPS负载均衡器配置过程

    AWS EC2服务器配置负载均衡器步骤:   1.普通负载均衡器   至少两台EC2实例,这里以Centos6.7系统为例 启动之后先安装个apache的httpd服务器默认80端口,或者使用其他服务 ...

随机推荐

  1. 使用requirejs来管理angularJS依赖示例

    有关requirejs是什么在这里不做解释,只用纯代码实战让你感受requirejs依赖管理的强大. 一.首先要先下载require.js,然后整一个入口文件main.js包括了对其他js的引用. / ...

  2. vue2.0 带头冲锋(打包时,小心萝卜坑)

    距离上一期,时间间距可能有点长.谁让本人处于兴奋状态,生活已经不能自理. 哈哈哈,嗯,正经一下, 在已有的经验里总结一下那些容易抓狂的坑! 起因:npm run build 打包 本地运行,你以为可以 ...

  3. [C#].Net Core 获取 HttpContext.Current 以及 AsyncLocal 与 ThreadLocal

    在 DotNetCore 当中不再像 MVC5 那样可以通过 HttpContext.Current 来获取到当前请求的上下文. 不过微软提供了一个 IHttpContextAccessor 来让我们 ...

  4. win7下ubuntu14.4双系统安装

    参考https://jingyan.baidu.com/article/f71d60379824041ab641d19d.html

  5. 在脚本中使用source命令不生效

    问题描述    1. 一次写自动化安装脚本,要安装java,需要将JAVA_HOME写到/etc/profile中,然后使用source命令,但是发现profile文件中确实有JAVA_HOME,使用 ...

  6. keil应用小贴士:Use MicroLIB是干什么的

    在keil 建立ARM的工程时,其中有一项是选 use MicroLIB 查了查,得到了以下信息: microlib 是缺省 C 库的备选库. 它旨在与需要装入到极少量内存中的深层嵌入式应用程序配合使 ...

  7. [NOI 2016]区间

    Description 在数轴上有 $n$ 个闭区间 $[l_1,r_1],[l_2,r_2],...,[l_n,r_n]$.现在要从中选出 $m$ 个区间,使得这 $m$ 个区间共同包含至少一个位置 ...

  8. 计蒜客NOIP模拟赛4 D1T3 小X的佛光

    小 X 是远近闻名的学佛,平日里最喜欢做的事就是蒸发学水. 小 X 所在的城市 X 城是一个含有 N 个节点的无向图,同时,由于 X 国是一个发展中国家,为了节约城市建设的经费,X 国首相在建造 X ...

  9. 【BZOJ3224】【tyvj1728】普通平衡树

    最近开始学习平衡树,在学长的强烈推荐下学习了AVL.红黑树.splay(以上我都还没学)treap. 首先讲一下个人对treap(树堆)的理解. treap,顾名思义,就是tree+heap,首先因为 ...

  10. this指针是什么?

    this指针的用处: 一个对象的this指针并不是对象本身的一部分.不会影响sizeof(对象)的结果.this的作用域在类内部,当在类的非静态成员函数中访问类的非静态成员的时候,编译器会自动将对象本 ...