在CentOS7.6下安装 Redis
1,下载最新的安装包
http://download.redis.io/releases/
2,解压安装包
#1,下载安装包
wget http://download.redis.io/releases/redis-6.2.1.tar.gz
#2,解压安装包
tar -zxvf redis-6.2.1.tar.gz
#3,移动解压文件到指定目录
mv redis-6.2.1 /usr/local/src/redis-6.2.1
#4.1,进入到redis目录,然后通过make命令进行编译。
cd /usr/local/src/redis-6.2.1
make MALLOC=libc
#4.2 安装
make install PREFIX=/usr/loca/redis-6.2.1
#5.拷贝配置文件到安装后目录
cp /usr/local/src/redis-6.2.1/redis.conf /usr/local/redis-6.2.1/redis.conf
#6.修改配置redis.conf文件
bind 127.0.0.1::1 改为 bind 127.0.0.1
#设置密码
requirepass XXXX
#7,测试是否可以启动
./usr/local/redis-6.2.1/bin/redis-server ./usr/local/redis-6.2.1/redis.conf
#8, 设置开机启动
#8.1 使用root权限创建redis文件目录
sudo gropdadd redis
sudo useradd -g redis redis --no-create-home
sudo chown -R redis:redis /usr/local/redis-6.2.1
#8.2 编辑配置文件redis.conf,将daemonize 改为yes支持后台运行
#8.3 添加开机启动服务
vim /etc/systemd/system/redis-server.service
#8.3.1 添加如下内容
[Unit]
Description=Redis Server Manager
After=syslog.target
After=network.target
[Service]
Type=simple
User=redis
Group=redis
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis-6.2.1/bin/redis-server /usr/local/redis-6.2.1/redis-6379.conf
ExecStop=/usr/local/redis-6.2.1/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
# wq!保存
#8.3.2 设置为开机启动
systemctl daemon-reload
systemctl start redis-server.service
systemctl enable redis-server.service
#8.3.3 创建redis-cli软连接
ln -s /usr/local/redis-6.2.1/bin/redis-cli /usr/bin/redis-cli
#退出redis服务:
(1)pkill redis-server
(2)kill 进程号
(3)/usr/local/redis-6.2.1/bin/redis-cli shutdown
遇到文件及解决方案
第一个警告:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
第二个警告:overcommit_memory is set to 0! Background save may fail under low memory condition. 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.
第三个警告:you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix thisissue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain thesetting after a reboot. Redis must be restarted after THP is disabled.
-------------------------------------------------------------------------------------------------------
解决方案
考虑到redis一般都是部署在服务器上作为服务存在的。所以,本文的解决方案都是持久性配置,不是临时配置。
第一个警告
将net.core.somaxconn = 1024添加到/etc/sysctl.conf中,然后执行sysctl -p生效配置。
第二个警告
将vm.overcommit_memory = 1添加到/etc/sysctl.conf中,然后执行sysctl -p生效配置。
第三个警告
将echo never > /sys/kernel/mm/transparent_hugepage/enabled添加到/etc/rc.local中,然后执行source /etc/rc.local生效配置