AWS EC2 CentOS release 6.5 部署redis

前端之家收集整理的这篇文章主要介绍了AWS EC2 CentOS release 6.5 部署redis前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
AWS EC2 CentOS release 6.5 部署redis @H_403_0@参考:http://blog.csdn.net/ludonqin/article/details/47211109 @H_403_0@ @H_403_0@ @H_403_0@一.安装redis @H_403_0@1) 下载redis安装包 @H_403_0@可去官网http://redis.io ,也可通过wget命令: @H_403_0@[root@ip-172-31-46-4 ~]# wget http://download.redis.io/redis-stable.tar.gz @H_403_0@ @H_403_0@ @H_403_0@2) 解压 @H_403_0@执行命令: @H_403_0@[root@ip-172-31-46-4 ~]# tar –zxvf redis-stable.tar.gz @H_403_0@ @H_403_0@ @H_403_0@3) 编译、安装 @H_403_0@执行命令: @H_403_0@[root@ip-172-31-46-4 ~]# cd redis-stable @H_403_0@ @H_403_0@ @H_403_0@执行命令: @H_403_0@[root@ip-172-31-46-4 redis-stable]# make @H_403_0@ @H_403_0@ @H_403_0@在make成功以后,需要执行命令: @H_403_0@[root@ip-172-31-46-4 redis-stable]# make test @H_403_0@ @H_403_0@ @H_403_0@成功后可手动拷贝src目录下redis-server、redis-cli、redis-check-aof、redis-check-dump等至/usr/local/bin目录下,也可执行命令: @H_403_0@[root@ip-172-31-46-4 redis-stable]# make install @H_403_0@ @H_403_0@ @H_403_0@验证系统目录下启动脚本: @H_403_0@[root@ip-172-31-46-4 ~]# cd /usr/local/bin @H_403_0@[root@ip-172-31-46-4 bin]# ls -ltrh @H_403_0@total 26M @H_403_0@-rwxr-xr-x 1 root root 7.5M Jan 7 08:03 redis-server @H_403_0@-rwxr-xr-x 1 root root 5.4M Jan 7 08:03 redis-benchmark @H_403_0@-rwxr-xr-x 1 root root 5.5M Jan 7 08:03 redis-cli @H_403_0@-rwxr-xr-x 1 root root 7.5M Jan 7 08:03 redis-check-rdb @H_403_0@lrwxrwxrwx 1 root root 12 Jan 7 08:03 redis-sentinel -> redis-server @H_403_0@-rwxr-xr-x 1 root root 22K Jan 7 08:03 redis-check-aof @H_403_0@ @H_403_0@ @H_403_0@ @H_403_0@ @H_403_0@二.修改配置文件.conf @H_403_0@ @H_403_0@ @H_403_0@1) 创建配置文件目录,dump file 目录,进程pid目录,log目录等 @H_403_0@配置文件一般放在/etc/下,创建redis目录 @H_403_0@[root@ip-172-31-46-4 bin]# cd /etc/ @H_403_0@[root@ip-172-31-46-4 etc]# mkdir redis @H_403_0@ @H_403_0@ @H_403_0@ll 查看创建的redis目录 @H_403_0@~ @H_403_0@dump file、进程pid、log目录等,一般放在/var/目录下, @H_403_0@[root@ip-172-31-46-4 etc]# cd /var/ @H_403_0@[root@ip-172-31-46-4 var]# mkdir redis @H_403_0@[root@ip-172-31-46-4 var]# cd redis @H_403_0@[root@ip-172-31-46-4 redis]# mkdir data log run @H_403_0@ @H_403_0@ @H_403_0@至此,目录创建完毕 @H_403_0@ @H_403_0@ @H_403_0@2) 修改配置文件,配置参数 @H_403_0@首先拷贝解压包下的redis.conf文件至/etc/redis @H_403_0@[root@ip-172-31-46-4 redis]# cp ~/redis-stable/redis.conf /etc/redis/ @H_403_0@ @H_403_0@ @H_403_0@打开配置文件: @H_403_0@[root@ip-172-31-46-4 redis]# vi /etc/redis/redis.conf @H_403_0@ @H_403_0@ @H_403_0@修改端口(默认6379) @H_403_0@# Accept connections on the specified port,default is 6379 (IANA #815344). @H_403_0@# If port 0 is specified Redis will not listen on a TCP socket. @H_403_0@port 6379 @H_403_0@ @H_403_0@ @H_403_0@修改pid目录为新建目录 @H_403_0@# Creating a pid file is best effort: if Redis is not able to create it @H_403_0@# nothing bad happens,the server will start and run normally. @H_403_0@pidfile /var/redis/run/redis_6379.pid @H_403_0@ @H_403_0@ @H_403_0@修改dump目录为新建目录 @H_403_0@# The working directory. @H_403_0@# @H_403_0@# The DB will be written inside this directory,with the filename specified @H_403_0@# above using the 'dbfilename' configuration directive. @H_403_0@# @H_403_0@# The Append Only File will also be created inside this directory. @H_403_0@# @H_403_0@# Note that you must specify a directory here,not a file name. @H_403_0@dir /var/redis/data @H_403_0@ @H_403_0@ @H_403_0@修改log存储目录为新建目录 @H_403_0@# Specify the log file name. Also the empty string can be used to force @H_403_0@# Redis to log on the standard output. Note that if you use standard @H_403_0@# output for logging but daemonize,logs will be sent to /dev/null @H_403_0@logfile /var/redis/log/redis.log @H_403_0@ @H_403_0@ @H_403_0@修改配置文件使得redis在background运行(默认redis服务是console模式运行的) @H_403_0@# By default Redis does not run as a daemon. Use 'yes' if you need it. @H_403_0@# Note that Redis will write a pid file in /var/run/redis.pid when daemonized. @H_403_0@daemonize yes @H_403_0@ @H_403_0@ @H_403_0@3)持久化 @H_403_0@默认rdb,可选择是否开启aof,若开启,修改配置文件appendonly @H_403_0@ @H_403_0@ @H_403_0@4)启动redis,查看各目录下文件 @H_403_0@[root@ip-172-31-46-4 redis]# cd /usr/bin/ @H_403_0@[root@ip-172-31-46-4 bin]# redis-server /etc/redis/redis.conf @H_403_0@ @H_403_0@ @H_403_0@redis已启动,查看进程,dump,log,pid等 @H_403_0@ @H_403_0@ @H_403_0@5)客户端连接redis @H_403_0@[root@ip-172-31-46-4 bin]# redis-cli @H_403_0@ @H_403_0@默认端口6379 @H_403_0@ @H_403_0@ @H_403_0@6)至此,redis基础配置完毕,若有其他相关配置调整,可查找文档再修改 @H_403_0@ @H_403_0@ @H_403_0@ @H_403_0@ @H_403_0@三.服务及开机自启动 @H_403_0@1) 创建redis启动脚本 @H_403_0@拷贝解压包下utils下redis启动脚本至/etc/init.d/ @H_403_0@[root@ip-172-31-46-4 bin]# cp ~/redis-stable/utils/redis_init_script /etc/init.d/ @H_403_0@ @H_403_0@ @H_403_0@修改脚本名称(也可不修改)为redis @H_403_0@[root@ip-172-31-46-4 bin]# mv /etc/init.d/redis_init_script /etc/init.d/redis @H_403_0@ @H_403_0@ @H_403_0@修改脚本pid及conf路径为实际路径 @H_403_0@[root@ip-172-31-46-4 bin]# vi /etc/init.d/redis_init_script @H_403_0@REDISPORT=6379 @H_403_0@EXEC=/usr/local/bin/redis-server @H_403_0@CLIEXEC=/usr/local/bin/redis-cli @H_403_0@ @H_403_0@ @H_403_0@PIDFILE=/var/redis/run/redis_${REDISPORT}.pid @H_403_0@CONF="/etc/redis/redis.conf" @H_403_0@ @H_403_0@ @H_403_0@ @H_403_0@至此,在/etc/init.d/目录下,已经可以通过: @H_403_0@service redis start/stop 命令启动和关闭redis @H_403_0@ @H_403_0@若在其他目录下,不能够使用这2个命令,请继续配置2),添加权限 @H_403_0@2) 给启动脚本添加权限 @H_403_0@chmod +x /etc/init.d/redis @H_403_0@ @H_403_0@ @H_403_0@实际命令,根据目录的不同,会不一样 @H_403_0@相应的删除权限是 @H_403_0@chmod –x /etc/init.d/redis @H_403_0@如果需要在开机的时候,redis服务自动启动,可继续3) @H_403_0@3) 设置自启动 @H_403_0@chkconfig redis on @H_403_0@如果运行报错,提示 @H_403_0@ @H_403_0@ @H_403_0@是因为没有在启动脚本里加入redis启动优先级信息,可添加如下 @H_403_0@ @H_403_0@ @H_403_0@再次执行chkconfig redis on,成功 @H_403_0@ @H_403_0@至此,自启动配置完毕 @H_403_0@ @H_403_0@ @H_403_0@-------------------------------------------------------- @H_403_0@ @H_403_0@ @H_403_0@安装可能出错的地方: @H_403_0@a.如果提示: @H_403_0@gcc command不识别,请自行安装gcc; @H_403_0@(执行:yum -y install gcc) @H_403_0@b.如果提示: @H_403_0@couldn’t execute tcl : no such file or dicrectory,请自行安装tcl; @H_403_0@(执行:yum install -y tcl) @H_403_0@c.如果提示: @H_403_0@zmalloc.h:51:31: error: jemalloc/jemalloc.h: No such file or directory @H_403_0@原因是编译依赖或原来编译遗留出现的问题 @H_403_0@(执行:make distclean) @H_403_0@d.如果提示: @H_403_0@zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory @H_403_0@zmalloc.h:55:2: error: #error "Newer version of jemalloc required" @H_403_0@make[1]: *** [adlist.o] Error 1 @H_403_0@make[1]: Leaving directory `/data0/src/redis-2.6.2/src' @H_403_0@make: *** [all] Error 2zmalloc.h:50:31: error: jemalloc/jemalloc.h:; @H_403_0@原因是jemalloc重载了Linux下的ANSI C的malloc和free函数 @H_403_0@

(执行:make MALLOC=libc)

@H_403_0@

进阶:

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

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

猜你在找的CentOS相关文章