查看是否安装了redis
yum installed list | grep redis
ps -ef | grep redis
安装epel 仓库(仓库是软件包下载的,类似maven,nuget)
yum install epel-release
搜索 redis 包
yum search redis
安装:
yum install redis
查看配置:
rpm -ql redis
rpm -qc redis
rpm -qv redis
rpm -qi redis
yum install redis
# 查看是否卸载了
rpm -qi redis
上面是安装的 3.x 太旧了,可用使用下面的方法安装最新版:
yum -y update
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum --enablerepo=remi install redis
rpm -qi redis
配置开机启动:
systemctl enable --now redis
绑定IP,只允许本机访问:
# 备份 /etc/redis.conf
# 打开 vi /etc/redis.conf
# 跳转到66行:66gg
bind 127.0.0.1 ::1
# 配置密码
requirepass 123456
# 重启服务
systemctl restart redis
查看redis监听端口:
ss -tunelp | grep 6379
连接 redis
redis-cli
auth 123456
# 查看 redis 信息
info server
# 压力测试
redis-benchmark -h 127.0.0.1 -p 6379 -n 10000 -c 15 -a 123456
参考:https://www.digitalocean.com/community/tutorials/how-to-install-secure-redis-centos-7
其他源,
https://computingforgeeks.com/how-to-install-latest-redis-on-centos-rhel/
yum remove redis
rpm -qi redis
下载最新稳定版:
cd /usr/local/
wget http://download.redis.io/releases/redis-7.2.4.tar.gz
# 解压
tar -zxvf redis-7.2.4.tar.gz -C /usr/local/
# 安装
cd /redis-7.2.4
make
make install
# 启动
redis-server
# 后台启动
nohup redis-server &
# 配置后台启动
redis-server /usr/local/redis-7.2.4/redis.conf
配置开机自启动
# vi /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
Restart=always
[Install]
WantedBy=multi-user.target
重新加载:
systemctl daemon-reload
设置 redis 用户和用户组权限
useradd redis
mkdir /etc/redis
chown redis:redis /etc/redis
cp /usr/local/redis-7.2.4/redis.conf /etc/redis/redis.conf
# 设置开机启动服务
systemctl enable redis.service
处理报错,一开始直接用的root配置的,后来加了 redis 用户,并且把配置移动到 /etc/redis 后,解决。
Failed to write PID file: Permission denied
Jan 14 18:04:43 iZ8vb396j1s3u6ajh598vtZ postfix/master[1089]: warning: process /usr/libexec/postfix/pickup pid 28545 exit status 127
Jan 14 18:04:43 iZ8vb396j1s3u6ajh598vtZ postfix/master[1089]: warning: /usr/libexec/postfix/pickup: bad command startup -- throttling
Jan 14 18:05:18 iZ8vb396j1s3u6ajh598vtZ systemd[1]: redis.service start operation timed out. Terminating.
Jan 14 18:05:18 iZ8vb396j1s3u6ajh598vtZ redis-server[28496]: 28496:signal-handler (1705226718) Received SIGTERM scheduling shutdown...
Jan 14 18:05:19 iZ8vb396j1s3u6ajh598vtZ redis-server[28496]: 28496:M 14 Jan 2024 18:05:19.017 * User requested shutdown...
Jan 14 18:05:19 iZ8vb396j1s3u6ajh598vtZ redis-server[28496]: 28496:M 14 Jan 2024 18:05:19.017 * Saving the final RDB snapshot before exiting.
Jan 14 18:05:19 iZ8vb396j1s3u6ajh598vtZ redis-server[28496]: 28496:M 14 Jan 2024 18:05:19.020 * DB saved on disk
Jan 14 18:05:19 iZ8vb396j1s3u6ajh598vtZ redis-server[28496]: 28496:M 14 Jan 2024 18:05:19.020 * Removing the pid file.
Jan 14 18:05:19 iZ8vb396j1s3u6ajh598vtZ redis-server[28496]: 28496:M 14 Jan 2024 18:05:19.020 # Redis is now ready to exit, bye bye...
客户端软链接
find / -name redis-cli
ln -s /usr/loca/bin/redis-cli /usr/bin/redis
# 测试
redis
netstat -ntulp | grep 6379
netstat -ntulp | grep redis
Redis 客户端:
https://github.com/RedisInsight/RedisDesktopManager