Linux下安装Redis
Linux下安装Redis
1、解压安装Redis
# 使用-C指定到解压下目录
tar -zvxf redis-6.0.5.tar.gz -C /usr/local/redis
2、编译
cd redis-6.0.5
make
# 指定安装位置
make PREFIX=/usr/local/redis install
3、修改配置
vim redis.conf
# 取消保护模式
protected-mode no
# 取消图形界面
daemonize yes
# 允许远程
bind 0.0.0.0
# requirepass foobared去掉注释,foobared改为自己的密码
# 日志
logfile /usr/local/redis/redis-server.log
------------------------------------------------------------性能配置---------------------------------------------------------------
# 内存管理
maxmemory 10gb
maxmemory-policy allkeys-lru
maxmemory-samples 10
# 网络和连接
timeout 300
tcp-keepalive 60
# 内存优化
lazyfree-lazy-eviction yes
lazyfree-lazy-expire yes
lazyfree-lazy-server-del yes
# 自动碎片整理
activedefrag yes
active-defrag-ignore-bytes 100mb
active-defrag-threshold-lower 10
active-defrag-threshold-upper 100
active-defrag-cycle-min 5
active-defrag-cycle-max 25
4、启动redis
cd src
./redis-server /usr/local/redis-3.2.8/redis.conf &
5、测试连接
# 启动Redis客户端
./redis-cli
# 身份验证
-> auth password
6、配置开机自启
vim /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
# 这行配置内容要根据redis的安装目录自定义路径
ExecStart=/usr/local/redis-7.0.9/bin/redis-server /usr/local/redis-3.2.8/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 重载系统服务
systemctl daemon-reload
# 开机自启
systemctl enable redis
# 启动redis
systemctl start redis
# 查看redis 服务的状态
systemctl status redis