下载
redis建议安装在linux下,windows版本老旧,且问题奇多。所以这里使用linux进行演示。
在https://download.redis.io/releases/redis-6.2.6.tar.gz 地址进行下载最新稳定版redis。
安装
对redis进行解压,编译安装。
<pre data-language="shell" style="margin: 0px; padding: 16px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); font-size: 13px; color: rgb(89, 89, 89);">wget http://download.redis.io/releases/redis-6.2.6.tar.gz
tar xzf redis-6.2.6.tar.gz
cd redis-6.2.6
make</pre>
启动
编译安装完成后,可以在redis目录中的src下使用redis-server进行启动。
<pre data-language="shell" style="margin: 0px; padding: 16px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); font-size: 13px; color: rgb(89, 89, 89);">cd ./redis/src
./redis-server</pre>
出现上面的显示,表示redis已经成功启动了。
然后新打开一个终端,同样进入src目录,启动redis-cli。对其进行测试
<pre data-language="shell" style="margin: 0px; padding: 16px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); font-size: 13px; color: rgb(89, 89, 89);"> cd redis/src/
./redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
</pre>
出现上面的显示,表示redis已经安装成功。
创建运行目录并把redis-cli 和redis-server进行复制到 /usr/local/redis 中
<pre data-language="shell" style="margin: 0px; padding: 16px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); font-size: 13px; color: rgb(89, 89, 89);">mkdir /usr//local/redis
cp redis-cli redis-server /usr/local/redis
</pre>
把运行目录也拷贝到运行目录
<pre data-language="shell" style="margin: 0px; padding: 16px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); font-size: 13px; color: rgb(89, 89, 89);">cd ..
cp redis.conf /usr/local/redis/</pre>
配置
使redis后台运行,需要修改redis.conf文件。找到daemonize 修改为yes ,表示后台启动redis
启动时带上配置文件进行启动
<pre data-language="shell" style="margin: 0px; padding: 16px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; border-width: 1px; border-style: solid; border-color: rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); font-size: 13px; color: rgb(89, 89, 89);">./redis-server redis.conf</pre>
查看进程,可以看到redis已经启动完成了
如果需要远程链接redis,需要继续修改redis.conf文件,将bind 127.0.0.1 -::1 进行注释
在启动中还有可能会遇到以下报错:
这个报错代表着,redis开启了保护模式,可以通过设置密码或者修改配置文件,bind ip地址的方式来进行规避。这里选择去掉保护模式,同样打开redis.conf 文件。将protected-mode 改为no
如果要绑定IP使用上面的bind就可以做到,如果要修改密码,可以使用requirepass来进行设置。