一、启动redis:
首先后台启动需要先修改配置文件,vim 编辑redis.conf前先将其备份到其他目录,以防出错
[root@localhost redis-6.2.1]# cp redis.conf /etc/redis.conf
再将daemonize no改为yes,可在后台启动
# When Redis is supervised by upstart or systemd, this parameter has no impact.
daemonize yes
1.先进入redis安装目录,找到redis-server
[root@localhost local]# cd /usr/local/bin
[root@localhost bin]# ls
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
2.输入命令:redis-server 后加redis.conf配置文件所在位置
[root@localhost etc]# redis-server /etc/redis.conf
3.查看端口是否启动(redis默认端口号6379)
[root@localhost bin]# ps -ef|grep redis
root 3737 1 0 Jul18 ? 00:00:15 redis-server 127.0.0.1:6379
root 16892 8087 0 01:52 pts/4 00:00:00 grep --color=auto redis
4.通过客户端连接redis
[root@localhost bin]# cd /usr/local/bin
[root@localhost bin]# ls
dump.rdb redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
[root@localhost bin]# redis-cli
127.0.0.1:6379> auth 123456
OK
输入沟通命令Ping查看状态,返回PONG,连接成功!
127.0.0.1:6379> ping
PONG
二、关闭redis:
进入终端关闭,输入shutdown(推荐):
127.0.0.1:6379> shutdown
单实例关闭,查看redis端口号,杀掉进程(可能导致数据丢失):
[root@localhost bin]# ps -ef|grep redis
root 3737 1 0 Jul18 ? 00:00:17 redis-server 127.0.0.1:6379
root 17535 8087 0 02:02 pts/4 00:00:00 grep --color=auto redis
[root@localhost bin]# kill -9 3737