一、安装redis
注:先在阿里云的服务器防火墙上加上6379的端口号
1.yum安装 yum install redis
- 遇到 Is this ok [y/N]: 选 y
- 出现 Complete! 代表安装完成
[root@iZbp1cyapchvqkm4fmxcliZ ~]# yum install redis
Last metadata expiration check: 2:40:55 ago on Fri 05 Feb 2021 12:16:16 PM CST.
Dependencies resolved.
==============================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================
Installing:
redis x86_64 5.0.3-2.module_el8.2.0+318+3d7e67ea AppStream 925 k
Enabling module streams:
redis 5
Transaction Summary
==============================================================================================================================
Install 1 Package
Total download size: 925 k
Installed size: 3.2 M
Is this ok [y/N]: y
Downloading Packages:
redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64.rpm 8.1 MB/s | 925 kB 00:00
------------------------------------------------------------------------------------------------------------------------------
Total 8.0 MB/s | 925 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64 1/1
Installing : redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64 1/1
Running scriptlet: redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64 1/1
Verifying : redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64 1/1
Installed:
redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64
Complete!
2.启动服务 service redis start
查看服务 service redis status
[root@iZbp1cyapchvqkm4fmxcliZ ~]# service redis start
Redirecting to /bin/systemctl start redis.service
[root@iZbp1cyapchvqkm4fmxcliZ ~]# service redis status
Redirecting to /bin/systemctl status redis.service
● redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis.service.d
└─limit.conf
Active: active (running) since Fri 2021-02-05 14:57:46 CST; 8s ago
Main PID: 68289 (redis-server)
Tasks: 4 (limit: 11498)
Memory: 6.5M
CGroup: /system.slice/redis.service
└─68289 /usr/bin/redis-server 127.0.0.1:6379
Feb 05 14:57:46 iZbp1cyapchvqkm4fmxcliZ systemd[1]: Starting Redis persistent key-value database...
Feb 05 14:57:46 iZbp1cyapchvqkm4fmxcliZ systemd[1]: Started Redis persistent key-value database.
3. 服务验证 redis-cli
[root@iZbp1cyapchvqkm4fmxcliZ ~]# redis-cli
127.0.0.1:6379> help
redis-cli 5.0.3
To 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 preferences:
":set hints" enable online hints
":set nohints" disable online hints
Set your preferences in ~/.redisclirc
127.0.0.1:6379> quit
4. 开机启动 systemctl enable redis
[root@iZbp1cyapchvqkm4fmxcliZ ~]# systemctl enable redis
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.
二、配置环境变量
修改 /etc/redis.conf 文件
1. 端口
- 查一下文件中有没有6379端口,有的话忽略这项,没有的话把这一行代码加在末尾
port 6379
2.安装成功后有可能会导致远程连接不上,需要对文件进行以下三项修改
把protected-mode yes改为protected-mode no(在没有密码的情况下,关闭保护模式)
注释掉bind 127.0.0.1 (取消绑定本地地址)
把daemonize no改为daemonize yes (是否为进程守护,关闭ssh窗口后即是否在后台继续运行)