Redis安装与部署
一、安装
$ wget https://download.redis.io/releases/redis-6.2.6.tar.gz
$ tar xzf redis-6.2.6.tar.gz
$ cd redis-6.2.6
$ make
$ make install
二、前台启动
- 编译好的二进制文件在 src 目录里。启动 Redis:
$ src/redis-server
三、后台启动
- 复制配置文件到/etc目录下
[root@localhost redis]# cp redis.conf /etc/redis.conf
- etc目录下
[root@localhost etc]# vim redis.conf
- 修改配置 daemonize no为yes
252 ################################# GENERAL ################################# ####
253
254 # By default Redis does not run as a daemon. Use 'yes' if you need it.
255 # Note that Redis will write a pid file in /var/run/redis.pid when daemoniz ed.
256 # When Redis is supervised by upstart or systemd, this parameter has no imp act.
257 daemonize yes
- 启动
[root@localhost redis-6.2.6]# cd /usr/local/bin/
[root@localhost bin]# ./redis-server /etc/redis.conf
- 报错解决
[root@localhost bin]# ls
# 若没有以下文件,执行make install
redis-benchmark redis-check-rdb redis-sentinel
redis-check-aof redis-cli redis-server
四、连接Redis与关闭
- 使用内置的客户端与Redis通讯:
[root@localhost bin]# ./redis-cli
127.0.0.1:6379> shutdown
not connected> exit
[root@localhost bin]#
五、切换数据库
- 一共16个数据库,默认0号
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]>