四. Redis 6.0.9编译安装&多实例

1. 下载安装包
#下载地址:http://download.redis.io/releases/
wget http://download.redis.io/releases/redis-6.0.9.tar.gz -P /opt
2. 解压
cd /opt && tar -xvf redis-6.0.9.tar.gz; cd /opt/redis-6.0.9
3. 安装依赖
yum -y install cmake gcc jemalloc-devel
4. 编译安装
make
# 出现以下报错
···
server.c:***:**: error: 'struct redisServer' has no member named '***'
···
# 参考以下文档 确认是gcc版本问题 https://blog.csdn.net/weixin_45520603/article/details/108020571
yum -y install centos-release-scl && yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils && scl enable devtoolset-9 bash
gcc -v
# 编译完毕后提示以下信息,并按照提示进入./src 执行make test 失败
 ···
 You need tcl 8.5 or newer in order to run the Redis test
# 参考以下文档https://blog.csdn.net/zjh_746140129/article/details/80807393 安装tcl
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz -P /opt
cd /opt && tar -zxvf tcl8.6.1-src.tar.gz
cd ./tcl8.6.1/unix && ./configue; make && make install
# 执行make test 通过
 ···
\o/ All tests passed without errors!

Cleanup: may take some time... OK
# 启动服务,验证
./redis-server
./redis-cli
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> 
5. 创建工作目录、添加环境变量
mkdir /usr/local/redis/{bin,etc} -p #程序及配置文件目录
mkdir /data/redis63{79,80,81}/{data,logs} -p #数据及日志目录
cd /opt/redis-6.0.9/src/ && cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli  redis-server  /usr/local/redis/bin #拷贝相关程序
cp ..redis.conf /usr/local/redis/etc/redis6379.conf #拷贝、编辑配置文件
daemonize yes
pidfile /data/redis6379/redis.pid
port 6379
tcp-backlog 511
timeout 300
tcp-keepalive 60
loglevel notice
logfile /data/redis6379/logs/redis.log
databases 5
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename xinshen.rdb
dir /data/redis/data/
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
maxclients 600
maxmemory 2G
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
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-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
requirepass "redis"
# 添加环境变量
cat /etc/profile.d/redis.sh
Redis_Path=/usr/local/redis/bin
export PATH=$PATH:$Redis_Path
# 重新加载环境变量
source  /etc/profile.d/redis.sh
6. 多实例配置
# 拷贝配置文件
cd /usr/local/redis/etc && echo 'redis6380.conf redis6381.conf' | xargs -n 1 cp redis6379.conf
# 修改配置文件参数
···
port 6379
logfile “/data/redis6379/logs/redis.log”
dir /data/redis6379/data/
pidfile /data/redis6379/redis.pid

#启动6380,6381端口,连接测试
redis-server ./redis6380.conf && redis-server ./redis6381.conf
[root@lqy etc]# redis-cli -p 6380 -a 'redis6380'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6380> set k1 v1
OK
127.0.0.1:6380> get k1
"v1"
127.0.0.1:6380> exit
[root@lqy etc]# redis-cli -p 6381 -a 'redis6381'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> set k1 v1
OK
127.0.0.1:6381> get k1
"v1"
7. 编写启动脚本
#!/bin/sh
#实例 ./redis start 6379 ; ./redis stop 6380
#redis服务器监听的端口
REDISPORT=$2
 
#服务端所处位置
EXEC=/usr/local/redis/bin/redis-server
 
#客户端位置
CLIEXEC=/usr/local/redis/bin/redis-cli
 
#redis的PID文件位置,需要修改
PIDFILE=/data/redis$2/redis.pid
 
#redis的配置文件位置,需将${REDISPORT}修改为文件名
CONF="/usr/local/redis/etc/redis${REDISPORT}.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 "PID: {$PID}Stopping ..."
                $CLIEXEC -p $REDISPORT -a redis shutdown 2> /dev/null
                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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值