您的位置:首页 > 数据库 > Redis

redis安装与配置

2016-01-22 13:55 555 查看

redis安装

1、下载redis

下载地址http://redis.io/download

2、安装redis

下载后解压 tar zxvf redis-3.0.6.tar.gz 到任意目录,例如/usr/local/redis

解压后,进入redis目录

cd /usr/local/redis
make
cp redis.conf /etc/ 这个文件时redis启动的配置文件
cp redis-benchmark redis-cli redis-server /usr/bin/


3、启动redis服务

[root@localhost ~]# redis-server /etc/redis.conf

6229:M 22 Jan 14:03:11.096 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-``    `.  `_.  ''-._           Redis 3.0.6 (00000000/0) 64 bit
.-`` .-```.  ```\/    _.,_ ''-._
(    '      ,       .-`  | `,    )     Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
|    `-._   `._    /     _.-'    |     PID: 6229
`-._    `-._  `-./  _.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|    `-._`-._        _.-'_.-'    |           http://redis.io `-._    `-._`-.__.-'_.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|    `-._`-._        _.-'_.-'    |
`-._    `-._`-.__.-'_.-'    _.-'
`-._    `-.__.-'    _.-'
`-._        _.-'
`-.__.-'

6229:M 22 Jan 14:03:11.096 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn
is set to the lower value of 128.6229:M 22 Jan 14:03:11.097 # Server started, Redis version 3.0.6
6229:M 22 Jan 14:03:11.097 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To
fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.6229:M 22 Jan 14:03:11.099 * DB loaded from disk: 0.003 seconds
6229:M 22 Jan 14:03:11.099 * The server is now ready to accept connections on port 6379


查看进程,确认redis已经启动

[root@localhost ~]# ps -ef|grep redis
root      6229  2270  0 14:03 pts/0    00:00:00 redis-server *:6379
root      6257  6236  0 14:04 pts/1    00:00:00 grep redis


上面的启动方法并没有在后台启动,修改redis.conf,设置redis进程为后台守护进程

# 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              #redis后台运行
dir /usr/local/redis       #指定持久化文件保存路径


4、测试redis

[root@localhost ~]# redis-cli
127.0.0.1:6379> set name songbin
OK
127.0.0.1:6379> get name
"songbin"


5、关闭redis服务

[root@localhost ~]#redis-cli shutdown


6、自启动脚本

[root@localhost redis]# cp utils/redis_init_script /etc/init.d/redis
[root@localhost redis]#vi /etc/init.d/redis
#chkconfig: 2345 80 90
REDISPORT=6379
EXEC=/usr/bin/redis-server
CLIEXEC=/usr/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/redis.conf"


添加 #chkconfig: 2345 80 90

并修改配置文件路径 ,以及redis-server路径

[root@localhost redis]# chkconfig --add redis
[root@localhost redis]# chkconfig redis on
[root@localhost redis]# service redis start
Starting Redis server...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: