资讯专栏INFORMATION COLUMN

Centos下Redis的安装与配置

233jl / 289人阅读

摘要:没有官方的版本,微软开源技术团队开发和维护着的版本,但并不建议用于生产环境。这里主要介绍下安装,以及配置,后台运行以及自动启动等。

Redis 没有官方的Windows版本,微软开源技术团队(Microsoft Open Tech group)开发和维护着 Win64 的版本,但并不建议用于生产环境。

这里主要介绍Centos下安装Redis,以及配置redis,后台运行以及自动启动等。

安装

官方下载地址为:https://redis.io/download

[root@localhost ~]# wget http://download.redis.io/releases/redis-4.0.6.tar.gz

解压

[root@localhost ~]# tar xzf redis-4.0.6.tar.gz

编译

[root@localhost ~]# cd redis-4.0.6
[root@localhost redis-4.0.6]# make

安装,官网并没有这个操作,执行这个的目的就是将可执行文件拷贝到/usr/local/bin/目录下,这样就可以直接执行redis-serverredis-cli 等命令了。

[root@localhost redis-4.0.6]# make install

安装完成,查看版本

[root@localhost redis-4.0.6]# redis-server -v
Redis server v=4.0.6 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=4f1a60f0053726b7

启动 redis-server

[root@localhost redis-4.0.6]# redis-server 
9961:C 12 Dec 05:14:58.101 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9961:C 12 Dec 05:14:58.101 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=9961, just started
9961:C 12 Dec 05:14:58.101 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
                _._                                                  
           _.-``__ ""-._                                             
      _.-``    `.  `_.  ""-._           Redis 4.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```/    _.,_ ""-._                                   
 (    "      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|"` _.-"|     Port: 6379
 |    `-._   `._    /     _.-"    |     PID: 9961
  `-._    `-._  `-./  _.-"    _.-"                                   
 |`-._`-._    `-.__.-"    _.-"_.-"|                                  
 |    `-._`-._        _.-"_.-"    |           http://redis.io        
  `-._    `-._`-.__.-"_.-"    _.-"                                   
 |`-._`-._    `-.__.-"    _.-"_.-"|                                  
 |    `-._`-._        _.-"_.-"    |                                  
  `-._    `-._`-.__.-"_.-"    _.-"                                   
      `-._    `-.__.-"    _.-"                                       
          `-._        _.-"                                           
              `-.__.-"                                               

9961:M 12 Dec 05:14:58.105 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
9961:M 12 Dec 05:14:58.105 # Server initialized
9961:M 12 Dec 05:14:58.105 # 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.
9961:M 12 Dec 05:14:58.105 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command "echo never > /sys/kernel/mm/transparent_hugepage/enabled" as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
9961:M 12 Dec 05:14:58.105 * Ready to accept connections

看到以上页面就启动成功啦,我们新开一个终端去连接redis。

[root@localhost ~]# redis-cli
127.0.0.1:6379> set name zhangsan
OK
127.0.0.1:6379> get name
"zhangsan"
127.0.0.1:6379> keys *
1) "name"
127.0.0.1:6379> 

可有些童鞋就疑惑了,为什么运行redis-server后,不能退出后台运行呢,如果关闭终端,不就连redis一起关闭了吗?
请继续往下看……

后台运行

拷贝redis.conf配置文件到/etc/redis

在刚解压的redis根目录执行:

[root@localhost redis-4.0.6]# mkdir /etc/redis
[root@localhost redis-4.0.6]# cp redis.conf /etc/redis/

编辑配置文件

[root@localhost redis-4.0.6]# vim /etc/redis/redis.conf 

找到daemonize no 改为daemonize yes

# By default Redis does not run as a daemon. Use "yes" if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

指定配置文件启动redis

[root@localhost redis-4.0.6]# redis-server  /etc/redis/redis.conf 
9999:C 12 Dec 05:31:11.872 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9999:C 12 Dec 05:31:11.872 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=9999, just started
9999:C 12 Dec 05:31:11.872 # Configuration loaded
[root@localhost redis-4.0.6]# 

是不是可以后台启动了呢?

最后

有些童鞋可能还是有疑惑,如何能让redis开机启动?又如何能让redis像服务一样启动或停止,类似下面的操作呢?

#打开服务
service redisd start
#关闭服务
service redisd stop
更新内容,请查看原文:http://www.tech1024.com/origi...

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/36795.html

相关文章

  • CentOS(linux) Redis安装(Nginx+Tomcat集群第三步:负载均衡+Ses

    摘要:注意如果图片显示不正常把这个改成。使用库方式切换操作各个数据库保存快照的频率,第一个表示多长时间,第二个表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。保存快照是否使用压缩数据快照文件名只是文件名,不包括目录。 Nginx+Tomcat集群第三步(负载均衡+基于Spring Boot的Session共享) Nginx和Tomcat没安装好的可以参考前两步: Ce...

    sixleaves 评论0 收藏0
  • CentOS(linux) Redis安装(Nginx+Tomcat集群第三步:负载均衡+Ses

    摘要:注意如果图片显示不正常把这个改成。使用库方式切换操作各个数据库保存快照的频率,第一个表示多长时间,第二个表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。保存快照是否使用压缩数据快照文件名只是文件名,不包括目录。 Nginx+Tomcat集群第三步(负载均衡+基于Spring Boot的Session共享) Nginx和Tomcat没安装好的可以参考前两步: Ce...

    王伟廷 评论0 收藏0
  • CentOS(linux) Redis安装(Nginx+Tomcat集群第三步:负载均衡+Ses

    摘要:注意如果图片显示不正常把这个改成。使用库方式切换操作各个数据库保存快照的频率,第一个表示多长时间,第二个表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。保存快照是否使用压缩数据快照文件名只是文件名,不包括目录。 Nginx+Tomcat集群第三步(负载均衡+基于Spring Boot的Session共享) Nginx和Tomcat没安装好的可以参考前两步: Ce...

    EscapedDog 评论0 收藏0
  • CentOS(linux) Redis安装(Nginx+Tomcat集群第三步:负载均衡+Ses

    摘要:注意如果图片显示不正常把这个改成。使用库方式切换操作各个数据库保存快照的频率,第一个表示多长时间,第二个表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。保存快照是否使用压缩数据快照文件名只是文件名,不包括目录。 Nginx+Tomcat集群第三步(负载均衡+基于Spring Boot的Session共享) Nginx和Tomcat没安装好的可以参考前两步: Ce...

    LittleLiByte 评论0 收藏0
  • CentOS(linux) Redis安装(Nginx+Tomcat集群第三步:负载均衡+Ses

    摘要:注意如果图片显示不正常把这个改成。使用库方式切换操作各个数据库保存快照的频率,第一个表示多长时间,第二个表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。保存快照是否使用压缩数据快照文件名只是文件名,不包括目录。 Nginx+Tomcat集群第三步(负载均衡+基于Spring Boot的Session共享) Nginx和Tomcat没安装好的可以参考前两步: Ce...

    cjie 评论0 收藏0
  • centos配置redis

    摘要:本文详细介绍单机单实例安装与配置,服务及开机自启动。注意若此时执行查看版本命令,若提示,则需要将目录加到环境变量,如何添加,此处不做详细介绍,可查看修改,查看环境变量命令正常如下至此,安装完成,接着配置。 本文详细介绍Redis单机单实例安装与配置,服务及开机自启动。(以下配置基于CentOS release 6.5 Final, redis版本3.0.2 [redis版本号中间位是偶...

    graf 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<