前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS7安装Redis

CentOS7安装Redis

原创
作者头像
技术训练营
修改2019-12-05 18:15:04
4990
修改2019-12-05 18:15:04
举报
文章被收录于专栏:操作系统

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

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

安装Redis:

代码语言:javascript
复制
[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!

查看安装路径:

代码语言:javascript
复制
[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:

代码语言:javascript
复制
[root@redis ~]# vim /etc/redis.conf

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

代码语言:javascript
复制
################################## 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

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

代码语言:javascript
复制
################################## 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

开机自动启动服务:

代码语言:javascript
复制
[root@redis ~]# systemctl enable redisCreated symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.

启动服务:

代码语言:javascript
复制
[root@redis ~]# systemctl start redis

查看服务状态:

代码语言:javascript
复制
[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,可以远程访问:

代码语言:javascript
复制
firewall-cmd --permanent --zone=public --add-port=6379/tcpfirewall-cmd --reload

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

代码语言:javascript
复制
[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原创,未经许可不得在任何平台转载,侵权必究。如需转载,可关注微信公众号:技术训练营,在后台留言,与作者联系,取得许可才能转载~

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

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 Redis
腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档