Centos8 安装 Redis6.0.16
下载,解压,编译,安装
安装至 /opt/redis/redis-6.0.16 目录
tar xvf redis-6.0.16.tar.gz
gcc --version
cd redis-6.0.16/
yum install tcl
make
make test
make PREFIX=/opt/redis/redis-6.0.16 install
配置文件
cd /opt/redis/
ln -s redis-6.0.16 latest
cd /opt/redis/redis-6.0.16
mkdir conf
# 复制配置文件模板
cp ~/backup/redis-6.0.16/redis.conf conf/redis_6379.conf
cd conf/
# 修改配置文件
vi redis_6379.conf
涉及到的改动
cat /opt/redis/latest/conf/redis_6379.conf | grep -v '^$'|grep -v '^#'|grep -v '^;'
bind 192.168.255.4 #改了
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes #改了, 这边不论设置yes/no, 日志都会输出到日志文件, 所以直接yes吧
supervised no
pidfile /run/redis_6379.pid #改了
loglevel notice
logfile "/var/log/redis_6379.log" #改了
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /data/redis/db/ #改了
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
requirepass what.1234 #改了
修改系统参数
修改 somaxconn
vi /etc/sysctl.d/99-sysctl.conf
# 最后增加两行
net.core.somaxconn = 1024
vm.overcommit_memory = 1
# 增加结束
sysctl -p
transparent_hugepage
vi /etc/rc.local
# 最后增加两行
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
# 增加结束
cd /etc/
# chmod+x 后, 启动才会执行
chmod +x rc.local
重启确认设置成功
reboot
cat /sys/kernel/mm/transparent_hugepage/defrag
cat /sys/kernel/mm/transparent_hugepage/enabled
添加到系统服务
复制服务模板
# 实际上这个systemd-redis_server.service 不好用, 最后加上`Type=forking`才成功启动
cd /usr/lib/systemd/system
cp ~/backup/redis-6.0.16/utils/systemd-redis_server.service redis.service
vi redis.service
systemctl enable redis
systemctl start redis
systemctl status redis
服务文件 /usr/lib/systemd/system/redis.service 内容
[Unit]
Description=Redis data structure server
Documentation=https://redis.io/documentation
#Before=your_application.service another_example_application.service
#AssertPathExists=/var/lib/redis
Wants=network-online.target
After=network-online.target
[Service]
Type=forking
ExecStart=/opt/redis/latest/bin/redis-server /opt/redis/latest/conf/redis_6379.conf
#ExecStop=/opt/redis/latest/bin/redis-cli -p 6379 shutdown
PrivateTmp=yes
LimitNOFILE=10032
NoNewPrivileges=yes
[Install]
WantedBy=multi-user.target
其中
- 不需要设置ExecStop, 因为配置加了口令, 这个命令执行不会成功
- Wants和After要使用
network-online.target
, 否则开机启动会产生这样的错误
900:C 17 Oct 2021 22:24:14.717 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
900:C 17 Oct 2021 22:24:14.720 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=900, just started
900:C 17 Oct 2021 22:24:14.721 # Configuration loaded
900:M 17 Oct 2021 22:24:14.721 # Could not create server TCP listening socket 192.168.255.4:6379: bind: Cannot assign requested address