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

CentOS安装redis

2016-12-08 14:38 197 查看
由于公司的项目需要用到redis技术,这两天就在研究这玩意,首先在linux安装redis

cd /usr/local


然后下载安装包:
wget http://download.redis.io/releases/redis-3.2.5.tar.gz


版本可自行去http://download.redis.io/releases/ 选择

下载完毕后就是解压拉
tar zvxf redis-3.2.5.tar.gz
然后把文件夹改名。。
mv redis-3.2.5.tar.gz redis


安装依赖(安装过可以省略)
yum install gcc
然后安装
make
make install
这时不出意外的话已经安装好了

然后我们把redis注册成服务
cp /usr/local/redis/utils/redis_init_script /etc/rc.d/init.d/redis
使用vim修改配置文件
vim /etc/rc.d/init.d/redis


把 chkconfig: 2345 80 90 加在第二行 2345表示系统运行级别是2,3,4或者5时启动服务,80启动优先级别

90是关闭的优先级别
#!/bin/sh 
#chkconfig: 2345 80 90 
# Simple Redis init.d script conceived to work on Linux systems 
# as it does use of the /proc filesystem.

.....
注册服务:
chkconfig --add redis
这时已经可以用命令启动服务了
service redis start


不过默认启动服务是在前台界面所以需要去修改配置文件

将redis配置文件拷贝到/etc/redis/${REDISPORT}.conf 
mkdir /etc/redis

cp /usr/local/src/redis/redis.conf /etc/redis/6379.conf
//修改配置文件
vim /etc/redis/6379.conf
修改daemonize为yes,即默认以后台程序方式运行

如果需要密码验证的可以找到# requirepass foobared

把#去掉 把foobared换成自己的密码
requirepass "helloRedis"


#检测后台进程是否存在
ps -ef |grep redis


#检测6379端口是否在监听
netstat -lntp | grep 6379


去客户端测试
cd /usr/local/bin
./redis-cli
127.0.0.1:6379> keys *
//如果设置了密码会出现如下错误
(error) NOAUTH Authentication required.
//键入auth 加你的密码就可以了
127.0.0.1:6379> auth helloRedis
OK
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> shutdown
not connected> quit
借阅几篇文章,终于写好了这篇文章
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  redis linux 技术