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