标签:release
基于CentOS release 6.5 Final, redis版本3.0.2 [redis版本号中间位是偶数的是稳定版,奇数的为非稳定版]
一、安装redis
1) 下载redis安装包
可去官网http://redis.io ,也可通过wget命令,
[root@wenjia srv]# wget http://download.redis.io/redis-stable.tar.gz
2)解压
[root@wenjia srv]# tar -zxvf redis-stable.tar.gz
3)编译、安装(编译安装安装Development tools和Desktop Platfrom 开发包组工具)
[root@wenjia srv]# cd redis-stable
[root@wenjia redis-stable]# ll
total 200
-rw-r--r--. 1 1000 1000 78892 Oct 26 15:17 00-RELEASENOTES
-rw-r--r--. 1 1000 1000 53 Oct 26 15:17 BUGS
-rw-r--r--. 1 1000 1000 1805 Oct 26 15:17 CONTRIBUTING
-rw-r--r--. 1 1000 1000 1487 Oct 26 15:17 COPYING
drwxr-xr-x. 7 1000 1000 4096 Oct 26 15:17 deps
-rw-r--r--. 1 1000 1000 11 Oct 26 15:17 INSTALL
-rw-r--r--. 1 1000 1000 151 Oct 26 15:17 Makefile
-rw-r--r--. 1 1000 1000 4223 Oct 26 15:17 MANIFESTO
-rw-r--r--. 1 1000 1000 6834 Oct 26 15:17 README.md
-rw-r--r--. 1 1000 1000 46695 Oct 26 15:17 redis.conf
-rwxr-xr-x. 1 1000 1000 271 Oct 26 15:17 runtest
-rwxr-xr-x. 1 1000 1000 280 Oct 26 15:17 runtest-cluster
-rwxr-xr-x. 1 1000 1000 281 Oct 26 15:17 runtest-sentinel
-rw-r--r--. 1 1000 1000 7606 Oct 26 15:17 sentinel.conf
drwxr-xr-x. 2 1000 1000 4096 Oct 26 15:17 src
drwxr-xr-x. 10 1000 1000 4096 Oct 26 15:17 tests
drwxr-xr-x. 7 1000 1000 4096 Oct 26 15:17 utils
[root@wenjia redis-stable]# make
CC geo.o
LINK redis-server
INSTALL redis-sentinel
CC redis-cli.o
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
INSTALL redis-check-rdb
CC redis-check-aof.o
LINK redis-check-aof
Hint: It‘s a good idea to run ‘make test‘ ;)
make[1]: Leaving directory `/srv/redis-stable/src‘
[root@wenjia redis-stable]# make install
cd src && make install
make[1]: Entering directory `/srv/redis-stable/src‘
Hint: It‘s a good idea to run ‘make test‘ ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory `/srv/redis-stable/src‘
[root@wenjia redis-stable]#
[root@wenjia redis-stable]# ls /usr/local/bin
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
[root@wenjia redis-stable]#
[root@wenjia redis-stable]# /usr/local/bin/redis-server -v
Redis server v=3.2.5 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=661b15c1ebfa36b
注意:若此时执行redis-server –v (查看版本命令),若提示redis-server command not found,则需要将/usr/local/bin目录加到环境变量,如何添加,此处不做详细介绍,可查看修改/etc/profile,(查看环境变量命令:echo $PATH)
至此,redis安装完成,接着配置。
二、修改配置文件.conf
1)创建配置文件目录,dump file目录,进程目录,log目录等
配置文件一般放在/etc/下,创建fedis目录
[root@wenjia redis-stable]# cd /etc/
[root@wenjia etc]# mkdir redis
dump file、进程目录、log目录等,一般放在/var/目录下,
[root@wenjia etc]# cd redis/
[root@wenjia redis]# ls
[root@wenjia redis]# cd /var
[root@wenjia var]# mkdir redis
[root@wenjia var]# cd redis/
[root@wenjia redis]# mkdir data log run
[root@wenjia redis]# ll
total 12
drwxr-xr-x. 2 root root 4096 Dec 5 15:58 data
drwxr-xr-x. 2 root root 4096 Dec 5 15:58 log
drwxr-xr-x. 2 root root 4096 Dec 5 15:58 run
[root@wenjia redis]#
至此目录创建完毕。
2)修改配置文件,配置参数
首先拷贝解压包下的redis.conf文件至/etc/redis
[root@wenjia redis-stable]# cp redis.conf /etc/re
readahead.conf redhat-lsb/ redhat-release redis/ resolv.conf resolv.conf.save
[root@wenjia redis-stable]# cp redis.conf /etc/redis/
[root@wenjia redis-stable]# vi /etc/redis/redis.conf 最好备份一份redis.conf.bak
# 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
#####修改默认端口
# 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/run/redis_6379.pid
#####修改pid目录为新建的目录
# 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 ./
#####修改dump目录为新建目录
# 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 ""
#####修改log存储目录为新建目录
3)持久化
默认rdb,可选择是否开启aof,若开启,修改配置文件appendonly
4)启动redis,查看各目录下文件
[root@wenjia redis-stable]# redis-server /etc/redis/redis.conf
查看dump,log,pid等
[root@wenjia redis]# cd data
[root@wenjia data]# ll
total 0
[root@wenjia data]# ll../log
-bash: ll../log: No such file or directory
[root@wenjia data]# ll ../log
total 4
-rw-r--r--. 1 root root 1861 Dec 5 16:15 redis.log
[root@wenjia data]# ll ../run
total 4
-rw-r--r--. 1 root root 6 Dec 5 16:15 redis_6379.pid
[root@wenjia data]#
发现只有日志,没有dump和pid信息,是因为当前redis服务仍然是console模式运行的,且没有数据存储操作
停止redis服务,修改配置文件使得redis在background运行
改成yes,保存,重启redis服务
5)客户端连接redis
[root@wenjia run]# redis-cli
127.0.0.1:6379> #####默认端口6379
6)至此,redis基础配置完毕,若有其他相关配置调整,可查找文档在修改
三、服务及开机自启动
1)创建redis启动脚本
拷贝解压包下utils下redis启动脚本至/etc/init.d
[root@wenjia redis-stable]# cd /srv/redis-stable/utils/
[root@wenjia utils]# cp redis_init_script /etc/init.d/
修改脚本名称为redis 并修改脚本pid及conf路径为实际路径
至此,在/etc/init.d目录下,已经可以通过service redis start/stop 启动/关闭redis服务了。
2、给启动脚本添加删除权限
#chmod +x /etc/init.d/redis 给启动脚本添加权限
#chmod -x /etc/init.d/redis 删除权限
3、设置自启动
#chkconfig redis on
如果运行报错,提示
[root@wenjia init.d]# chkconfig redis on
service redis does not support chkconfig
是因为没有在启动脚本里加入redis启动优先级信息,可添加如下
再次执行chkconfig redis on,成功,至此自启动配置完毕。
本实验参考http://blog.csdn.net/ludonqin/article/details/47211109此文档完成。
标签:release
原文地址:http://liwenjia.blog.51cto.com/2656598/1879613