CentOS7安装Redis

Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。

和Memcached类似,它支持存储的value类型相对更多。数据都是缓存在内存中。会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步。Redis 是一个高性能的key-value数据库。redis的出现,很大程度补偿了memcached这类key/value存储的不足,在部 分场合可以对关系数据库起到很好的补充作用。

安装Redis:

[root@redis ~]# yum install redisLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: hkg.mirror.rackspace.com * extras: mirrors.163.com * updates: mirrors.aliyun.comResolving Dependencies--> Running transaction check---> Package redis.x86_64 0:3.2.12-2.el7 will be installed--> Processing Dependency: libjemalloc.so.1()(64bit) for package: redis-3.2.12-2.el7.x86_64--> Running transaction check---> Package jemalloc.x86_64 0:3.6.0-1.el7 will be installed--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================================================================================== Package                                            Arch                                             Version                                                  Repository                                      Size===================================================================================================================================================================================================================Installing: redis                                              x86_64                                           3.2.12-2.el7                                             epel                                           544 kInstalling for dependencies: jemalloc                                           x86_64                                           3.6.0-1.el7                                              epel                                           105 k
Transaction Summary===================================================================================================================================================================================================================Install  1 Package (+1 Dependent package)
Total download size: 648 kInstalled size: 1.7 MIs this ok [y/d/N]: yDownloading packages:(1/2): jemalloc-3.6.0-1.el7.x86_64.rpm                                                                                                                                                      | 105 kB  00:00:00     (2/2): redis-3.2.12-2.el7.x86_64.rpm                                                                                                                                                        | 544 kB  00:00:00     -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total                                                                                                                                                                              925 kB/s | 648 kB  00:00:00     Running transaction checkRunning transaction testTransaction test succeededRunning transaction  Installing : jemalloc-3.6.0-1.el7.x86_64                                                                                                                                                                     1/2   Installing : redis-3.2.12-2.el7.x86_64                                                                                                                                                                       2/2   Verifying  : redis-3.2.12-2.el7.x86_64                                                                                                                                                                       1/2   Verifying  : jemalloc-3.6.0-1.el7.x86_64                                                                                                                                                                     2/2 
Installed:  redis.x86_64 0:3.2.12-2.el7
Dependency Installed:  jemalloc.x86_64 0:3.6.0-1.el7
Complete!

查看安装路径:

[root@redis ~]# rpm -ql redis/etc/logrotate.d/redis/etc/redis-sentinel.conf/etc/redis.conf/etc/systemd/system/redis-sentinel.service.d/etc/systemd/system/redis-sentinel.service.d/limit.conf/etc/systemd/system/redis.service.d/etc/systemd/system/redis.service.d/limit.conf/usr/bin/redis-benchmark/usr/bin/redis-check-aof/usr/bin/redis-check-rdb/usr/bin/redis-cli/usr/bin/redis-sentinel/usr/bin/redis-server/usr/lib/systemd/system/redis-sentinel.service/usr/lib/systemd/system/redis.service/usr/libexec/redis-shutdown/usr/share/doc/redis-3.2.12/usr/share/doc/redis-3.2.12/00-RELEASENOTES/usr/share/doc/redis-3.2.12/BUGS/usr/share/doc/redis-3.2.12/CONTRIBUTING/usr/share/doc/redis-3.2.12/MANIFESTO/usr/share/doc/redis-3.2.12/README.md/usr/share/licenses/redis-3.2.12/usr/share/licenses/redis-3.2.12/COPYING/usr/share/man/man1/redis-benchmark.1.gz/usr/share/man/man1/redis-check-aof.1.gz/usr/share/man/man1/redis-check-rdb.1.gz/usr/share/man/man1/redis-cli.1.gz/usr/share/man/man1/redis-sentinel.1.gz/usr/share/man/man1/redis-server.1.gz/usr/share/man/man5/redis-sentinel.conf.5.gz/usr/share/man/man5/redis.conf.5.gz/var/lib/redis/var/log/redis/var/run/redis

编辑/etc/redis.conf:

[root@redis ~]# vim /etc/redis.conf

修改绑定的IP,由127.0.0.1(环回地址) 改为0.0.0.0(通配):

################################## NETWORK #####################################
# By default, if no "bind" configuration directive is specified, Redis listens# for connections from all the network interfaces available on the server.# It is possible to listen to just one or multiple selected interfaces using# the "bind" configuration directive, followed by one or more IP addresses.## Examples:## bind 192.168.1.100 10.0.0.1# bind 127.0.0.1 ::1## ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the# internet, binding to all the interfaces is dangerous and will expose the# instance to everybody on the internet. So by default we uncomment the# following bind directive, that will force Redis to listen only into# the IPv4 lookback interface address (this means Redis will be able to# accept connections only from clients running into the same computer it# is running).## IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES# JUST COMMENT THE FOLLOWING LINE.# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~bind 0.0.0.0

默认是不用密码的,修改为我们自己设定的密码:

################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other# commands.  This might be useful in environments in which you do not trust# others with access to the host running redis-server.## This should stay commented out for backward compatibility and because most# people do not need auth (e.g. they run their own servers).## Warning: since Redis is pretty fast an outside user can try up to# 150k passwords per second against a good box. This means that you should# use a very strong password otherwise it will be very easy to break.## requirepass foobaredrequirepass mypassword

开机自动启动服务:

[root@redis ~]# systemctl enable redisCreated symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.

启动服务:

[root@redis ~]# systemctl start redis

查看服务状态:

[root@redis ~]# systemctl status redis● redis.service - Redis persistent key-value database   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)  Drop-In: /etc/systemd/system/redis.service.d           └─limit.conf   Active: active (running) since Wed 2019-09-25 09:17:02 CST; 32s ago Main PID: 3123 (redis-server)   CGroup: /system.slice/redis.service           └─3123 /usr/bin/redis-server 0.0.0.0:6379
Sep 25 09:17:02 redis systemd[1]: Starting Redis persistent key-value database...Sep 25 09:17:02 redis systemd[1]: Started Redis persistent key-value database.

开放端口6379,可以远程访问:

firewall-cmd --permanent --zone=public --add-port=6379/tcpfirewall-cmd --reload

Redis-cli客户端访问服务是否正常(如设置了密码则需要登录):

[root@redis ~]# redis-cli127.0.0.1:6379> AUTH mypasswordOK127.0.0.1:6379> HELPredis-cli 3.2.12To get help about Redis commands type:      "help @<group>" to get a list of commands in <group>      "help <command>" for help on <command>      "help <tab>" to get a list of possible help topics      "quit" to exit
To set redis-cli perferences:      ":set hints" enable online hints      ":set nohints" disable online hints

至此,Redis 服务安装、配置完毕~

注:本文为Toyo Lau原创,未经许可不得在任何平台转载,侵权必究。如需转载,可关注微信公众号:技术训练营,在后台留言,与作者联系,取得许可才能转载~

原创声明,本文系作者授权云+社区发表,未经许可,不得转载。

如有侵权,请联系 yunjia_community@tencent.com 删除。

编辑于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Python疯子

Python使用RMF聚类分析客户价值

投资机构或电商企业等积累的客户交易数据繁杂。需要根据用户的以往消费记录分析出不同用户群体的特征与价值,再针对不同群体提供不同的营销策略。

9740
来自专栏木二天空

002.Kubernetes简单入门实例

提示:若不关闭鉴权,可能出现以下报错:Error creating: No API token found for service account "defau...

6820
来自专栏服务器使用遇到的坑洞

mysql远程访问开启(Navicat Premium)

数据库安全策略设置,我没用也可以成功;我是用mysql5.56 和 mariadb 10.3.15 没问题;

10520
来自专栏Java那些事

MongoDB【快速入门】

MongoDB(来自于英文单词“Humongous”,中文含义为“庞大”)是可以应用于各种规模的企业、各个行业以及各类应用程序的开源数据库。作为一个适用于敏捷开...

6310
来自专栏PingCAP的专栏

Unified Thread Pool | Hackathon 2019 优秀项目介绍

距离 TiDB Hackathon 落幕已经过去了半个多月,回忆这次比赛、获奖的经历,依然让我感到非常兴奋。我目前是华南理工大学大三的学生,我和正在 PingC...

7120
来自专栏Java研发军团

【附源码】大厂的分开库分表详解!!!

不管是IO瓶颈,还是CPU瓶颈,最终都会导致数据库的活跃连接数增加,进而逼近甚至达到数据库可承载活跃连接数的阈值。在业务Service来看就是,可用数据库连接少...

8830
来自专栏搜云库技术团队

使用 Redis 如何实现点赞,取消点赞呢?

本文基于 SpringCloud, 用户发起点赞、取消点赞后先存入 Redis 中,再每隔两小时从 Redis 读取点赞数据写入数据库中做持久化存储。

12220
来自专栏happyJared

Docker 下载镜像

要运行容器,就必须保证本地存在对应的镜像。所以,第一步是需要下载镜像。当尝试下载镜像时,Docker 会尝试先从默认的镜像仓库(默认使用 Docker Hub ...

8220
来自专栏小麦苗的DB宝专栏

【DB笔试面试688】在Oracle中,跟踪会话执行语句的方法有哪几种?

因为TRACE的目标范围不同,所以导致必须使用不同的方法。若作用于数据库全局的,则改初始化参数。若只作用于当前会话的,则就用ALTER SESSION命令。若作...

7230
来自专栏杨建荣的学习笔记

MySQL中的SQL优化建议那么多,该如何有的放矢

今天早上看到同事的一个优化需求,优化的时间其实不多,但是对于这条SQL的优化思考了很多,希望有一些参考。

10230

扫码关注云+社区

领取腾讯云代金券

年度创作总结 领取年终奖励