设为首页 收藏本站
查看: 804|回复: 0

[经验分享] centos 6.5 安装、配置redis

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-12-6 08:46:15 | 显示全部楼层 |阅读模式
基于CentOS release 6.5 Final, redis版本3.0.2 [redis版本号中间位是偶数的是稳定版,奇数的为非稳定版]
一、安装redis

1)     下载redis安装包

可去官网http://redis.io ,也可通过wget命令,


[iyunv@wenjia srv]# wget http://download.redis.io/redis-stable.tar.gz

2)解压
[iyunv@wenjia srv]# tar -zxvf redis-stable.tar.gz
3)编译、安装(编译安装安装Development tools和Desktop Platfrom 开发包组工具)
[iyunv@wenjia srv]# cd redis-stable
[iyunv@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

[iyunv@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'
[iyunv@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'
[iyunv@wenjia redis-stable]#
[iyunv@wenjia redis-stable]# ls /usr/local/bin
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server
[iyunv@wenjia redis-stable]#
[iyunv@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目录


[iyunv@wenjia redis-stable]# cd /etc/
[iyunv@wenjia etc]# mkdir redis

dump file、进程目录、log目录等,一般放在/var/目录下,


[iyunv@wenjia etc]# cd redis/
[iyunv@wenjia redis]# ls
[iyunv@wenjia redis]# cd /var
[iyunv@wenjia var]# mkdir redis
[iyunv@wenjia var]# cd redis/
[iyunv@wenjia redis]# mkdir data log run
[iyunv@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
[iyunv@wenjia redis]#
至此目录创建完毕。
2)修改配置文件,配置参数
首先拷贝解压包下的redis.conf文件至/etc/redis

[iyunv@wenjia redis-stable]# cp redis.conf /etc/re
readahead.conf    redhat-lsb/       redhat-release    redis/            resolv.conf       resolv.conf.save
[iyunv@wenjia redis-stable]# cp redis.conf /etc/redis/
[iyunv@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,查看各目录下文件

[iyunv@wenjia redis-stable]# redis-server /etc/redis/redis.conf

查看dump,log,pid等


[iyunv@wenjia redis]# cd data
[iyunv@wenjia data]# ll
total 0
[iyunv@wenjia data]# ll../log
-bash: ll../log: No such file or directory
[iyunv@wenjia data]# ll ../log
total 4
-rw-r--r--. 1 root root 1861 Dec  5 16:15 redis.log
[iyunv@wenjia data]# ll ../run
total 4
-rw-r--r--. 1 root root 6 Dec  5 16:15 redis_6379.pid
[iyunv@wenjia data]#

发现只有日志,没有dump和pid信息,是因为当前redis服务仍然是console模式运行的,且没有数据存储操作

停止redis服务,修改配置文件使得redis在background运行

20150804102119940.jpg

改成yes,保存,重启redis服务

5)客户端连接redis


[iyunv@wenjia run]# redis-cli
127.0.0.1:6379>    #####默认端口6379

6)至此,redis基础配置完毕,若有其他相关配置调整,可查找文档在修改
三、服务及开机自启动

1)创建redis启动脚本

拷贝解压包下utils下redis启动脚本至/etc/init.d

[iyunv@wenjia redis-stable]# cd /srv/redis-stable/utils/
[iyunv@wenjia utils]# cp redis_init_script /etc/init.d/
修改脚本名称为redis 并修改脚本pid及conf路径为实际路径
QQ截图20161206084640.png
至此,在/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
如果运行报错,提示
[iyunv@wenjia init.d]# chkconfig redis on
service redis does not support chkconfig
是因为没有在启动脚本里加入redis启动优先级信息,可添加如下
QQ截图20161206084620.png
再次执行chkconfig redis on,成功,至此自启动配置完毕。





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-310269-1-1.html 上篇帖子: service redis does not support chkconfig 下篇帖子: Redis 未授权访问缺陷可轻易导致系统被黑【SSV-89715】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表