#redis6.0.5编译安装
https://segmentfault.com/a/1190000023048088
##redis仓库
http://download.redis.io/releases/
##官方链接
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
###解压
tar -zxvf redis-6.2.6.tar.gz
cd redis-6.2.6/
###安装依赖包
yum -y install cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make centos-release-scl devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
#切换终端
scl enable devtoolset-9 bash
###安装
cd ./deps/
make hiredis lua linenoise jemalloc
cd ../
make
###PREFIX=/apps/redis 指定
make install PREFIX=/data/redis install
###准备相关目录和配置文件
mkdir /data/redis/{conf,pid,data,logs}
###配置变量
echo 'PATH=/data/redis/bin:$PATH' > /etc/profile.d/redis.sh
. /etc/profile.d/redis.sh
###目录结构
find /data/redis/
###将源包下的redis.conf移动到/app/redis/etc下
[root@redis 23:08:46 ~/redis-6.2.6 288]# mv ~/redis-6.2.6redis.conf /data/redis/conf/
根据实际目录来编写配置文件
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /data/redis/pid/redis_6379.pid
loglevel notice
logfile "/data/redis/logs/redis_6379.log"
databases 16
always-show-logo yes
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /data/redis/data/
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 "123456"
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
cat >/usr/lib/systemd/system/redis.service <<EOF
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/data/redis/bin/redis-server /data/redis/conf/redis.conf
ExecStop=/data/redis/bin/redis-shutdown
ExecStartPost=
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
EOF
cat /usr/lib/systemd/system/redis.service
###刷新 systemctl
systemctl daemon-reload
编写关闭脚本
vim /data/redis/bin/redis-shutdown
#!/bin/bash
#
# Wrapper to close properly redis and sentinel 包装关闭正确的redis和哨兵
test x"$REDIS_DEBUG" != x && set -x
REDIS_CLI=/data/redis/bin/redis-cli
# Retrieve service name 检索服务名称
SERVICE_NAME="$1"
if [ -z "$SERVICE_NAME" ]; then
SERVICE_NAME=redis
fi
# Get the proper config file based on service name 根据服务名称获取适当的配置文件
CONFIG_FILE="/etc/redis/$SERVICE_NAME.conf"
# Use awk to retrieve host, port from config file 使用awk从配置文件中检索主机,端口
HOST=`awk '/^[[:blank:]]*bind/ { print $2 }' $CONFIG_FILE | tail -n1`
PORT=`awk '/^[[:blank:]]*port/ { print $2 }' $CONFIG_FILE | tail -n1`
PASS=`awk '/^[[:blank:]]*requirepass/ { print $2 }' $CONFIG_FILE | tail -n1`
SOCK=`awk '/^[[:blank:]]*unixsocket\s/ { print $2 }' $CONFIG_FILE | tail -n1`
# Just in case, use default host, port 以防万一,使用默认的主机和端口
HOST=${HOST:-127.0.0.1}
if [ "$SERVICE_NAME" = redis ]; then
PORT=${PORT:-6379}
else
PORT=${PORT:-26739}
fi
# Setup additional parameters 其他参数设置
# e.g password-protected redis instances 例如密码保护的redis实例
[ -z "$PASS" ] || ADDITIONAL_PARAMS="-a $PASS"
# shutdown the service properly 正确关闭服务
if [ -e "$SOCK" ] ; then
$REDIS_CLI -s $SOCK $ADDITIONAL_PARAMS shutdown
else
$REDIS_CLI -h $HOST -p $PORT $ADDITIONAL_PARAMS shutdown
fi
useradd -r -s /sbin/nologin redis
###设置目录权限
chown -R redis.redis /app/redis/
firewall-cmd --permanent --zone=public --add-port=6379/tcp
firewall-cmd --reload
firewall-cmd --list-all
###前台启动redis
redis-server /app/redis/etc/redis.conf
###开启redis多范例
redis-server --port 6380
redis-server --port 6379
ps -ef | grep redis
###systemctl启动
systemctl start redis
systemctl status redis
systemctl enable redis
cat >> /etc/sysctl.conf <
cat >> /etc/sysctl.conf <
echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local
chmod +x /etc/rc.d/rc.local
cat /etc/rc.d/rc.local
Failed at step USER spawning /data/redis/bin/redis-server: No such process
Failed at step USER spawning /data/redis/bin/redis-server:没有这样的进程
The process /data/redis/bin/redis-server could not be executed and failed.
日志含义进程/data/redis/bin/redis-server执行失败。
Failed to start Redis persistent key-value database.
日志含义启动Redis persistent key-value数据库失败。
###刷新 systemctl
systemctl daemon-reload
###设置目录权限
chown -R redis.redis /app/redis/