#! /bin/bash
##
###
redis_package='/root/redis-3.2.12.tar.gz'
redis_data_dir='/export/Data/redis_data'
redis_conf_dir='/export/servers/redis/conf'
redis_aof_dir='/export/Data/redis_data'
USAGE="USAGE:
./redis.sh --install
install Redis server
./redis.sh --start
Start Redis server
./redis.sh --stop
stop Redis server
./redis.sh --restart
restart Redis server
./redis.sh --clean
remove Reids server"
[ $# -eq 0 ] && echo "$USAGE" && exit 0
redis_install(){
#######add_redis_user###########
groupadd -g 599 redis
useradd -u 599 -g redis redis
echo "redispassword" | passwd --stdin redis
########Redis_dir_check#########
if [ -d $redis_data_dir ];then
echo "redis data dir already exists"
else
mkdir -p $redis_data_dir
chown -R redis:redis $redis_data_dir
fi
#if [ -d $redis_conf_dir ];then
# echo "redis conf dir already exists"
#else
# mkdir -p $redis_conf_dir
# chown -R redis:redis $redis_conf_dir
#fi
########Redis_Installation######
if [ -f $redis_package ]
then
tar -zxvf $redis_package -C /export/servers/.
cd /export/servers/
ln -s redis-3.2.12 redis
cd /export/servers/redis && make
cp /export/servers/redis/src/redis-cli /usr/bin
cp /export/servers/redis/src/redis-server /usr/bin
if [ -d $redis_conf_dir ];then
chown -R redis:redis $redis_data_dir
echo "redis conf dir already exists"
else
mkdir -p $redis_conf_dir
chown -R redis:redis $redis_conf_dir
chown -R redis:redis $redis_data_dir
fi
else
chown -R redis:redis $redis_data_dir
echo "Please check redis installation packege!"
exit 0
fi
#########Redis_data_dir#########
for i in `seq 6379 6388`;
do
echo "daemonize yes
pidfile "$redis_data_dir/$i/$i.pid"
port $i
timeout 300
tcp-keepalive 0
loglevel notice
logfile "$redis_data_dir/$i/redis_$i.log"
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
dbfilename "$i.rdb"
dir "$redis_data_dir/$i"
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
repl-backlog-size 128mb
maxmemory 1gb
appendonly yes
appendfilename "$i.aof"
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 40960
zset-max-ziplist-value 4096
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 128mb 128mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
rename-command keys jkeys
rename-command flushdb trunactedb
rename-command flushall truncateall
maxclients 10000
requirepass RootRedis@2018
maxmemory-policy allkeys-lru" >$redis_conf_dir/redis_$i.conf
mkdir $redis_data_dir/$i
chown -R redis:redis $redis_data_dir
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_$i.conf" >2&
sleep 1
done
#sleep 5
if [ `ps -ef | grep redis | grep -v grep | wc -l` -eq 10 ];then
echo "Redis Installation is ok!"
else
chown -R redis:redis $redis_data_dir
echo "Please check Redis Installation!"
fi
}
redis_clean(){
for i in `seq 6379 6388`
do
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p $i shutdown
done
rm -rf /export/servers/redis*
rm -rf /export/Data/redis_data
}
redis_start(){
for i in `seq 6379 6388`
do
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_$i.conf" >2&
done
}
redis_stop(){
for i in `seq 6379 6388`
do
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p $i shutdown
done
}
redis_6379_start(){
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_6379.conf" >2&
}
redis_6380_start(){
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_6380.conf" >2&
}
redis_6381_start(){
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_6381.conf" >2&
}
redis_6382_start(){
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_6382.conf" >2&
}
redis_6383_start(){
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_6383.conf" >2&
}
redis_6384_start(){
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_6384.conf" >2&
}
redis_6385_start(){
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_6385.conf" >2&
}
redis_6386_start(){
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_6386.conf" >2&
}
redis_6387_start(){
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_6387.conf" >2&
}
redis_6388_start(){
su - redis -c "/export/servers/redis/src/redis-server $redis_conf_dir/redis_6388.conf" >2&
}
redis_stop_6379(){
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p 6379 shutdown
}
redis_stop_6380(){
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p 6380 shutdown
}
redis_stop_6381(){
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p 6381 shutdown
}
redis_stop_6382(){
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p 6382 shutdown
}
redis_stop_6383(){
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p 6383 shutdown
}
redis_stop_6384(){
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p 6384 shutdown
}
redis_stop_6385(){
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p 6385 shutdown
}
redis_stop_6386(){
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p 6386 shutdown
}
redis_stop_6387(){
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p 6387 shutdown
}
redis_stop_6388(){
/export/servers/redis/src/redis-cli -a RootRedis@2018 -h localhost -p 6388 shutdown
}
case $1 in
--install)
redis_install
;;
--start)
redis_start
;;
--stop)
redis_stop
;;
--restart)
redis_stop
redis_start
;;
--clean)
redis_clean
;;
--start6379)
redis_6379_start
;;
--start6380)
redis_6380_start
;;
--start6381)
redis_6381_start
;;
--start6382)
redis_6382_start
;;
--start6383)
redis_6383_start
;;
--start6384)
redis_6384_start
;;
--start6385)
redis_6385_start
;;
--start6386)
redis_6386_start
;;
--start6387)
redis_6387_start
;;
--start6388)
redis_6388_start
;;
--stop6379)
redis_stop_6379
;;
--stop6380)
redis_stop_6380
;;
--stop6381)
redis_stop_6381
;;
--stop6382)
redis_stop_6382
;;
--stop6383)
redis_stop_6383
;;
--stop6384)
redis_stop_6384
;;
--stop6385)
redis_stop_6385
;;
--stop6386)
redis_stop_6386
;;
--stop6387)
redis_stop_6387
;;
--stop6388)
redis_stop_6388
;;
esac
Redis Install Script
最新推荐文章于 2024-07-15 23:14:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)