0%

Redis安装

安装redis

官网下载链接:https://download.redis.io/releases/

安装基础环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 安装基础环境
yum -y install gcc wget
cd /usr/local/src/
# 下载redis
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
tar xf redis-6.2.6.tar.gz -C /usr/local/
cd /usr/local/redis-6.2.6/
# 编译安装redis
make
make PREFIX=/usr/local/redis-6.2.6 install
# 修改内核参数
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
echo "net.core.somaxconn = 1024" >> /etc/sysctl.conf
sysctl -p
echo "* soft nofile 10240" >> /etc/security/limits.conf
echo "* hard nofile 10240" >> /etc/security/limits.conf

常用配置项

1
2
3
4
5
6
7
8
# 监听地址,默认是127.0.0.1,不允许其他机器访问
bind 192.168.6.143
# 监听端口
port 6379
# 后台启动
daemonize yes
# 设置redis密码
requirepass n9zxcCynQy#j4du

启动redis

1
2
3
4
/usr/local/redis-6.2.6/bin/redis-server /usr/local/redis-6.2.6/redis.conf
# 配置开机自启动
echo "/usr/local/redis-6.2.6/bin/redis-server /usr/local/redis-6.2.6/redis.conf" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local

清理缓存

1
2
3
4
5
6
7
8
9
10
11
# 清空当前数据库的所有key
flushdb
#清空整个Redis服务器的所有数据
flushall

#当前数据库的 key 的数量
dbsize
#查看所有key值
keys *
#切换数据库(默认有16个库,0-15)
select 1