redis安装和使用
2016-08-02 本文已影响216人
大龄程序员在帝都
1、安装redis:
上传文件到固定目录下;版本为: redis-3.2.0
tar xzvf redis-3.2.0.tar.gz
cd redis-3.2.0
make && make install
2、启动redis
redis-server redis.conf
3、一般不会在原配置文件上进行修改,原配置文件相当于备份。所以在centos7上创建
mkdir /etc/redis
4、拷贝redis原配置文件到 /etc/redis
cp redis.conf /etc/redis/
按照最新的配置文件启动:
redis-server /etc/redis/redis.conf
启动后如果直接关闭命令行窗口,redis会在后台运行,但是不能按ctrl+c,如果按这个会终止redis,所以直接关掉窗口即可
[root@localhost ~]# ps -ef |grep redis
root 30337 1 0 09:10 ? 00:00:00 redis-server 127.0.0.1:6379
root 32116 28120 0 09:18 pts/1 00:00:00 grep --color=auto redis
以上redis就启动了!
5、启动后,如何关闭redis?
redis-cli shutdown
[root@localhost ~]# redis-cli shutdown
[root@localhost ~]# ps -ef |grep redis
root 32257 28120 0 09:19 pts/1 00:00:00 grep --color=auto redis
执行后redis就关闭了。
6、redis添加后台启动
daemonize yes
7、配置redis日志文件位置:
logfile "/Users/wang/Documents/redis.log"
7、添加到
开机启动配置
echo "/usr/local/bin/redis-server /etc/redis/redis.conf &" >> /etc/rc.local
8、添加密码
vi /etc/redis/redis.conf
require pass paas2016
添加密码paas2016
redis是默认不允许其他客户端连接的:
需要在配置文件中放开: bind 127.0.0.1 才能允许其他客户端操作
客户端连接:
ss:~ wqp$ redis-cli -h hostname -p 6379 -a paas2016
hostname:6379> set aa "aaaa"
OK
hostname:6379> get aa
"aaaa"