脚本一键安装redis实现主从复制

  1. 安装脚本及配置文件上传至家目录即可,sh执行脚本即可选择主从
    #!/bin/bash
    #Description:atuo install redis
    #Date:2018.4.11

Download_redis=http://download.redis.io/releases/redis-3.2.1.tar.gz
dir1=/opt
redis=redis-3.2.1
redis_conf1=/usr/local/redis-6379/redis.conf
redis_conf2=/usr/local/redis-6380/redis.conf
FILE1=$HOME/6379.conf
FILE2=$HOME/6380.conf
dir2=/server/scripts/redis
count=ps -ef|grep redis|grep -v grep| wc -l

install_yum () {
echo -e "\033[41;37m <===开始安装redis依赖 软件,请稍等...===> \033[0m"
sleep 2
yum install -y gcc wget
}

install_dir () {
cd $dir1
wget -q $Download_redis
echo -e "\033[41;37m <===redis下载中,请稍后...===> \033[0m"
tar xf redis-3.2.1.tar.gz -C /usr/local
cd /usr/local/$redis
make
make PREFIX=${redis_setup_dir} install
if [ echo $? -eq 0 ];then
echo -e "\e[1;32m redis安装成功. \e[0m"
elif [ echo $? -ne 0 ];then
echo -e "\e[1;31m redis安装失败,请检查环境. \e[0m"
exit
fi
sleep 1
}

select_or () {
echo "---------------------------------------------------------------
select Master Slave
1 Master
2 Slave
----------------------------------------------------------------"

read input

case "$input" in 
     1)
      mv /usr/local/$redis /usr/local/redis-6379
      sleep 1
      cd /usr/local/redis-6379
      cp -f redis.conf redis.conf.bak
      cat "$HOME/6379.conf" >$redis_conf1
      /usr/local/redis-6379/src/redis-server /usr/local/redis-6379/redis.conf &
      sleep 3
      ;;
     2)
      mv /usr/local/$redis /usr/local/redis-6380
      sleep 1
      cd /usr/local/redis-6380
      cp -f redis.conf redis.conf.bak
      cat "$HOME/6380.conf" >$redis_conf2
      /usr/local/redis-6380/src/redis-server /usr/local/redi

s-6380/redis.conf &
sleep 3
;;
*)
echo "---------------------------------------------------------------
select Master Slave
1 Master
2 Slave
----------------------------------------------------------------"
esac
}

count_conf () {
if [ $count -gt 1 ];then
echo -e "\e[1;32m redis is running \e[0m"
elif [ $count -le 1 ];then
echo -e "\e[1;31m redis is not running \e[0m"
fi
}

install_yum
install_dir
select_or
count_conf


2.主配置文件
daemonize yes
pidfile /usr/local/redis-6379/run/redis.pid
bind 0.0.0.0
port 6379
timeout 300
tcp-keepalive 0
loglevel notice
#logfile stdout
databases 16
unixsocketperm 0
maxmemory 2000000000
maxmemory-policy volatile-lru
maxmemory-samples 3
maxclients 10000
#save 900 1
#save 300 10
#save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
slave-serve-stale-data yes
slave-read-only yes
repl-ping-slave-period 10
repl-timeout 60
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 1024
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
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


3.从配置文件
daemonize yes
pidfile /usr/local/redis-6380/run/redis.pid
port 6380
timeout 300
tcp-keepalive 0
loglevel notice
#logfile stdout
databases 16
unixsocketperm 0
maxmemory 2000000000
maxmemory-policy volatile-lru
maxmemory-samples 3
maxclients 10000
#save 900 1
#save 300 10
#save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
slaveof 192.168.1.42 6379 (根据你实际的本地环境配置为主的ip 及端口)
slave-serve-stale-data yes
slave-read-only yes
repl-ping-slave-period 10
repl-timeout 60
repl-disable-tcp-nodelay no
slave-priority 100
appendonly yes
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 1024
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
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

转载于:https://blog.51cto.com/11571922/2103928

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值