【教程】Linux安装Redis步骤记录
下载地址
安装redis-7.4.0.tar.gz
1.下载安装包
wget https://download.redis.io/releases/redis-7.4.0.tar.gz
2.解压
tar -zxvf redis-7.4.0.tar.gz
3.进入目录
cd redis-7.4.0/
4.编译
make
5.安装
make install PREFIX=/usr/local/redis
6.配置文件
将解压之后的redis目录下的 redis.conf 文件复制到这里
/usr/local/redis/bin
7.启动redis
进入到这个目录下
/usr/local/redis/bin
执行启动命令 选择配置文件
./redis-server redis.conf
配置redis后台运行
打开 redis.conf 找到 daemonize no 改为 daemonize yes
设置密码
设置为123456
requirepass 123456
设置端口
#定位关键字port
:/port
#默认配置为6379,有需要可以变更,这里变更为6380,若变更了端口需要同步变更pidfile的配置
port 6380
#定位关键字pidfile
:/pidfile
#变更配置默认为/var/run/redis_6379.pid,这里变更为/var/run/redis_6380.pid
pidfile /var/run/redis_6380.pid
关闭保护模式
#定位关键字protected-mode
:/protected-mode
#默认配置为yes,只有本机才可以访问redis,这里改为no,关闭保护模式
protected-mode no
允许外网访问
#定位关键字bind
:/bind
#bind 绑定的是机器网卡的ip,代表允许客户端通过机器的哪些网卡ip去访问,内网一般可以不配置bind,注释掉即可;外网访问变更为0.0.0.0,并配置服务器安全组
bind 0.0.0.0
启动之后提示
WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
解决方案
vim /etc/sysctl.conf
最后加一行
vm.overcommit_memory = 1
加完之后执行
sysctl vm.overcommit_memory=1
重启redis
vm.swappiness = 0
kernel.sysrq = 1
net.ipv4.neigh.default.gc_stale_time = 120
# see details in https://help.aliyun.com/knowledge_detail/39428.html
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
# see details in https://help.aliyun.com/knowledge_detail/41334.html
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_slow_start_after_idle = 0
#TODO 加到这里
vm.overcommit_memory = 1