CentOS 安装 Redis,java 程序员进阶路线
5、编译安装
cd?redis-6.2.4/src
make?install
编译过程如下 ->

看到如下结果输出则编译成功 ->

?
或者在 src 目录下出现服务端和客户端的脚本 ->
redis-sentinel
redis-server
redis-cli

6、修改配置文件
Redis 的配置文件在解压目录下的 redis.conf

6.1 首先设置后台启动,防止窗口一关闭服务就挂掉
默认后台启动参数为 no ->
#?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?no
修改成 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.
#?When?Redis?is?supervised?by?upstart?or?systemd,?this?parameter?has?no?impact.
daemonize?yes
6.2 允许其他主机访问
根据 Redis 的文档配置注释,我们要运行其他主机访问有多种方式 ->
可以选择配置访问主机的 IP address
bind * -::* 相当于允许所有其它主机访问
bind 0.0.0.0 相当于允许所有其它主机访问
直接注释 相当于允许所有其它主机访问
#?bind?192.168.1.100?10.0.0.1?????#?listens?on?two?specific?IPv4?addresses
#?bind?127.0.0.1?::1??????????????#?listens?on?loopback?IPv4?and?IPv6
#?bind??-::?????????????????????#?like?the?default,?all?available?interfaces
我的处理方式,安装文档的注释来配置

6.3 配置访问密码
如果是要考虑安全性,一定要配置密码,找到 requirepass 配置处,新增如下配置(阿里云等云服务其外网访问一定要配置,作者被黑过,整台服务器重启都无法重启,损失惨重,但是穷,官方处理需要 Money,建议这里一定要谨慎)
requirepass?yourpassword
7、启动 Redis
使用 redis-server 来启动,启动的方式如下->
/usr/local/soft/redis-6.2.4/src/redis-server?/usr/local/soft/redis-6.2.4/redis.conf
或者这个也一样 ->
cd?/src
redis-server??../redis.conf
查看端口是否启动成功 ->
netstat?-an|grep?6379?

8、客户端
进入客户端的方式如下 ->
/usr/local/soft/redis-6.2.4/src/redis-cli

9、停止 Redis
停止 Redis 有两种方式 :
方式一,在客户端中执行 SHUTDOWN
SHUTDOWN

方式二,暴力 kill -9
ps?-aux?|?grep?redis
kill?-9?57927

10、配置别名
为了方便启动 Redis 和进入客户端,我们可以通过配置别名来实现
vim?~/.bashrc
添加如下配置
注意**''**很重要
redis 与 rcli 后面的=两边不能有空格
alias?redis='/usr/local/soft/redis-6.2.4/src/redis-server?/usr/local/soft/redis-6.2.4/redis.conf'
alias?rcli='/usr/local/soft/redis-6.2.4/src/redis-cli'

使配置生效
评论