【赵渝强老师】Redis的安装与访问

在这里插入图片描述

  本文将基于Redis 6.2版本进行讲解,并将Redis部署在CentOS 7 64位的虚拟机环境中。下图展示了Redis官方网站提供的Redis下载信息。
在这里插入图片描述

提示:由于Redis基于C语言开发,因此在安装CentOS 7的时候需要安装GCC编译器。GCC(GNU Compiler Collection,GNU编译器套件)是由GNU开发的编程语言译器。GNU编译器套件包括C、C++、 Objective-C、Fortran、Java、Ada和Go语言前端,也包括了这些语言的库。

  视频讲解如下:

Redis的安装与访问

【赵渝强老师】Redis的安装与访问

  下面通过具体的步骤来安装部署Redis。
(1)创建Redis的安装目录。

mkdir /root/training/

(2)解压Redis的安装包。

tar -zxvf redis-6.2.6.tar.gz
cd redis-6.2.6/

(3)编译Redis,并将其安装到/root/training/redis目录下。

make
make PREFIX=/root/training/redis install

(4)将Redis的配置文件redis.conf复制到/root/training/redis/conf目录下。

mkdir /root/training/redis/conf
cp redis.conf /root/training/redis/conf

(5)查看Redis的目录结构。

tree /root/training/redis/

输出的信息如下
/root/training/redis/
├── bin
│   ├── redis-benchmark						Redis基准测试工具
│   ├── redis-check-aof -> redis-server		AOF持久化文件检测和修复工具
│   ├── redis-check-rdb -> redis-server		RDB持久化文件检测和修复工具
│   ├── redis-cli							Redis客户端程序
│   ├── redis-sentinel -> redis-server		Redis哨兵启动程序
│   └── redis-server						Redis服务器端启动程序
└── conf
    └── redis.conf
2 directories, 7 files

(6)使用vi编辑器修改/root/training/redis/conf/redis.conf的文件。

......
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE 
# INTERFACES JUST COMMENT OUT THE FOLLOWING LINE.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# bind 127.0.0.1 -::1		注释掉该行
......
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no			将protected-mode改为no
......
################### GENERAL ###################

# 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.
# When Redis is supervised by upstart or systemd, this parameter has 
# no impact. 
daemonize yes				将daemonize改为yes
......

(7)在默认情况下,Redis没有启用系统日志功能。为了能够更好地监控Redis,建议在生产环境中启用Redis的系统日志。修改/root/training/redis/conf/redis.conf的文件。

......
# Specify the server verbosity level.
# This can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel notice

# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile "/root/training/redis/redis.log"	设置Redis系统日志文件
......

(8)进入Redis的安装目录,执行bin目录下的redis-server命令启动Redis。

bin/redis-server conf/redis.conf

(9)查看文件/root/training/redis/redis.log的内容。

......
*** #oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
*** #Redis version=6.2.6,bits=64,commit=00000000,modified=0,
*** #pid=121814,just started
*** #Configuration loaded
*** *Increased maximum number of open files to 10032
*** #(it was originally set to 1024).
*** *monotonic clock: POSIX clock_gettime
*** *Running mode=standalone, port=6379.
......
*** #Server initialized
......
*** *Ready to accept connections
......

提示:从redis.log文件中可以看出,当前Redis实例是一个单节点实例并且Redis Server默认监听6379端口。

(10)使用ps命名查看Redis的后台进程信息。

ps -ef|grep redis

输出的信息如下:
root     121814      1  0 09:59 ?        00:00:00 bin/redis-server *:6379
root     121902 116943  0 10:05 pts/1 	 00:00:00 grep --color=auto redis

(11)使用Redis的客户端工具登录Redis Server。

bin/redis-cli

(12)执行info命令查看Redis Server的统计信息。

127.0.0.1:6379> info
输出的信息如下:
# Server
redis_version:6.2.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:d9df5c2d7eb8e995
redis_mode:standalone
os:Linux 3.10.0-693.el7.x86_64 x86_64
arch_bits:64
......
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

赵渝强老师

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

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

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

打赏作者

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

抵扣说明:

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

余额充值