博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
脚本一键安装redis实现主从复制
阅读量:5823 次
发布时间:2019-06-18

本文共 4197 字,大约阅读时间需要 13 分钟。

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

Download_redis=

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 inputcase "$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

你可能感兴趣的文章
MTK 平台上如何给 camera 添加一种 preview size
查看>>
云计算最大难处
查看>>
关于数据分析思路的4点心得
查看>>
加班越久故障越多,如何跳出程序员的恶性循环?
查看>>
Memcached安装与配置
查看>>
Ansible二三事
查看>>
美团数据仓库的演进
查看>>
云计算和无人机如何谈出恋爱火花?
查看>>
SAP被评为“大数据”预测分析领军企业
查看>>
联想企业网盘张跃华:让文件创造业务价值
查看>>
iOS 简单数据的读写
查看>>
记录一次蚂蚁金服前端电话面试
查看>>
RecyclerView预加载机制源码分析
查看>>
直播源码开发视频直播平台,不得不了解的流程
查看>>
Ubuntu上的pycrypto给出了编译器错误
查看>>
聊聊flink的RestClientConfiguration
查看>>
在CentOS上搭建git仓库服务器以及mac端进行克隆和提交到远程git仓库
查看>>
測試文章
查看>>
Flex很难?一文就足够了
查看>>
【BATJ面试必会】JAVA面试到底需要掌握什么?【上】
查看>>