CentOS安装Redis

【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】

**开源地址:https://docs.qq.com/doc/DSmxTbFJ1cmN1R2dB **

Redis6.x.x版本支持了多线程,需要gcc的版本大于4.9,我们需要查看默认GCC版本,如果版本过低则需要升级

gcc -v

我的新安装的虚拟机CentOS显示 ->

image.png

证明我的没有安装gcc,安装gcc ->

yum install gcc

image.png

再次查看安装后的版本,发现是4.8.5,这个是CentOS默认的版本,我们需要对gcc进行升级 ->

yum -y install centos-release-scl

yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

scl enable devtoolset-9 bash

echo “source /opt/rh/devtoolset-9/enable” >>/etc/profile

查看升级后的版本 ->

image.png

5、编译安装

cd redis-6.2.4/src

make install

编译过程如下 ->

image.png

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

image.png

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

redis-sentinel

redis-server

redis-cli

image.png

6、修改配置文件

Redis的配置文件在解压目录下的 redis.conf

image.png

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的文档配置注释,我们要运行其他主机访问有多种方式 ->

  1. 可以选择配置访问主机的IP address

  2. bind * -:😗 相当于允许所有其它主机访问

  3. bind 0.0.0.0 相当于允许所有其它主机访问

  4. 直接注释 相当于允许所有其它主机访问

# 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

我的处理方式,安装文档的注释来配置

image.png

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

  • 26
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值