转载自 https://www.dbalog.net,转载请注明出处
1、下载Redis
-
[root@lb03 src]# wget http://download.redis.io/releases/redis-3.0.6.tar.gz
2、解压编译
-
[root@lb03 src]# tar -zxvf redis-3.0.6.tar.gz
-
[root@lb03 src]# cd redis-3.0.6
-
[root@lb03 redis-3.0.6]# make
3、启停服务
-
启动:
-
[root@lb03 redis-3.0.6]# src/redis-server
-
[root@lb03 redis-3.0.6]# src/redis-server & #放入后台 或者修改daemonize 参数为yes
-
启动后提示redis的默认端口是6379
-
停止:
-
启动后前台会被占用,如需停止服务,ctrol+c即可,或者
-
[root@lb03 redis-3.0.6]# src/redis-cli shutdown
4、连接测试
-
[root@lb03 redis-3.0.6]# src/redis-cli
-
127.0.0.1:6379> set name kaodaxia
-
OK
-
127.0.0.1:6379> get name
-
"kaodaxia"
-
127.0.0.1:6379>
5、修改redis随Linux系统自动启动
-
方法1:
-
[root@lb03 redis-3.0.6]# vi /etc/rc.local
-
#!/bin/sh
-
#
-
# This script will be executed *after* all the other init scripts.
-
# You can put your own initialization stuff in here if you don't
-
# want to do the full Sys V style init stuff.
-
touch /var/lock/subsys/local
-
/usr/local/src/redis-3.0.6/src/redis-server #增加此行,保证随机启动
-
方法2:
-
[root@lb03 redis-3.0.6]# mkdir /etc/redis
-
[root@lb03 redis-3.0.6]# cp redis.conf /etc/redis/6379.conf #为什么是6379.cof
-
#看下utils/redis_init_script启动脚本就明白
-
[root@lb03 redis-3.0.6]# cp utils/redis_init_script /etc/init.d/redisd
-
[root@lb03 redis-3.0.6]# chkconfig redisd on
-
redisd 服务不支持 chkconfig
-
报错了 ,在启动脚本添加如下两行注释即可:
-
[root@lb03 redis-3.0.6]# vi /etc/init.d/redisd
-
#!/bin/sh
-
#
-
# Simple Redis init.d script conceived to work on Linux systems
-
# as it does use of the /proc filesystem.
-
# chkconfig: 2345 90 10
-
# description: Redis is a persistent key-value database
-
[root@lb03 redis-3.0.6]# service redisd stop
-
Stopping ...
-
Redis stopped
-
[root@lb03 redis-3.0.6]# service redisd start
-
Starting Redis server...
-
注意:启动脚本开头需要修改下PIDFILE的变量值
* 推荐使用方法2,不仅自动启动,还可以使用redis的启停脚本
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29335267/viewspace-2126189/
,如需转载,请注明出处,否则将追究法律责任。