安装
安装命令
yum install redis
安装完毕
# 查看安装包
[root@star ~]# rpm -qa|grep redis
redis-6.0.5-1.11.al8.x86_64
#查看安装的路径
[root@star ~]# rpm -ql redis-6.0.5-1.11.al8.x86_64
/etc/logrotate.d/redis
/etc/redis-sentinel.conf
/etc/redis.conf
/etc/systemd/system/redis-sentinel.service.d
/etc/systemd/system/redis-sentinel.service.d/limit.conf
/etc/systemd/system/redis.service.d
找到redis.conf所在目录/etc/redis.conf
修改配置文件
vi /etc/redis.conf
仅修改: daemonize yes (no–>yes)
启动redis服务
sudo redis-server /etc/redis.conf
查看服务是否启动
[root@star ~]# ps aux | grep redis-server
root 278819 0.1 0.9 274152 18412 ? Ssl Dec22 1:06 redis-server 127.0.0.1:6379
root 279801 0.0 0.0 221460 796 pts/0 S+ 10:08 0:00 grep --color=auto redis-server
使用redis客户端
[root@star ~]# redis-cli
127.0.0.1:6379> set age 10
OK
127.0.0.1:6379> get age
"10"
开启远程服务
非专业人士千万别开启redis远程服务啊,我就中招了,装完redis的之后,我的阿里云服务器就显示cpu使用率100%,使用top查看显示正常,但是阿里云也给我发邮件提示恶意执行的命令行,自己整了好长时间也没解决,所以大家开启远程服务和端口一定要慎之又慎,而且之前的不知道自己的服务器被这么多人访问过。
#查看访问失败的记录
cat /var/log/secure* | grep Failed
修改配置文件redis.conf
vi /etc/redis.conf
#注释bind 127.0.0.1
#修改 protected-mode yes改为protected-mode no
#保存退出
重启服务
sudo redis-server /etc/redis.conf
服务器开放端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
此处注意端口号后面要加上协议,否则会报错
Error: INVALID_PORT: bad port (most likely missing protocol), correct syntax is portid[-portid]/protocol