Redis二进制安装

一、系统信息

[root@centos8 07:40:23~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"

二、安装依赖包

[root@centos8 07:41:39~]# yum -y install gcc automake autoconf libtool make gcc-c++ vim wget

 三、下载软件6.2.5版本的redis

[root@centos8 07:53:17~]# wget https://download.redis.io/releases/redis-6.2.5.tar.gz

四、创建目录

[root@centos8 07:54:14~]# mkdir /data/software/redis

 五、安装redis

[root@centos8 07:56:36~]# tar -zxf redis-6.2.5.tar.gz && \
cd redis-6.2.5 && \
make -j 4 PREFIX=//data/software/redis install

五、创建所需要的目录

[root@centos8 07:58:30~]# cd /data/software/redis/ && mkdir data log run etc

六、配置redis配置文件

[root@centos8 08:00:02~]# cat > /data/software/redis/etc/redis.conf <<EOF
bind 0.0.0.0
requirepass 123456
protected-mode yes
port  6379
tcp-backlog 500
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /data/software/redis/run/redis.pid
loglevel notice
logfile "/data/software/redis/log/redis.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
dir /data/software/redis/data
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
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
EOF

七、配置redis环境变量

[root@centos8 08:08:30~]# cat > /etc/profile.d/redis_home.sh <<EOF 
export REDIS_HOME=/data/software/redis
export PATH=\$PATH:\$REDIS_HOME/bin
EOF

[root@centos8 08:08:30~]# source /etc/profile

[root@centos8 08:08:51~]# redis-cli -v
redis-cli 6.2.5
[root@centos8 08:09:07~]#

八、配置启动关闭脚本

[root@centos8 08:10:37~]# cat /etc/init.d/redis 
#!/bin/sh
# 
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

### BEGIN INIT INFO
# Provides:     redis_6379
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Redis data structure server
# Description:          Redis data structure server. See https://redis.io
### END INIT INFO

REDISPORT=6379
EXEC=/data/software/redis/bin/redis-server
CLIEXEC=/data/software/redis/bin/redis-cli

PIDFILE=/data/software/redis/run/redis.pid
CONF="/data/software/redis/etc/redis.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT -a $(awk '$1=="requirepass" {print $2}' ${CONF}) --no-auth-warning shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

九、添加用户和修改属性

[root@centos8 08:12:48~]# useradd -r -s /sbin/nologin redis

[root@centos8 08:13:47~]# chown redis:redis -R /data/software/redis

十、加入到system管理服务中同时启动服务

[root@centos8 08:16:19~]# chmod +x /etc/init.d/redis && \
chkconfig --add redis && \
chkconfig --level 345 redis on && \
systemctl daemon-reload && \
systemctl start redis && \
netstat -untpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      11172/redis-server  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      966/sshd            
tcp6       0      0 :::22                   :::*                    LISTEN      966/sshd            
udp        0      0 127.0.0.1:323           0.0.0.0:*                           945/chronyd         
udp6       0      0 ::1:323                 :::*                                945/chronyd         

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值