CentOS7 安装 Redis

# 检查系统是否已经安装 mysql

rpm -qa|grep redis

[aaron@localhost /]$ rpm -qa|grep redis
[aaron@localhost /]$   #说明没有安装过mysql
1
2
3
4

# 下载安装文件

wget http://download.redis.io/releases/redis-5.0.5.tar.gz

[root@localhost download]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
1
2
3

# 解压安装包

tar -zxvf redis-5.0.5.tar.gz
1

# 进入解压后的文件目录使用 make 命令进行编译

[root@yangliangxi redis-5.0.5]# make

    CC blocked.o
    CC hyperloglog.o
    CC latency.o
    CC sparkline.o
    CC redis-check-rdb.o
    CC redis-check-aof.o
    CC geo.o
    CC lazyfree.o
    CC module.o
    CC evict.o
    CC expire.o
    CC geohash.o
    CC geohash_helper.o
    CC childinfo.o
    CC defrag.o
    CC siphash.o
    CC rax.o
    CC t_stream.o
    CC listpack.o
    CC localtime.o
    CC lolwut.o
    CC lolwut5.o
    LINK redis-server
    INSTALL redis-sentinel
    CC redis-cli.o
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    INSTALL redis-check-rdb
    INSTALL redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: 离开目录“/home/aaron/redis-5.0.5/src”
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

# 进入 src 文件执行 make install 安装 redis

[root@yangliangxi src]# make install
    CC Makefile.dep

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
1
2
3
4
5
6
7
8
9
10

# 在 src 目录执行 ./redis-server 即可启动 redis

[root@yangliangxi src]# ./redis-server
14518:C 14 Mar 2023 13:38:57.401 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
14518:C 14 Mar 2023 13:38:57.401 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=14518, just started
14518:C 14 Mar 2023 13:38:57.401 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
14518:M 14 Mar 2023 13:38:57.401 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 14518
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

14518:M 14 Mar 2023 13:38:57.402 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
14518:M 14 Mar 2023 13:38:57.402 # Server initialized
14518:M 14 Mar 2023 13:38:57.402 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
14518:M 14 Mar 2023 13:38:57.402 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
14518:M 14 Mar 2023 13:38:57.402 * Ready to accept connections
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# 修改配置实现 redis 后台运行、远程连接访问

# 在 redis 的安装目录找到 redis.conf 配置文件进行修改

修改配置

进入redis.conf的编辑模式

vi redis.conf
1

# 找到bind 127.0.0.1并将其注释

使用"/ 要搜索的内容",回车,直接快速定位文档中的位置

注释bind

# 如果是本地服务器或者虚拟机,则需要放开对应端口

// 在防火墙添加不拦截6379
firewall-cmd --zone=public --add-port=6379/tcp --permanent

// 重启防火墙
firewall-cmd --reload

// 查看防火墙开放端口
firewall-cmd --list-all
1
2
3
4
5
6
7
8

# 如果是腾讯云或者阿里云,需要开放 6379 的端口

注释bind

# 在 redis.conf 配置文件中找到以下几个配置进行修改

// 修改保护模式,不修改保护模式也是只能内网访问的 protected-mode yes 改成 protected-mode no
protected-mode no

// daemonize no 改为yes 后台一直运行
daemonize yes

// 设置密码,这里建议设置密码,否则可能会发生一些预料不到的事情,因为6379端口有漏洞
requirepass "你的密码"
1
2
3
4
5
6
7
8
上次更新: 2025/02/15, 13:42:25
最近更新
01
Git问题集合
01-29
02
安装 Nginx 服务器
01-25
03
安装 Docker 容器
01-25
更多文章>
×
×