自动配置redis集群的shell脚本

发布时间:2020-05-05编辑:脚本学堂
分享一例redis集群的自动配置脚本,用来学习redis集群的配置,以及shell编程的相关知识,还是比较有用的,感兴趣的朋友可以参考下。

本节内容:
自动配置redis集群

分享一个redis集群的自动安装的shell/ target=_blank class=infotextkey>shell脚本,如下:
 

复制代码 代码示例:
#!/bin/bash 
#
#site: www.jb200.com
if [[ $1 == "" ]];then 
echo "Usage: $0 ipaddr***" 
exit 0 
fi 
masterIp=$1 
cd /usr/local/src/ 
tar -zxvf redis-2.6.12.tar.gz 
cd /usr/local/src/redis-2.6.12 
make && make install 
mkdir -p /etc/redis/ 
mkdir -p /export/data/redis_data/6379 
mkdir -p /export/data/redis_data/6380 
sed -i "s/127.0.0.1/$masterIp/g" /usr/local/src/6380.conf 
cp -rf /usr/local/src/6379.conf /etc/redis/ 
cp -rf /usr/local/src/6380.conf /etc/redis/ 
cat >> /etc/sysctl.conf <<EOF 
net.core.somaxconn = 32768 
net.core.wmem_default = 8388608 
net.core.rmem_default = 8388608 
net.core.rmem_max = 16777216 
net.core.wmem_max = 16777216 
net.ipv4.tcp_timestamps = 0 
net.ipv4.tcp_synack_retries = 1 
net.ipv4.tcp_syn_retries = 0 
net.ipv4.tcp_tw_recycle = 1 
net.ipv4.tcp_tw_reuse = 1 
net.ipv4.tcp_mem = 94500000 915000000 927000000 
net.ipv4.tcp_max_orphans = 3276800 
net.ipv4.ip_local_port_range = 1024 65535 
net.ipv4.tcp_fin_timeout = 10 
net.ipv4.tcp_keepalive_time = 100 
net.ipv4.tcp_syncookies = 1 
net.ipv4.tcp_max_syn_backlog = 8192 
net.ipv4.tcp_max_tw_buckets = 20000 
EOF 
modprobe bridge 
sysctl -p 
/usr/local/bin/redis-server /etc/redis/6379.conf 
/usr/local/bin/redis-server /etc/redis/6380.conf 

2,6379.conf
 

复制代码 代码示例:
daemonize yes 
pidfile /var/run/redis_6379.pid 
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 
dir /export/data/redis_data/6379 
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,6380.conf
 

复制代码 代码示例:
daemonize yes 
pidfile /var/run/redis_6380.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 
dir /export/data/redis_data/6380 
slaveof 127.0.0.1 6379 
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