Redis入门以及在Linux下的环境搭建(解决三个Warning和启动服务器以及客户端)

(目录

一、在CentOS下搭建redis环境

二、启动redis服务器和客户端,尝试简单命令

三、总结



一、在CentOS下搭建redis环境

su     //用root用户执行后续操作
wget http://download.redis.io/redis-stable.tar.gz
tar xzf redis-stable.tar.gz
cd redis-stable
make
make install    //把可执行程序复制到/usr/local/bin中,方便后面直接使用命令redis-server

 如图:

注意这个时候你下载的redis-stable是在你的主用户文件中,如此时是在我的/home/winwin文件中,因为此时我打开终端没进行cd操作进入的目录~就是我的主用户目录。

如图:

然后输入redis-server出现了下列3个报错:

第一个Warning: no config file specified, using the default config.
In order to specify a config file use 'redis-server /path/to/redis.conf'

警告:没有明确的config文件,使用默认配置。为了明确配置文件请使用'redis-server /path/to/redis.conf'

解决:redis-server /home/你的用户名/redis-stable/redis-conf

或者你也可以找到redis-conf文件把他cp复制到你熟悉的目录下如cp redis-conf /etc

第二个Warning:WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

警告:无法强制执行TCP backlog设置511,因为/proc/sys/net/core/somaxconn设置为较低的值128。

解决:echo 511 > /proc/sys/net/core/somaxconn,如果这里511写不进去,你可以vi/etc/sysctl.conf  里面添net.core.somaxconn= 1024,然后执行sysctl -p 就可以永久消除这个warning

第三个Warning:overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to/etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

警告:overcommit_memory参数设置为0!在内存不足的情况下,后台程序save可能失败。建议在文件 /etc/sysctl.conf 中将overcommit_memory修改为1。

解决:sysctl vm.overcommit_memory=1


 


二、启动redis服务器和客户端,尝试简单命令

上述三个警告解决后,输入redis-server /home/kie/redis-stable/redis.conf不再出现redis一系列的信息说明,如果你要查看redis的pid等信息可以输入redis-server来查询,如图:

 

尝试一下简单命令

set test1 1          /设置键test1,并赋值为1
set test2 2 
keys *                 /查询所有键名
get test1             /获取test1的键值
get test2

 


三、总结

wget云下载redis-stable后解压缩到主用户目录下,解决三个警告,启动redis服务器,再启动redis服务端,出现127.0.0.1:6379>的交互模式,最后进行了简单的redis命令测试。
 


  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我的思路很明确

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值