您好,欢迎访问一九零五行业门户网

详解如何安装和配置Redis(Linux环境)

如何安装redis?下面本篇文章给大家介绍一下linux环境下安装和配置redis的方法。
【相关推荐:redis视频教程】
一、准备好 gcc 环境yum install gcc-c++
出现以下日志,代表安装成功。package gcc-c++-4.8.5-39.el7.x86_64 already installed and latest version
loaded plugins: fastestmirrordetermining fastest mirrorsbase | 3.6 kb 00:00:00 docker-ce-stable | 3.5 kb 00:00:00 epel | 4.7 kb 00:00:00 extras | 2.9 kb 00:00:00 nginx | 2.9 kb 00:00:00 updates | 2.9 kb 00:00:00 (1/7): epel/x86_64/group_gz | 95 kb 00:00:00 (2/7): epel/x86_64/updateinfo | 1.0 mb 00:00:00 (3/7): docker-ce-stable/x86_64/primary_db | 45 kb 00:00:00 (4/7): extras/7/x86_64/primary_db | 205 kb 00:00:00 (5/7): updates/7/x86_64/primary_db | 3.0 mb 00:00:00 (6/7): epel/x86_64/primary_db | 6.8 mb 00:00:00 (7/7): nginx/x86_64/primary_db | 55 kb 00:00:02 package gcc-c++-4.8.5-39.el7.x86_64 already installed and latest versionnothing to do[root@root ~]#
二、下载并安装redis执行命令:wget http://download.redis.io/releases/redis-5.0.7.tar.gz。下载完成之后进行解压。再先后执行 make、make install命令。
[root@root /]# cd usr/java[root@root java]# mkdir redis[root@root java]# cd redis/[root@root redis]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz[root@root redis]# tar -zxvf redis-5.0.7.tar.gz[root@root redis]# cd redis-5.0.7[root@root redis-5.0.7]# make[root@root redis-5.0.7]# make install
三、启动输入命令:redis-server redis.conf ,启动redis。看到以下页面代表启动成功。
[root@root redis-5.0.7]# redis-server redis.conf _._ _.-``__ ''-._ _.-`` `. `_. ''-._ redis 5.0.7 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| port: 6379 | `-._ `._ / _.-' | pid: 12513 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'
但是这种启动没有办法在这个tab页下做任何操作了,因为这个时候使用ctrl+c之后,就变成了这个样子。也就是关闭了redis,这种方式是前台启动。
^c13082:signal-handler (1594381754) received sigint scheduling shutdown...13082:m 10 jul 2020 19:49:14.132 # user requested shutdown...13082:m 10 jul 2020 19:49:14.132 * saving the final rdb snapshot before exiting.13082:m 10 jul 2020 19:49:14.135 * db saved on disk13082:m 10 jul 2020 19:49:14.135 * removing the pid file.13082:m 10 jul 2020 19:49:14.135 # redis is now ready to exit, bye bye...
四、后台启动打开redis.conf 文件。这也是redis的配置文件。
[root@root redis-5.0.7]# vim redis.conf #打开之后,在命令窗口按下/输入daem然后回车
修改为yes
daemonize yes
redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程,启用守护进程后,redis会把pid写到一个pidfile中,在/var/run/redis_6379.pid文件中。
再次启动
[root@root redis-5.0.7]# redis-server redis.conf 13352:c 10 jul 2020 19:54:34.301 # oo0ooo0ooo0oo redis is starting oo0ooo0ooo0oo13352:c 10 jul 2020 19:54:34.301 # redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=13352, just started13352:c 10 jul 2020 19:54:34.301 # configuration loaded
五、连接redis[root@root redis-5.0.7]# redis-cli 127.0.0.1:6379> pingpong127.0.0.1:6379> config get requirepass#查看密码1) "requirepass"2) ""127.0.0.1:6379>
设置密码
我们发现竟然不需要密码就可以进入redis。那怎么设置呢?
requirepass foobared:设置 redis 连接密码,如果配置了连接密码,客户端在连接 redis 时需要通过 auth password命令提供密码,默认是关闭。
1、临时设置
config set requirepass 123456
2、永久设置
[root@root redis-5.0.7]# vim redis.conf#打开之后,在命令窗口按下/输入 requirepass 然后回车
找到如图所示的内容,将注释放开设置自己的密码。
然后重启redis。
[root@root redis-5.0.7]# redis-server redis.conf [root@root redis-5.0.7]# redis-cli 127.0.0.1:6379> ping(error) noauth authentication required.127.0.0.1:6379> auth xxxok127.0.0.1:6379> pingpong127.0.0.1:6379>
可以看到第一次ping的时候提示我需要身份验证。auth xxx这是连接后输入密码。也可以在连接的时候输入:
[root@root redis-5.0.7]# redis-cli -p 6379 -a xxx
在线体验:try.redis.io/
本文转载自:https://juejin.cn/post/6979019298543140901#heading-4
作者:程序员小杰
更多编程相关知识,请访问:编程教学!!
以上就是详解如何安装和配置redis(linux环境)的详细内容。
其它类似信息

推荐信息